PDA

View Full Version : Serial Strings For Timer



walkbones
12-01-2006, 01:26 AM
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··
http://forums.parallax.com/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.
·

Chris Savage
12-01-2006, 01:56 AM
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, [STX, "01", P, ETX]

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

walkbones
12-01-2006, 05:34 AM
Thank you very much, I have made good progress with the addition of the Constants and the Max232 ;)

1. When I send this, I get a single character response in the Debug window:
SEROUT CntTimer, ClockBaud, [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, [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, [inClock]
DEBUG inClock, CR

Chris Savage
12-01-2006, 07:21 AM
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

walkbones
12-06-2006, 12:45 AM
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··

http://forums.parallax.com/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.

Chris Savage
12-06-2006, 02:11 AM
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

walkbones
12-08-2006, 12:54 AM
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, [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

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.

walkbones
12-08-2006, 01:30 AM
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 Savage
12-08-2006, 01:44 AM
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

walkbones
12-08-2006, 02:17 AM
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, [STX, "01", value.LOWBYTE, ETX]
SEROUT ClockOut, ClockBaud, [STX, "01", value.HIGHBYTE, ETX]

walkbones
12-08-2006, 02:21 AM
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 Savage
12-08-2006, 02:51 AM
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.


SEROUT ClockOut, ClockBaud, [STX, "01", value.LOWBYTE, value.HIGHBYTE, ETX]


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

walkbones
12-08-2006, 03:41 AM
Chris,

I tried·your suggestion·but it did not·change the display.

value VAR Word
value=1244
SEROUT ClockOut, ClockBaud, [STX, "01", value.LOWBYTE, value.HIGHBYTE, ETX]

However, sending 1244 really does display 1244 on the·timer with

SEROUT ClockOut, ClockBaud, [STX, "01", "1244", ETX]

The reply from the display in the DEBUG window is 255 when I have SERIN like this

SERIN ClockIn, ClockBaud, [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, [STX, "01", P, ETX]
SERIN ClockIn, ClockBaud, [inClock2]
DEBUG DEC inClock2, CR

Chris Savage
12-08-2006, 04:33 AM
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, [STX, "01", DEC4 value, ETX]

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

walkbones
12-08-2006, 04:48 AM
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, [STX, "01", P, ETX]
SERIN ClockIn, ClockBaud, [inClock2]
DEBUG DEC inClock2, CR

Chris Savage
12-08-2006, 04:55 AM
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

walkbones
12-08-2006, 05:20 AM
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 Savage
12-08-2006, 05:31 AM
Well, knowing that you could in theory use a DEC modifier on the input as well.· Try something like this:



SERIN ClockIn, ClockBaud, [WAIT(STX, "R"), DEC value]


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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

walkbones
12-08-2006, 05:44 AM
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 Savage
12-08-2006, 05:49 AM
Whoops!· I thought the return parameter was an ASCII R, instead try this...(no quotes)

SERIN ClockIn, ClockBaud, [WAIT(STX, R), DEC value]


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

walkbones
12-08-2006, 05:51 AM
Still hangs.

walkbones
12-08-2006, 06:00 AM
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, [STR serStr\6]··············· ' Get 9-byte string
· DEBUG STR serStr·························· ' Display the string

Chris Savage
12-08-2006, 06:05 AM
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

walkbones
12-08-2006, 06:11 AM
yes, I'm sending this first

SEROUT ClockIn, ClockBaud, [STX, "01", P, ETX]

walkbones
12-08-2006, 06:13 AM
OOPs, I just now saw that I had ClockIn instead of ClockOut in that command. I tried it the correct way

SEROUT ClockOut, ClockBaud, [STX, "01", P, ETX] and got a better response but I still ned to decifer it..

walkbones
12-08-2006, 06:40 AM
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}
' -----[ 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
' -----[ 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
' -----[ 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
' -----[ Program Code ]----------------------------------------------------
Main:
·DO
··· GOSUB KeyScan······················ ' Get A Keypress
· LOOP································· ' Forever
· STOP
' -----[ Subroutines ]-----------------------------------------------------
KeyScan:
· DO : LOOP WHILE KeyRdy = 1··········· ' Wait Until Data Valid
· SERIN KeyPad, KeyBaud, [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, [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, [STX, "01", "1357", ETX]
PAUSE 20
GOTO Main
Two:
value=2468
SEROUT ClockOut, ClockBaud, [STX, "01", DEC4 value, ETX]
PAUSE 20
SEROUT ClockOut, ClockBaud, [STX, "01", P, ETX]
serStr(9) = 0································ ' Put 0 in last byte
SERIN ClockIn, ClockBaud, [STR serStr\9]··············· ' Get 6-byte string
DEBUG STR serStr·························· ' Display the string
PAUSE 20
GOTO Main

Chris Savage
12-08-2006, 07:05 AM
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

walkbones
12-08-2006, 09:55 AM
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

walkbones
12-09-2006, 12:58 AM
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 Savage
12-09-2006, 01:07 AM
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

walkbones
12-09-2006, 11:28 PM
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.

http://forums.parallax.com/attachment.php?attachmentid=73786

walkbones
12-12-2006, 05:24 AM
Hi Chris,

Herer is what else EDI had to say, regarding using Hyperterminal to test the timer. Can the Stamp recognize black mask and herat shapes?

"Make sure to activate the ASCHII ECO and you should see in the monitor: a symbol like black mask followed by address of the sign (01) the actual data and a symbol like a heart shape."··

Chris Savage
12-12-2006, 09:49 AM
The things you refer to are actually just values that have that appearance in Hyper Terminal.· Your list doesn’t show those figures so it wouldn’t be possible from here to identify which figure goes with which value but it sounds like it receives a binary value, followed by some ASCII characters, then another binary value.· I think this is one of those things you will have to experiment with.· Knowing the address and data expected can help you pinpoint the data you’re looking for and how many bytes there are in a sequence.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

walkbones
12-13-2006, 08:44 AM
Hi folks,

In case anyone was following the details of this thread, here is the code that works for "polling" this timer with RS232. It replys with 8 bytes -

STX=2
Address 0·= 48
Address 1 = 49
Data for the time·if the time was 1111 =
49
49
49
49
ETX = 3

ClockBaud······ CON···· 2063··········· ' 1200 bps True, (18447 is inverted)
STX············ CON···· 02············· 'Start Of Transmission
ETX············ CON····· 03············ 'End Of Transmission
P·············· CON···· 80············· ' Poll

serStr········· VAR···· Byte(8)······················· ' Make a 8-byte array·

SEROUT ClockOut, ClockBaud, [STX, "01", P, ETX]

SERIN ClockIn, ClockBaud, [STR serStr\8]··············· ' Get 8-byte string
DEBUG DEC?· serStr(7)," "·························· ' Display the string
DEBUG DEC?· serStr(6)," "·························· ' Display the string
DEBUG DEC?· serStr(5)," "·························· ' Display the string'
DEBUG DEC?· serStr(4)," "·························· ' Display the string
DEBUG DEC?· serStr(3)," "·························· ' Display the string
DEBUG DEC?· serStr(2)," "·························· ' Display the string
DEBUG DEC?· serStr(1)," "·························· ' Display the string
DEBUG DEC?· serStr(0)," ",CR·························· ' Display the string

Turns out that the primary cause of grief, as software guys always say, was "hardware!" related. I had a bad ground on the Max232. Go figure.

Dan

Chris Savage
12-13-2006, 11:34 PM
Dan,
·
·· I’m glad to see you got it figured out.· Take care.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support