Serial Strings For Timer
walkbones
Posts: 30
Hi,
I've tried to communicate with a countdown timer I'm using. I know this should be simple but I've only controlled DVD players. This is a little more involved. How should this serial string be formatted for the BS2P and PBASIC 2.5. I have the Baud rate set:
ClockBaud······ CON···· 2063··········· ' 1200 bps.
Here is what the manual says:
POLLING DISPLAY PROTOCOL··
Examples:
··········· To poll the display set to an address of ‘01’, the following character sequence should be sent:
··········· <STX> <01> <P> <ETX> (a total of five characters)·
NOTE: When ever this poll request is sent to the display, the display will respond with <STX> <R><Value of the display> <ETX>.
To poll the display set to an address of ‘02’, the following character sequence should be sent:
··········· <STX> <02> <P> <ETX> (a total of five characters)
NOTE: When ever this poll request is sent to the display, the display will respond with <STX><R> <Value of the display> <ETX>.
PRESETING DISPLAY·PROTOCOL··
··············<STX> <01> <Preset Value> <ETX>
Note: < >’s will not be included in the message.
Factory set @· 1200BPS ; No parity ; 8 Data bits ; 1 or 2 Stop bits.
·
I've tried to communicate with a countdown timer I'm using. I know this should be simple but I've only controlled DVD players. This is a little more involved. How should this serial string be formatted for the BS2P and PBASIC 2.5. I have the Baud rate set:
ClockBaud······ CON···· 2063··········· ' 1200 bps.
Here is what the manual says:
POLLING DISPLAY PROTOCOL··
Examples:
··········· To poll the display set to an address of ‘01’, the following character sequence should be sent:
··········· <STX> <01> <P> <ETX> (a total of five characters)·
NOTE: When ever this poll request is sent to the display, the display will respond with <STX> <R><Value of the display> <ETX>.
To poll the display set to an address of ‘02’, the following character sequence should be sent:
··········· <STX> <02> <P> <ETX> (a total of five characters)
NOTE: When ever this poll request is sent to the display, the display will respond with <STX><R> <Value of the display> <ETX>.
PRESETING DISPLAY·PROTOCOL··
··············<STX> <01> <Preset Value> <ETX>
Note: < >’s will not be included in the message.
Factory set @· 1200BPS ; No parity ; 8 Data bits ; 1 or 2 Stop bits.
·
Comments
·
·· Two things to keep in mind…One, is the device RS-232 or TTL level serial?· This matters because if it’s RS-232 not only will you need a line driver such as the MAX232 but the data will be inverted.
·
· Also, you can declare constants for the <STX> and <ETX> so they can appear in the SEROUT line similar to the format used.· Try something like this, I hope it helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
1. When I send this, I get a single character response in the Debug window:
SEROUT CntTimer, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
How do I configure the code to receive and interpret the return string?
2. To preset the time then to say 12:44, would it be:
SEROUT CntTimer, ClockBaud, [noparse][[/noparse]STX, "01", 1244, ETX]
3. And the SERIN command, if the variable for serial in from the Clock was "inClock", would it be:
SERIN CntTimer, ClockBaud, [noparse][[/noparse]inClock]
DEBUG inClock, CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thanks again for your help. - Dan
There isn't much more of a manual beyond this. Here is the rest of the manual -
POLLING DISPLAY PROTOCOL··
Examples:
··········· To poll the display set to an address of ‘01’, the following character sequence should be sent:
··········· <STX> <01> <P> <ETX> (a total of five characters)·
NOTE: When ever this poll request is sent to the display, the display will respond with <STX> <R><Value of the display> <ETX>.
To poll the display set to an address of ‘02’, the following character sequence should be sent:
··········· <STX> <02> <P> <ETX> (a total of five characters)
NOTE: When ever this poll request is sent to the display, the display will respond with <STX><R> <Value of the display> <ETX>.
PRESETING DISPLAY·PROTOCOL··
··············<STX> <01> <Preset Value> <ETX>
Note: < >’s will not be included in the message.
Factory set @· 1200BPS ; No parity ; 8 Data bits ; 1 or 2 Stop bits.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I've implemented the advise so far on this project but I still am not clear on the proper·format of the "serout" and "serin" commands that will send the "preset" time to the timer and then "poll" the timer for the current time and capture the returned data. The first trick, I'm guessing from posts to the group from other threads,·is to establish timing, delays and·RS232 levels. Sending the "preset" string to the timer to give·it·a 4 digit time·should be pretty easy but I'm not able·to get the timer to receive·this with the BS2p. It does work with my PC, however.
I have the MAX232 for RS232 but I haven't really experimented with delays. Here is the command I'm sending the timer to set it to 1244 and nothing happens. (If I set up a serin command there is some response from the timer but not useful.)
*******************************************************************
ClockBaud······ CON···· 18447·········· ' 1200 bps, inverted
STX············ CON···· 2·············· ' Start Of Text
ETX············ CON···· 3·············· ' End Of Text
P·············· CON···· 80············· ' Poll
R·············· CON···· 82············· ' Replay
ClockIn········ PIN···· 13············· ' From Clock - Serial Data· 1200 bps
ClockOut······· PIN···· 12············· ' To Clock - Serial Data··· 1200 bps
Main:
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "0", 1244, ETX]
*******************************************************************
Here is the information from the manual. Of course it has not advise on using Basic Stamps. I'd appreciate any advise and tips for this - Dan
[size=+0]
ASCII·and it's DEC value from the manual:
"STX"··DEC 2··< This is Start of text’(STX), also known as a ‘control B’, this character must be the first character of each message.
"AD1"·and "AD2"·DEC 48-57·< These two ASCII decimal digits represent the address of the display as set on the display.
"P"·DEC 80 <Numeric value to be displayed in ASCII decimal digits. It is also permissible to include space characters (character value 32 decimal), minus sign characters (character value 45 decimal), and one decimal point character (character value 46 decimal) with the digits.
"ETX"·DEC 3 <‘End of text’(ETX), also known as a control C, this character must be the last character of each message.
Examples: To poll the display set to an address of ‘01’, the following character sequence should be sent:
"<STX> <01> <P> <ETX>" (a total of five characters)
NOTE: When ever this poll request is sent to the display, the display will respond with "<STX> <R> <Value of the display> <ETX>".
To poll the display set to an address of ‘02’, the following character sequence should be sent:
"<STX> <02> <P> <ETX>" (a total of five characters)
NOTE: When ever this poll request is sent to the display, the display will respond with "<STX> <R> <Value of the display> <ETX>".
PRESETING DISPLAY PROTOCOL
"<STX> <01> <Preset Value> <ETX>"
Note: < >’s will not be included in the message.
Factory set @ 1200BPS ; No parity ; 8 Data bits ; 1 or 2 Stop bits.[/size]
Dan
·
·· Is there a PDF version of the manual available?· I think at this point the biggest bottleneck is not know the details of some of the commands.· Interesting on the time thing, but you’re trying to send 1244 which is a word sized value, but the serial protocol only allows for byte sized data.· So you’ll need to send the data as two bytes.· You will need that value in a variable which you can then send as value.LOWBYTE, value.HIGHBYTE (or visa versa depending on how the unit expects it).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
That manual doesn't say too much about protocol for·using Basic Stamps. I looked at value.LOWBYTE and value.HIGHBYTE, these are a couple of new ones for me. More to learn. Is this what you mean
value··········· VAR···· word
value=1244
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", value.LOWBYTE, ETX]
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", value.HIGHBYTE, ETX]
Dan
·
·· Putting the 1244 in the SEROUT command like that won’t send it, but will only send the lower 8 bits.· Are you getting 1244 on your display?· You need to form the command as follows...Of course, you have to set value = 1244 and declare the variable as a word.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I tried·your suggestion·but it did not·change the display.
value VAR Word
value=1244
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", value.LOWBYTE, value.HIGHBYTE, ETX]
However, sending 1244 really does display 1244 on the·timer with
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", "1244", ETX]
The reply from the display in the DEBUG window is 255 when I have SERIN like this
SERIN ClockIn, ClockBaud, [noparse][[/noparse]inClock1]
DEBUG DEC inClock1, CR
For polling the timer
If I add a "Poll" command like the following the reply changes from 79,9,19,39,159 as a repeat the "Poll" command.
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
SERIN ClockIn, ClockBaud, [noparse][[/noparse]inClock2]
DEBUG DEC inClock2, CR
·
· I see why…Earlier when you posted the SEROUT line with 1244 you had no quotes around it.· In that case it is treated as a number by SEROUT and only the lower 8 bits would be sent.· In your current code you have quotes around it, which SEROUT treats differently.· In this case it sends out 4 ASCII characters representing those characters.· In this case you’re now locked to that text.· This can also be done from the word variable by placing the DEC modifier in front and allowing you to change what is sent.· See the following code…It will send the 4 ASCII characters of the value in the variable, ‘value’.· Again, value must be declared as a word variable.· Now, whatever the value of 'value' is can be sent.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
That worked fine. Thank you. Does any of this tell us how to capture the incoming data after issuing a Poll command?
I send·the lines of code below·and I get a·one or two digit·decimal number in the debug window(different ones). You said before, that what I need to do is·capture multiple bytes. It looks like I should wait for the STX and "R", according to the manual, before execting the 4 digit number (represented by ASCII characters?) followed by the ETX. How can I change serin to capture multiple bytes?
ClockIn········ PIN···· 13············· ' From Clock - Serial Data· 1200 bps
ClockOut······· PIN···· 12············· ' To Clock - Serial Data··· 1200 bps
·
inClock··· VAR·· Word
·
ClockBaud······ CON···· 2063··········· ' 1200 bps True, (18447 is inverted)
STX············ CON···· 2·············· ' Start Of Text
ETX············ CON···· 3·············· ' End Of Text
P·············· CON···· 80············· ' Poll
R·············· CON···· 82············· ' Reply
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
SERIN ClockIn, ClockBaud, [noparse][[/noparse]inClock2]
DEBUG DEC inClock2, CR
·
· The manual you posted seems to deal with Windows software and nothing about the serial protocol…It would really help to know what type of responses this thing sends back.· That would help form code to receive them.· You could create a small array and use the SERIN command with the STR modifier to stuff the data into an array which could then be sent to the DEBUG window.· This would allow you to see what comes back.· If the messages end with a CR for example, you could set that as the terminating character.· The Help File and BASIC Stamp Manual go into more detail on STR, but again, it helps to have some knowledge about how many bytes are being sent back.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
There's another·new one for me to research, the STR modifier·and arrays.·I only have a few hours left to try to nail this down but I'll get crackin on the Help File and see how fast I can learn it.
The information I do have says the following should be in the reply·-
STX, R, Value of the display, ETX
Just typing out loud to see if I'm an idiot..........
That's 7 bytes?· The Start of Transmission should be DEC 2 and the End Of Transmission should be DEC 3. I know that much. After the STX is the "R" which should be DEC 82, I'm guessing. That means what's left is the value of the display which should be bytes·3,4,5,6 .· Now, how do I·fashion a bit of code that reads all bytes into a 7 byte string and then grab numbers 3,4,5,6 and store them into variables? Any clues?
I'm off to my Help File................
Then debug value to the DEBUG screen using the DEC4 formatter...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
When I tried that I didn't get a reply and the system seems to hang. It no longer responds to my inputs to trigger preset or poll commands. It must be waiting for something.
Dan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
serStr(6) = 0································ ' Put 0 in last byte
· SERIN ClockIn, ClockBaud, [noparse][[/noparse]STR serStr\6]··············· ' Get 9-byte string
· DEBUG STR serStr·························· ' Display the string
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
SEROUT ClockIn, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX] and got a better response but I still ned to decifer it..
' {$STAMP BS2p}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
KeyRdy········· PIN···· 14············· ' Data Valid
KeyPad········· PIN···· 15············· ' Key Serial Data
ClockIn········ PIN···· 13············· ' From Clock - Serial Data· 1200 bps
ClockOut······· PIN···· 12············· ' To Clock - Serial Data··· 1200 bps
'
[noparse][[/noparse] Constants ]
KeyBaud········ CON···· 240············ ' 9600 bps (BS2p)
ClockBaud······ CON···· 2063··········· ' 1200 bps True, (18447 is inverted)
STX············ CON···· 2·············· ' Start Of Text
ETX············ CON···· 3·············· ' End Of Text
P·············· CON···· 80············· ' Poll
R·············· CON···· 82············· ' Reply
'
[noparse][[/noparse] Variables ]
time············ VAR··· Word
serStr········· VAR···· Byte(10)······················· ' Make a 10-byte array
inKey·········· VAR···· Byte··········· ' Data From EDE1144
outKey········· VAR···· Byte··········· ' Translated Data
inClock1········ VAR···· Word·········· 'Data from Clock
inClock2········ VAR···· Word
inClock3········ VAR···· Byte
value··········· VAR···· Word
sData··········· VAR···· Word
'
[noparse][[/noparse] Program Code ]
Main:
·DO
··· GOSUB KeyScan······················ ' Get A Keypress
· LOOP································· ' Forever
· STOP
'
[noparse][[/noparse] Subroutines ]
KeyScan:
· DO : LOOP WHILE KeyRdy = 1··········· ' Wait Until Data Valid
· SERIN KeyPad, KeyBaud, [noparse][[/noparse]inKey]······· ' Get Key Value
· inKey = inKey - 48··················· ' Remove ASCII Value Offset
· IF inKey < 10 THEN KeyScan2·········· ' Key Is 0 - 9
· inKey = inKey - 7···················· ' Key Is A - F, Remove ASCII Offset
KeyScan2:
· LOOKUP inKey, [noparse][[/noparse]49, 50, 51, 65, 52, 53, 54, 66, 55, 56, 57, 67, 42, 48, 35, 68], outKey
'················ 1·· 2·· 3·· A·· 4·· 5·· 6·· B·· 7·· 8·· 9·· C·· *·· 0·· #·· D
··· PAUSE 50
· 'DEBUG outkey, CR
··· PAUSE 50
· IF outkey = 49 THEN One
· IF outkey = 50 THEN Two
· RETURN
One:
DEBUG "One",CR
PAUSE 20
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", "1357", ETX]
PAUSE 20
GOTO Main
Two:
value=2468
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", DEC4 value, ETX]
PAUSE 20
SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
serStr(9) = 0································ ' Put 0 in last byte
SERIN ClockIn, ClockBaud, [noparse][[/noparse]STR serStr\9]··············· ' Get 6-byte string
DEBUG STR serStr·························· ' Display the string
PAUSE 20
GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
is it········· DEBUG STR DEC serStr··········I don't think that worked when I tried it.
Dan
I have a call in to EDI but haven't heard back. Do you have any other ideas on how to understand what the data from the timer is?
Dan
·
·· I don’t know…You may have to wait for them if the documentation doesn’t specify the return values.· Have you tried searching the internet for the information?· In Tech Support we sometimes test code by simulation.· If you know what a device returns you can have a second BASIC Stamp transmit that and test the ability of your code to properly handle it.
·
·· I once helped a customer with a counter system.· The module he had counted events with multiple internal counters which could be read by sending serial commands to the device and it would respond with the counts.· He had the datasheets and you could clearly see its command structure and responses for a given command.· I programmed a BS2 to simulate the device, accepting its commands and returning the appropriate responses.· I then advised him on changes to his code.
·
·· The interesting thing is how easy it was to simply do all the work in the BS2.· Had his system not been so dependant on that module he could’ve use a BASIC Stamp and not gotten lost in translation, so to speak.· Anyway, the datasheets he had clearly listed the formatting of the responses so you knew exactly how many bytes were returned for given commands.· If you had this information it would be so easy to work out the code.· Maybe they will get back to you with the information.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support