Shop OBEX P1 Docs P2 Docs Learn Events
Serial Strings For Timer — Parallax Forums

Serial Strings For Timer

walkboneswalkbones Posts: 30
edited 2006-12-13 15:34 in BASIC Stamp
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··
attachment.php?attachmentid=73784
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.
·
638 x 348 - 13K
«1

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-30 17:56
    Hello,
    ·
    ·· 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.
    CntTimer        PIN     1               ' I/O Pin for Serial Output
     
    ClockBaud       CON     2063            ' 1200 bps.
    STX             CON     2               ' Start Of Text
    ETX             CON     3               ' End Of Text
    P               CON     80
     
    SEROUT CntTimer, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-11-30 21:34
    Thank you very much, I have made good progress with the addition of the Constants and the Max232 [noparse];)[/noparse]

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-30 23:21
    Yes, that should work but, this assumes the device only replies with a single byte though…Do you know what the reply is supposed to be?· Is there a datasheet or manual online that can be viewed?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-05 16:45
    Sorry, I dropped the·project for a bit. The manual says - "When ever this poll request is sent to the display, the display will respond with <STX> <R><Value of the display> <ETX>". The DEBUG window shows the response but now· I'm trying·to figure out how to interpret the response in the code.



    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··

    attachment.php?attachmentid=73785

    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.
    638 x 348 - 13K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-05 18:11
    I guess what I was trying to say is that it seems the reply is multiple bytes, but you are only receiving the first one.· You will need to handle the remainder of the bytes to get the response.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 16:54
    I'd like to request some help form the group on this as I've hit·a wall on serout and serin commands.

    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]
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 17:30
    As an update, I just tried changing Clockbaud from the Inverted 1200 baud (18447) to True 1200 (2063) and was able to get the timer to display my time. Although only the last three digits. The left most digit stays zero. Progress though.

    Dan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 17:44
    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
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 18:17
    Here is the manual - http://edisupport.helpserve.com/index.php?_m=downloads&_a=viewdownload&downloaditemid=65

    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]
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 18:21
    Okay, I just tried the value.LOWBYTE value.HIGHBYTE knowing I probably had the format wrong and got nothing. But, when I switched back to just sending the 1244 time, all four digits popped up fine. Must be a timing issue?

    Dan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 18:51
    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.
    [color=black]SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", value.LOWBYTE, value.HIGHBYTE, ETX][/color]
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 19:41
    Chris,

    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


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 20:33
    Dan,
    ·
    · 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.

    SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", DEC4 value, ETX]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 20:48
    Chris,

    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 20:55
    Dan,
    ·
    · 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
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 21:20
    Chris,

    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................
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 21:31
    Well, knowing that you could in theory use a DEC modifier on the input as well.· Try something like this:

    [color=black]SERIN ClockIn, ClockBaud, [noparse][[/noparse]WAIT(STX, "R"), DEC value]
    [/color]
    

    Then debug value to the DEBUG screen using the DEC4 formatter...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 21:44
    Chris,

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 21:49
    Whoops!· I thought the return parameter was an ASCII R, instead try this...(no quotes)
    [color=black]SERIN ClockIn, ClockBaud, [noparse][[/noparse]WAIT(STX, R), DEC value]
    [/color]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 21:51
    Still hangs.
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 22:00
    This works somewhat. The reply are all DEC 255 but at least it doesn't hang afterwords.



    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 22:05
    Are you doing the SERIN after your SEROUT or just at any given time?·· Typically the device will send a response only when queried.· There must be a command to send to which requests this information.· Your code snippets don’t indicate this though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 22:11
    yes, I'm sending this first

    SEROUT ClockIn, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX]
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 22:13
    OOPs, I just now saw that I had ClockIn instead of ClockOut in that command. I tried it the correct way

    SEROUT ClockOut, ClockBaud, [noparse][[/noparse]STX, "01", P, ETX] and got a better response but I still ned to decifer it..
  • walkboneswalkbones Posts: 30
    edited 2006-12-07 22:40
    Here's the code in question so far and I uploaded it as well as a screen grab of the debug window.

    ' {$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
    1024 x 768 - 131K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 23:05
    It might help to display the DEC values of each byte on the screen…They look like binary values though, which would print garbage…

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • walkboneswalkbones Posts: 30
    edited 2006-12-08 01:55
    I tried adding DEC to the DEBUG but I didn't have the format correct.
    is it········· DEBUG STR DEC serStr··········I don't think that worked when I tried it.

    Dan
  • walkboneswalkbones Posts: 30
    edited 2006-12-08 16:58
    Chris,

    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-08 17:07
    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
  • walkboneswalkbones Posts: 30
    edited 2006-12-09 15:28
    Chris, I heard back from EDI. Attached is what they sent and below is the conversion chart I found. I'm still not clear on what the timer is doing.

    attachment.php?attachmentid=73786
    527 x 897 - 53K
Sign In or Register to comment.