Formatting serin data
docwisdom
Posts: 28
Hello all..
I am using serin from a computer point of sale system. I am getting the following information from the POS system and the relevent information I care about is R1 and T1.
sR1<CR><CR><CR><CR><CR><FF>sT1<CR><CR><CR><CR><CR><FF>
Can you give me some hints on how I could parse out all of the carriage returns?
so far to get just the R1 I am using
SERIN 1,16780,[noparse][[/noparse]STX, TYP, DEC QTY]'
DEBUG ? STX shows "s"
DEBUG ? TYP shows "R"
DEBUG ? QTY shows "1"
thanks!
I am using serin from a computer point of sale system. I am getting the following information from the POS system and the relevent information I care about is R1 and T1.
sR1<CR><CR><CR><CR><CR><FF>sT1<CR><CR><CR><CR><CR><FF>
Can you give me some hints on how I could parse out all of the carriage returns?
so far to get just the R1 I am using
SERIN 1,16780,[noparse][[/noparse]STX, TYP, DEC QTY]'
DEBUG ? STX shows "s"
DEBUG ? TYP shows "R"
DEBUG ? QTY shows "1"
thanks!
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
You'd have: SERIN 1,16780,[noparse][[/noparse]WAIT("s"),typ1,DEC qty1]
then: SERIN 1,16780,[noparse][[/noparse]WAIT("s"),typ2,DEC qty2]
something like depending on number of bytes, words
a var byte(3)
SERIN 1,16780,[noparse][[/noparse]a(0),wait ("ff"), a(1)]'
you could also use the skip modifier
Post Edited (Larry~) : 11/13/2009 12:48:28 AM GMT
As for what type of data is coming it. I basically want to know if the type is R or T and the QTY is a number from 1-255
but.....i forgot one thing
there isnt always a second item. In other words depending on what is purchased on the POS system it may be
sR10<CR><CR><CR><CR><CR><FF>
and thats it.
Mike: if the second item isnt purchased, it would nautally hang at the second SERIN command looking for data right? Should i do this in some kind of loop looking for more data?
Post Edited (docwisdom) : 11/13/2009 5:15:54 PM GMT
a var byte(4)
SERIN 1,16780,[noparse][[/noparse]a(0),a(1),wait ("ff"), a(2),a(3)]'
Post Edit -- I'm sure of it, it's the "sR" and "sT" jazz.· I looked around but nothing stood out to jog my recollection, bet it had some·daft·lamer title ("need help" or "noob question", "serin trouble", or sim.)
Post Edited (PJ Allen) : 11/14/2009 3:55:03 PM GMT
You could·compose a flow-chart or just keep beating around the bush.
PJ: Its an ongoing project with new hurdles & expectations every day. Apologies that I couldn't come up with all the problems at once and place them in one thread.
Mike,
I tried using timeout according to the manual but I run into two issues.
1. typ2 and qty2 show up as 0 no matter what
2. according to the manual, if the serin sees any valid data it will ignore the timeout. meaning it will see the <CR> and wont timeout.
I suspect you're going to have to do something completely different:
1) Slow down the Baud of the POS terminal, maybe as slow as 2400 so that the BS2 can parse the data itself rather than rely on the SERIN formatters.
2) Switch to a faster Stamp that can parse the data itself at the necessary speed. A BS2px is probably the fastest.
3) Switch to something like the Propeller which can handle all the work at high speeds.
The POS is running at 9600 and I am using a BS2px
I set the timeout for 2 seconds and im not sure why im getting 0 for typ2 and qty2.
Basically I have
SERIN 1,16780,[noparse][[/noparse]WAIT("s"),typ1,DEC qty1]
SERIN 1,16780,2000,CONT,[noparse][[/noparse]WAIT("s"),typ2,DEC qty2]
From what I have read in the manual if the second serin sees ANY valid serin data (whether it matches formatters or not) it will ignore the timeout.
Larry: Im not sure how to read the data if it doesnt exist. Basically if someone rings up type R items alone it will give me the total count. If someone rings up type T along it will give me the total amount. Its only if someone rings up R and T that I get the second set of data.
If I were to use your code SERIN 1,16780,[noparse][[/noparse]a(0),a(1),wait ("ff"), a(2),a(3)]' would it still hang looking for a(2) & a(3) if that data isnt there?
In testing, everything works great without a timeout and feeding two different types from the POS. As soon as I do the program hangs looking for the second block of data.
again thanks for all the help so far guys!
if not use the ("ff") thats always there and it will see the cr as the second item
and fill the second serin value with 13 then just look for a 13 in that data and don't use it
you may need to change it from 15 to 18 or 20 to capture all the data I want to see both ff's
a var byte(15)
SERIN 1,16780,[noparse][[/noparse]STR a\15]
debug STR a\15, cr
Post Edited (Larry~) : 11/16/2009 10:24:39 PM GMT
Got this with one item
sR1<CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><FF>
then this with two items
sR1<CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><FF>sT1<CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR><CR>
no second <FF> as it appears. ran it twice to be sure
Post Edited (docwisdom) : 11/16/2009 11:59:26 PM GMT
So, in summary, after the test results of the last post:
1. a valid type/qty pair always starts with "s"
2. the first string of characters always ends with <FF>
3. all the <CR> are just an irritation to the soul.
4. for an unknown reason, the second type/qty pair does NOT end with <FF>
5. the processor is a BS2px at 9600
Here's a method that might work, given the rather strange output from the POS system. This is not actual code, but close.
typ1 var byte
qty1 var byte
typ2 var byte
qty2 var byte
x var byte
serin 1,16780,[noparse][[/noparse]wait ("s") str typ1,dec qty1] ' grab the first set of data
do
serin 1, 16780,[noparse][[/noparse]str x] ' look at each of the subsequent bytes and discard unless its the <FF>
loop until x = 12 ' 012 is ASCII for FF ' when FF is found, get ready to see if a second set of data is coming
serin 1,16780,tim1,lab1,[noparse][[/noparse]wait ("s"),typ2,qty2] ' if "s" is seen, there is a second set, so grab it then proceed. If no second set is seen, timeout (because theres no serial activity) and proceed.
lab1:
'do rest of processing
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
in this program below it will capture both sets of data if there is no second set a3,a4,a5 will be 13,13,13 and you disregard this data and yes you will need to check this after reading the data
a var byte(6)
SERIN 1,16780,[noparse][[/noparse]wait ("s"), a(0),a(1),a(2), wait ("ff"), a(3),a(4),a(5)]
debug STR a\6, cr
Post Edited (Larry~) : 11/17/2009 2:15:42 AM GMT
Given the description of the data stream where <CR> is taken as Carriage Return, it follows that <FF> would be taken as Form Feed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
I believe with this code
a var byte(6)
SERIN 1,16780,[noparse][[/noparse]wait ("s"), a(0),a(1),a(2), wait ("ff"), a(3),a(4),a(5)]
debug STR a\6, cr
it will hang if there is no second string because there will be nothing after the ff to populate a3-a5. If there is no second string it stops at FF and no CRs follow it.
stamptrol:
ill give your code a test and see where I get. Your summary is dead on.
and yes that will be the case
I had a few problems with the above code. First the STR modifier wasnt allowed without having a variable length alloted (a\15)
I tried the script without the STR and it ran, but the loop kept stopping after 13 repetitions, even when the result wasnt 12. I was debugging x just to be sure.
Finally after tweaking and moving things around and adjusting code I came up with some that finally worked.
SERIN 1,16780,[noparse][[/noparse]SKIP 1,TYP,DEC QTY, WAIT(12)]
SERIN 1,16780,1000,CONT,[noparse][[/noparse]SKIP 1,TYP2,DEC QTY2]
it gives me my 4 variables that I care about and it times out properly. If anyone has an recommendation on the above code I am all ears.
Thanks for all the help from everyone.
Serial is always fun and a learning experience in every case. I had never tried putting the WAIT anywhere but the first of the brackets.
But, it obviously works and is yet another tool for using the command.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·