LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

read from serial port

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!

 

0 Kudos
Message 1 of 2
(3,033 Views)

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" Smiley Surprised ); 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



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(3,019 Views)