Tuesday, 31 July 2012

At last something that works...


Okay, I now have a working Gambas program that will read a formatted RS232 data stream and display the data as a dynamic bar chart.  To test this I rigged up my trusty old Psion II LZ and wrote a little OPL (Psion programming language) script to output a suitable random data stream.  The project is running on a laptop at the minute because I haven't gotten Gambas onto the RasberryPi yet and apparently it is quite slow, but I love the graphics.

The system is designed to work with 8 sensors and the data is 10-bit (values between 0-1023), so the format of a data frame is (at the moment) 18 bytes as follows -

- 'A' as the start character, the program reads data and ignores it until it receives an A;
- Pairs of bytes representing the upper and lower 5 bits of the 8 10-bit data values;
- 'B' as a terminating character.

To avoid confusion and make debugging easier, the 5-bit data is sent as bytes in the decimal range 32-63.  The ASCII codes for A and B are 65 and 66 respectively so no valid data byte can be an A or B or an ASCII control character.  Once the whole thing is operating properly, I may changes these.  The program detects all the possible errors in a data frame such as invalid data, invalid frame length or the terminator arriving too early and if any of these occur, the bad frame is ignored.  The program also has a timeout so that if no valid frame is received in 5 seconds, the chart is reset to zero.

For testing purposes the baud rate is at 9,600, but this is because the Psion works best at this rate.  Once the PIC is back in action, I will test the baud rate in steps right up to 115,200 checking for errors and see how we get on.

No comments:

Post a Comment