PDA

View Full Version : HSERIN string starting index ?



gunayburak
- 30th June 2016, 16:32
Hello everyone .. Gotta mind confusing question about a very favorite command HSERIN ..
Let's say I'm capturing bytes on USART and I have an INDEX variable called x and these x variables are within an 100 array size ..

Is there a possible way to set an index in the command starting with a specific number ? such as ?

hserin 60000,main,[str x[5]\90]

I need to do this because I need the data in x[0],x[1],x[2],x[3],x[4] variables ..
What I'm actually asking is if this command syntax is true and fine for purpose ?

Thansk in advance ..

richard
- 1st July 2016, 00:20
if the array offset is always a constant value ,
declare another var with that offset to use as a pointer using the EXT modifier

eg
x var byte[100]
y var byte EXT

asm
y = x+5
endasm

hserin 60000,main,[str y\90]

gunayburak
- 1st July 2016, 23:16
I am not familiar with this EXT statement .. What does it do exactly ? Can you please explain ?

HenrikOlsson
- 3rd July 2016, 06:58
Is there a possible way to set an index in the command starting with a specific number ? such as ?
hserin 60000,main,[str x[5]\90]
That would be my first test as well, I know it compiles and since [5] is just an offset I would asume it works but since you're asking you've must have tested it and found that it didn't, so I'm curious, what did it do?


I am not familiar with this EXT statement .. What does it do exactly ? Can you please explain ?
http://www.picbasic.co.uk/forum/showthread.php?t=3891

/Henrik.

gunayburak
- 3rd July 2016, 09:33
Hello Henrik :) I really can't figure out if it is working or not , so I can't say a certain thing about that because sometimes it seems working as it should and sometimes it doesn't .. I'm really not sure , that's why it a complex situation .. I need to observe and make other tests even need to modify my code to understand if it is properly working(I'm speaking for my code and by the way I could have tested it with a simple simulation code yet I haven't done so far because of being busy with a very long code my mind is like a trash :) )

HenrikOlsson
- 3rd July 2016, 09:57
Tried the following code:

i VAR BYTE
Array VAR BYTE[128]

PAUSE 3000

Main:
GOSUB ClearArray
HSEROUT["Send 6 bytes, these should end up starting at index 0, don't use '0'", 13]
HSERIN[STR Array\6]
GOSUB Echo

GOSUB ClearArray
HSEROUT["Send 6 bytes, these should end up starting at index 12, don't use '0'", 13]
HSERIN[STR Array[12]\6]
GOSUB Echo

GOSUB ClearArray
HSEROUT["Send 6 bytes, these should end up starting at index 3, don't use '0'", 13]
HSERIN[STR Array[3]\6]
GOSUB Echo

GOSUB ClearArray
HSEROUT["Send 6 bytes, these should end up starting at index 21, don't use '0'", 13]
HSERIN[STR Array[21]\6]
GOSUB Echo

Goto Main

Echo:
For i = 0 to 31
HSEROUT[Array[i], " "]
NEXT
HSEROUT[13,13]
RETURN

ClearArray:
For i = 0 to 31
Array[i] = "0"
NEXT
RETURN

And, sending the string "123456" it gives the following results:

Send 6 bytes, these should end up starting at index 0, don't use '0'
1 2 3 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Send 6 bytes, these should end up starting at index 12, don't use '0'
0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Send 6 bytes, these should end up starting at index 3, don't use '0'
0 0 0 1 2 3 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Send 6 bytes, these should end up starting at index 21, don't use '0'
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 0 0 0 0 0

Seems to work exactly as expected. One thing you need to watch out for is to not write outside of the array since that will corrupt the variable(s) being stored there - but that's not specific to this method.

/Henrik.

gunayburak
- 4th July 2016, 22:54
Wouww .. Thanks for the great effort , now it has opened up both my mind and the way to the future ideas ... Really Henrik , you're my hero after Darrel ...