PDA

View Full Version : How to get ASCII data in array.



Ioannis
- 5th November 2008, 21:25
Hi to all.

I wonder if the modifier DEC can be used with STR in data array reception like this:

Hserin [DEC3 STR array\n]

I know the above won't compile, but as I am getting ascii data in 3 bytes packets, is there a special syntax that might do the trick?

Thanks,
Ioannis

mackrackit
- 5th November 2008, 22:10
Would something like this work?


[STR NUMS\16]
X1 = (NUMS[1]-"0")
X2 = (NUMS[3]-"0")
X3 = (NUMS[5]-"0")
X4 = (NUMS[7]-"0")
X5 = (NUMS[9]-"0")
X6 = (NUMS[11]-"0")
X7 = (NUMS[13]-"0")
X8 = (NUMS[15]-"0")

Darrel Taylor
- 5th November 2008, 22:21
Do the 3 bytes ever represent more than 255?
If not, this might work ...


For LoopCount = 0 to n-1
HSERIN [DEC3 array(LoopCount)]
Next LoopCount

But there's a distinct possibility of getting the wrong numbers if there's nothing between the 3 byte data packets.
<br>

mackrackit
- 5th November 2008, 22:40
Maybe ideas here
http://www.picbasic.co.uk/forum/showpost.php?p=305&postcount=2

Ioannis
- 6th November 2008, 07:46
Thanks boys.

Currently, I do a simple 28bytes communication between radio modems using DT instant interrupts to get the Serial data like this:



Get_char:
ser_in=0
hserin 100,noreceived,[wait("##"),str temp_array\file] 'Get 28 characters
if temp_array[0]=node then 'Are for this node station?
ser_in=1 'if yes, then flag data and copy
endif
noreceived: 'else return
@ INT_RETURN


If data are coming to the serial port, then if the 2 first are ## data are captured in the temp_array (28 long)

The first byte is the node station. If data are for this node, then a flag is raised.

My concern is that, data can be any number including the $23 which is '#' character.

So this might lead the routine to hang if data are out of sync sometime.

My thought was to use data in the array only in ascii form without increasing length of temp_array x 3, by converting the ascii values while receiving them.

Ioannis

mackrackit
- 6th November 2008, 13:20
My concern is that, data can be any number including the $23 which is '#' character.

So this might lead the routine to hang if data are out of sync sometime.


Why not use a TimeOut? Or can you not afford to miss any data?

Ioannis
- 6th November 2008, 14:09
Please see the previous than yours post, that shows the timeout is there. But Darrel has explained very well why this might hang here:

http://www.pbpgroup.com/modules/newbb/viewtopic.php?topic_id=28&forum=8

Ioannis

mackrackit
- 6th November 2008, 18:04
Please see the previous than yours post, that shows the timeout is there.
OOPPS, I was sleepy? :o



But Darrel has explained very well why this might hang here:

http://www.pbpgroup.com/modules/newbb/viewtopic.php?topic_id=28&forum=8

Ioannis
That was interesting, I now have it bookmarked.
Just curios, is that the same project?

Ioannis
- 6th November 2008, 20:14
No. That was an easy (now, for me...) project. It just transmitted the number in 3 bytes form. E.g. if number was 128 then the port would transmit ASCII '1', ASCII'2' and ASCII '3' or 49, 50 and 56 as decimal values.

Ioannis