View previous topic :: View next topic |
Author |
Message |
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Thu Jan 29, 2015 6:59 am Post subject: How to Memcopy Multi Index Arrays? |
|
|
Hello all,
I am just trying the new multi index arrays. This is the code used without the multi index array:
Code: |
Dim RxBuffer(64) As Byte
'bts = MEMCOPY(source, target , bytes[ , option])
bts = MEMCOPY(RxTempBuf(1), Rxbuffer(Idx),Dta_len) '01/28/15a
|
Can anyone tell me how to port that to use this new multi index array?
Code: |
Dim RxBuffer(10,64) As Byte
|
Thank you,
Tim
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Thu Jan 29, 2015 11:18 pm Post subject: |
|
|
So you are trying to copy a 1 dimensional array into one dimension of a multi-dimensional array. I know of no language which allows that as a direct operation.
But of course you can do it easily in a loop:
for bt = 1 to Dta_len
RxBuffer(1,bt) = rxTempBuf(bt)
next
will put the temp buffer in column 1 of the multi-array
Yes of course it will take a bit longer than using memcopy ( although not much, since you are only copying bytes ). If you want it quicker, do it in ASM. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Fri Jan 30, 2015 3:26 am Post subject: |
|
|
Hi Adrian,
I thought there might be a way to do it... but without regard to that, the looping does not work. I get an error 61.
Code: |
Dim RxBuffer(10,64) As Byte
Dim RxTempBuf(64) As Byte
Dim b_temp1 as byte
Local Dta_len As Byte
For b_temp1 = 1 to Dta_len
Rxbuffer(1,b_temp1) = RxTempBuf(b_temp1) <===== ERROR 61 HERE
Print "Rxbuffer(b_temp1)= ";Rxbuffer(b_temp1)
Print "RxTempBuf(b_temp1)= ";RxTempBuf(b_temp1)
Next b_Temp1
|
Compiler says - Error 61 label not found (_X_RXBUFFER)
Ideas? Sure would like to use these multi indexed arrays...
Tim |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Fri Jan 30, 2015 4:02 am Post subject: |
|
|
Try it like this, ie use a single byte temporary variable to hold the result from 1 array to the other
Code: |
Dim RxBuffer(10,64) As Byte
Dim RxTempBuf(64) As Byte
Dim b_temp1 as byte
Local Dta_len As Byte
dim bt as byte
For b_temp1 = 1 to Dta_len
bt = RxTempBuf(b_temp1)
Rxbuffer(1,b_temp1) = bt
Print "Rxbuffer(b_temp1)= ";Rxbuffer(b_temp1)
Print "RxTempBuf(b_temp1)= ";RxTempBuf(b_temp1)
Next b_Temp1
|
_________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Fri Jan 30, 2015 4:32 am Post subject: |
|
|
Hi Adrian,
I had tried that before, but also again after you suggested to be sure... It does not work.
What I do not understand, is with the statement:
Rxbuffer(1,b_temp1) = bt
or
Rxbuffer(1,b_temp1) = RxTempBuf(b_temp1)
How does the compiler *know* that the array to FILL is the second array? It goes to the same rational you used for Memcopy... In my tiny brain (where is homer these days!?) two pointers, or arrays or vars - whatever - need to be there. But what do I know! I am sure that Marc had/has a hard time implementing this - but IT SURE IS COOL!
Thanks again for your effort and feedback on this!
Tim |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Fri Jan 30, 2015 8:50 am Post subject: |
|
|
Because you specify index 1 ( the first 'column' in the array ) in the assignment during the loop. ( or the second, if you specify BASE 0 ). That one stays fixed, while the other one is incremented by the loop counter.
I cannot see how they could work in the present form using memcopy, since there you cannot specify which index is fixed, and which is to be incremented.
Pity you cant get it working. I must admit I havent had a chance to play with multi-dim arrays yet in Bascom, so I dont really know if they work, but Mark assures us that they do for most simple assignments like here. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Fri Jan 30, 2015 10:52 am Post subject: |
|
|
Hi AdrianJ,
Multi multi-dim arrays in Bascom actuualy work quite well. I'm using them to handle the Batterie data from up to 8 Lion batteries (data supplied through SM Bus). You just Need to be careful of afew things:
Don't try to print from an Array element directly (or any complex command for that matter)
Print Array(1,1); won't work
temp=Array(1,1):print temp 'will work
If your using includes make sure that you have atleast one Access to the Array in the main code ( this is enough Var3=Array(Var1,Var1))
I'm actually using alot of the new functions in 7.8 (Multi Array and i2c multi bus). Both of which have saved me alot of work (even though there's a bug in the i2c Multi lib with regards to handling the err bit, see my thread for details).
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jan 30, 2015 11:03 am Post subject: |
|
|
Quote: | Compiler says - Error 61 label not found (_X_RXBUFFER) |
yes that is a bug. to workaround, access the multi array in your main code once.
memcopy should or could work but a quick test shown it doesnt. i will have a look at it.
the line in your sample should show : Bts = Memcopy(rxtempbuf(1) , Rxbuffer(1 , 1) , 64) '01/28/15a
because the array has multi dim, you need to provide these dimensions as well. _________________ Mark |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Fri Jan 30, 2015 6:57 pm Post subject: |
|
|
Thanks for the clarification everyone!
Tim |
|
Back to top |
|
|
|