LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read from the serial port and show it in a display?

Im using LabWindows/CVI 4.0.1.
I need to read 2 bytes from the serial port and show it in a display.
I dont know the command to use a default set of configuration in the serial port.
The example gives the ability to change the serial protocol, but i dont know much about C so even in looking in the code i dont understand it well, and i dont need to change the protocol, just set the serial as the well used 8N1 - 9600 bps is fine.

The numbers coming from the serial port can go up to 99 so a 2 digit display will work.

I will have to work on these numbers before they go to the display but i think i can do that by myself.

Thats all, just read and show.
Thanks.
0 Kudos
Message 1 of 4
(3,756 Views)
Which example have you looked at? There is the serial.prj example that you can find in the example finder. In fact, if all you are doing is outputing the data from the serial port, you can just use that example.
 
Regards,
Jack J.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,730 Views)
Thanks for the reply.
Thats the example im looking at. How can i set those parameters, i dont need a configuration screen as the parameters cant be changed. And i dont know why but the example is not working here, says the port must be 1 to 8 when i try to setup it in the configuration screen, and the ports 1 to 8 are the only options, strange.
I think the output goes to a text window, is there a display window that i could use? I think it would look better.
0 Kudos
Message 3 of 4
(3,716 Views)
Hi Malanar,
 
the sample project you are using is intended to be somewhat flexible so that it can meet as more need as it can, but you can use it as only a source reference and adapt it to your needs.
The configuration screen, as an example, is provided only to show you which parameters are settable in opening the serial port, but you absolutely don't need to have one in your application: your "the well used 8N1 - 9600 bps" configuration can be hardcoded in the source the same as port number, simply place somewhere in the code OpenComConfig () function appropriately setting all its parameters.
 
The same applies to reading and writing on serial channel: go into the sample code and take it as a reference, adapting it to your needs. You will need some knowledge about the device attached to the serial port in order to establish a dialogue.
As an example:
- Serial communication settings. OK, seems you know all about them
- Is the device expecting a termination character at the end of messages? And which one?
- Does the device responds with a termination character? If so, you can read up to this termination character (ComRdTerm), otherwise you must apply a correct delay or configure a timeout in reading (SetComTime)
- Consider that all messages are recived as a string: to interpret them as a number you must convert them appropriately (for example with strtoxxx functions).
 
Hope all this helps
Roberto


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?
0 Kudos
Message 4 of 4
(3,698 Views)