03-09-2009 09:15 PM
Hello, Ill first state that i am not a strong programmer. I need a program that will continously read 8 bits from my serial port(8 bits represents a level from a microcontroller) and output them to a level indicator(GUI). I have been fooling around with the libraries but im still havin trouble. Does anyone have any sample code that will do this?
Thanks a lot in advance!
03-10-2009 12:56 AM
Hello kevan5,
there is an example program of a basic serial writer/reader that you can youse as a reference on using the RS232 library, you can find it with the example finder, looking for "serial". I suggest you to take a look at the example as it gives you a sample usage of all instructions that can be used to communicate over the serial channel.
Regarding your actual problem, you must consider some hints before developing the application:
- serial communications parameters: you will nedd them when using OpenComConfig to accomodate communications standard to your external device
- do you need some polling to have the readings back from the device? Use ComWrt in thes case tosend the proper request message to the device
- give the device enough time to answer!
- what does "continuously" mean for you: every 10 msec? every 100? I suggest that you do not develop this part in a loop as it will consume all system resources and will not let you perform other tasks (even the very simple "stop application" ); you could use a timer instead (initially a UI timer that could be passed to a Async Timer in a second step)
- reading the results is the simple part: ComRd will return you a string that you can scan to obtain the integer value corresponding to the 8 bits received
- remember to trap RS232 errors during your program