DEC with SERIN
docwisdom
Posts: 28
I am capturing a serial string from a POS system. They are custom coupon codes that we programmed into the POS.
basically the string is: sR15e
s=start bit
R=type
15=qty
e=end bit
In order to capture the relevant material "R" & "15" I used the following SERIN command, then debugged the variables. From what I have read, DEC QTY should capture only numeric characters and stop once it reaches a non-numeric character (in my case "e")
Unfortunately the debug is not showing the variables or their values. Can anyone spot what I may be doing improperly?
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM4}
STX VAR Byte
TYP VAR Byte
QTY VAR Word
SERIN 1,16468,[noparse][[/noparse]STX, TYP, DEC QTY]
DEBUG ? STX
DEBUG ? TYP
DEBUG ? QTY
basically the string is: sR15e
s=start bit
R=type
15=qty
e=end bit
In order to capture the relevant material "R" & "15" I used the following SERIN command, then debugged the variables. From what I have read, DEC QTY should capture only numeric characters and stop once it reaches a non-numeric character (in my case "e")
Unfortunately the debug is not showing the variables or their values. Can anyone spot what I may be doing improperly?
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM4}
STX VAR Byte
TYP VAR Byte
QTY VAR Word
SERIN 1,16468,[noparse][[/noparse]STX, TYP, DEC QTY]
DEBUG ? STX
DEBUG ? TYP
DEBUG ? QTY
Comments
Make sure the signal from the POS terminal is correct for the Baud constant you're using. You're using 16468 which specifies 9600 Baud and an inverted signal (idle low). What's the output from the POS terminal and how do you have it connected?
The baud rate seems to be correct because if I do the following code, it debugs just fine. Each variable is filled out properly. The problem is that the QTY is going to be variable length and I cant pad it with 0's in the POS output. Therefore it could be sR5e or sR22e or sR158e, etc
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM4}
STX VAR Byte
TYP VAR Byte
QTY VAR Word
SERIN 1,16468,[noparse][[/noparse]STX, TYP, QTY, ETX]
DEBUG ? STX
DEBUG ? TYP
DEBUG ? QTY
DEBUG ? ETX
allan:
The non-numerical character "e" should tell the DEC that it has finished. At least according to the datasheet on SERIN
If this is in fact the problem. How can I interpret the incoming data as decimal not ASCII?
I wonder if "15e1" is a valid DEC string?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
I will look up arrays in the manual and see what I can do about getting you some sample data. This was my original approach. I was going to use a value separater, but PBASIC doesnt have a split function. ie s|R|15|e
The format would be similar to the following
SERIN 1,16468,[noparse][[/noparse]STX, TYP, STR QTY\3 \"e"]
Jeff T.
DEC worked great at 4800 baud. I may use that for now, but I have heard that POS software upgrades default the printers to 9600
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
Depending on how the string is formed realistically, he may be able to use the BS2 at 9600bps just fine. For example, using STR you can easily receive at 9600. The question is, is that the ideal way to handle this data? Without seeing it I can't say for sure.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
sR15e
where 15 is the variable quantity (up to 3 digits)
it is all coming through ASCII
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
Apologies for the multiple threads. I didnt want to confuse the different issues I was having by mixing them up in one thread. Ill keep that in mind for the future. Different boards, different rules.