Shop OBEX P1 Docs P2 Docs Learn Events
Having Trouble with serin command receiving comma delimted asci text non fixed — Parallax Forums

Having Trouble with serin command receiving comma delimted asci text non fixed

easyboteasybot Posts: 2
edited 2009-06-25 18:41 in BASIC Stamp
·Hello

My problem is that I have to recieve data in a fixed format (asci text comma delimited)·and speed 38k4. I am recieving the data in just fine into a byte array if it sends the normal length of data·and sending it out formatted to a display board. Two problems data length can be differant each time I receive it. it is comma seperated and has a end Character, but when I try to use the end character to signal serin to stop and proceed it just hangs as if the bytearray hasn't been filled.· The end char appears to be a cr or line feed. It shows up in a text file as a square box. It is also a long string so it uses all of the variable space leaving me with nothing to work with. I can solve the Variable issue by writing the data to the eprom and then reading it back freeing the variables for other uses. but I cant figure out how to get the serin command to end if the length changes.If I get a full bytearray it works fine. I have included a sample of the data and the program im using now. It does not have code to use the end character or make use of the comma seperater. I took it out because I could not get it to work. I know at that speed the BS2 cant do much on the data without losing some so I was just receiving it and then trying to work with it.

The data only updates once every 5 seconds plenty of time to work with it in between display updates. I can't change anything on the sender side.

Data:··10 sets from text file.
20.000,30.000,0.00,6.818
20.000,30.000,150.00,6.825
20.000,30.000,0.00,6.828
20.000,30.000,150.00,6.825
20.000,30.000,0.00,6.817
20.000,30.000,0.00,6.825
20.000,30.000,0.00,6.820
20.000,30.000,0.00,6.814
20.000,30.000,150.00,6.825
20.000,30.000,0.00,6.820
·If anyone can suggest a better way to accomplish this or supply a code example that will solve my problem I would be most grateful.My goal is to pull in the data use the comma to break up the data and display the data between the commas as is on the display. I know my programming skills are poor but I have tried all the examples in the manual for special formatters and I cant get them to work. Please help
Program:


'{$STAMP BS2}

'{$PBASIC 2.5}

#SELECT $STAMP

#CASE BS2, BS2E, BS2PE

T1200 CON 813

T2400 CON 396

T4800 CON 188

T9600 CON 84

T19K2 CON 32

T38K4 CON 6

#ENDSELECT

SevenBit CON $2000

Inverted CON $4000

Open CON $8000

' Video commands

v_Null CON 128

v_InvOn CON 129

v_InvOff CON 130

v_InvScrn CON 131

v_PlotXY CON 132

v_UnplotXY CON 133

v_Outs CON 134

v_DecByte CON 136

v_HexByte CON 137

v_Ohms CON 30

Baud CON T4800 + Inverted

Baud1 CON T38K4

Sout PIN 0

Rpin CON 16

Kei VAR Byte(25)

PAUSE 100

SEROUT Sout,baud,[noparse][[/noparse]v_Null,v_Null,v_Null,v_Null,CLS, v_InvOff]

SEROUT Sout,baud,[noparse][[/noparse]"Keimar Lab View", CR]

PAUSE 1000

SEROUT Sout,baud,[noparse][[/noparse]CLS]

 

Start:

'Writes basic info to display that doesn't change.

SEROUT Sout,baud,[noparse][[/noparse]HOME,CR]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,0,1,"Temp"]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,12,1, v_ohms,"C"]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,0,2,"pCO2"]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,12,2,"mmHg"]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,0,3,"pO2"]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,12,3,"mmHg"]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,0,4,"pH"]

'Gets Data from sensor board and stores it in variables.

SERIN Rpin,baud1,[noparse][[/noparse]STR Kei\26]

' writes sensor data to display.

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,5,1,Kei(0),Kei(1),Kei(2),Kei(3),Kei(4),Kei(5)]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,5,2,Kei(7),Kei(8),Kei(9),Kei(10),Kei(11),Kei(12)]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,5,3,Kei(14),Kei(15),Kei(16),Kei(17),Kei(18),Kei(19)]

SEROUT Sout,baud,[noparse][[/noparse]CRSRXY,5,4,Kei(21),Kei(22),Kei(23),Kei(24),Kei(25)]

'Update 4 times a second Change to larger number to reduce updates.(1000 equals·1 second)

PAUSE 250

GOTO Start

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-25 16:55
    1) A BS2 will not work reliably at 38.4KBaud, particularly receiving. The manual says so and experience says so. You could go to a faster Stamp like a BS2px. That also has the ability to input directly to the scratchpad RAM which would free up the space in the variables area.

    2) Your program uses the fixed length input method ("STR Kei\26"). Adding the terminator to the formatter might work ("STR Kei\26\CR"), but it might also slow things down enough so that it doesn't work at all. Remember that the formatter stores a zero byte for the CR and fills the rest of the array with zeroes.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-06-25 16:58
    Right away I see two problems here…the first is the high rate of speed of the data. At 38.4K the BASIC Stamp 2 isn’t going to be able to use any formatters or it will miss data due to the overhead. The second problem is variable space. You’re using up every byte for the incoming data and you have nothing left to work with for parsing the data.

    It sounds like the data is coming in already in ASCII format but I am unclear if you’re getting it all. In any event this data is formatted much like GPS data and because of that there is already example code using a BS2p to parse this type of string. The BS2p was used because the entire string could be brought into the SPRAM which is 126 bytes. From there you could easily parse individual fields and display and/or output them. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • easyboteasybot Posts: 2
    edited 2009-06-25 18:41
    Hi Guys

    Thanks for the replys. When I first built this thing it worked fine.I knew I was pushing it on the BS2 but it worked.The data never goes over 26 bytes. and never less than 24.·The last data set is a PH reading and can be 2 digits. I think I will drop the fixed length to 24 and display ph at a lower level and free up the variables for other tasks.·This will save me having to rebuild the box since we are working on a new interface with the prop to go right to the sensor board anyway and then this is not needed. This was just to give a simple output for the lab or for demos that could output to anything with a video in jack. Using off the shelf hardware. Gess I should of spent the few extra bucks and bought the bs2p.

    The stamp seems to work OK at that speed for just data transfer. This is a wierd situation anyway. The device im reading only outputs every five seconds so why they used such a high speed is beyond me.



    Thank you again for your help. and if you have any further insights that might help me without changing hardware please send them on.

    Thanks
Sign In or Register to comment.