Send a frame of ascii data using a BS2.
forbesg
Posts: 6
I need to simulate an instrument that sends data in a frame that is 10 bytes. The data is ASCII. This data must be sent to an RS232 port on, say pins 0 and 1. The baud rate will be 2400, data bits will be 8, no parity
Example frame will look like the following.
sExample 1 Displaying data of a scale:-10 Code of exclusive or check: 0C
Example 2 Displaying data of a scale:22040 Code of exclusive or check:14
Start
Weighing data(including subtraction sign and decimal point)
Exclusive or check
End
Low
High
Low
High
02
30
34
30
32
32
20
34
31
03
Example frame will look like the following.
sExample 1 Displaying data of a scale:-10 Code of exclusive or check: 0C
Example 2 Displaying data of a scale:22040 Code of exclusive or check:14
Start
Weighing data(including subtraction sign and decimal point)
Exclusive or check
End
Low
High
Low
High
02
30
34
30
32
32
20
34
31
03
Comments
You'll use serout and assemble the string you need. You'll have to have a loop to calculate the checksum according to the directions given by the manufacturer.
Note that using pins 0 or 1 will require the INVERTED form of SEROUT in order to give the receiving device a signal aproximating the rs-232 levels. Don't be surprised if you have to add a MAX232, MAX233 or ST232 chip to give an on-spec rs-232 set of voltages.
I've attached an old version of a string generator which generates a few specific strings. Note that it didn't need the checksum.
Cheers,
Thanks for this info. I am attaching sample data frames I will need to send. This is a wireless bluetooth application, so I will be sending the data to a BT to serial converter attached to my laptop. In actual use, the scale will send the data to this serial converter. So I will need to attach the serial cable to the BS2. I already have a backpack serial LCD on pin 0, I believe. All the other pins are available. So I guess I will need the x232 chip you mentioned. It has been years since I have done anything serious with a BS2, so please forgive my ignorance here.
Thanks for the help.
Dan
Are you using a Board of Education (BoE)?
Using your first example, the Stamp would send: (I just converted each 2-character hex code to ASCII. From left to right, that gives: STX, 0, 1, -,spc,spc,spc,chksum,chksum,ETX)
SEROUT 8,com_ind,[002,048,049,045,032,032,032,067,048,003]
The serial side of the BT converter should be able to connect to the programming port on the Stamp. That would eliminate the need for the xx232 chip.
You'll also have to create a routine to calculate the checksum characters, but only if they're needed by the receiving system.
Cheers,
Thanks. I just need to demonstrate that the system works. I tried to connect the BT serial port to the BS2 and connect using the stamp editor. It reports "No stamp connected" or something similar. It is an IO Gear GBS301. Perhaps I need to adjust some of its timing settings.
It has been years since I have looked at using my stamps. This is a re-learning process for me. Something I hope to use to launch a new side to my laser business. Thanks again for your help. Enjoy the holiday and be safe.
Forbes
I am using an OLD BS2 board with an OLD BackPack LCD display. Old as in 12 years or so.
ForbesG
I want to avoid clouding the issue at hand. Just wanted to know if your board was a Parallax product or your own devise. If it's a Parallax product then it should have the 9_pin programming port. Given that, you can/could send your test frames using SEROUT 16... and thereby pin#2 of the 9_pin.
Get the latest PBASIC IDE.
If you make your own 9_pin cable using just pin#2 and pin#5 then you don't have to worry about "echo" and all that stuff (from the on-board 4k7 resistor between pin#2 and pin#3).
Tom
Thanks. I have the latest PBasic download from Parallax so I should be fine there. I plan on making a simple program that transmits the serial data on one of several button pushes, thus simulating an on demand scale output. Once I have the program running, I should be able to remove the programming cable and plug in the BT cable. Thanks for the additional info.
ForbesG
Exactly, please see my reply to PJ. You both have advance my knowledge greatly.
I will modify and use your program.
Thanks,
Forbesg