LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Serial Communication using RS232

Solved!
Go to solution

Hello,

 

I have been doing some research on how to read and write using the serial port with RS232. The only example I found was a test program that is really involved. All I need to do is transmit 7 information bits which will pass through a digital communications kit then Read the same 7 info bits after the comm kit. (7 bits not including stop bits, parity bits..ect).

 

So I simply need to

 

-TX desired 7 info bits to comm kit (plus any stop bits needed)

-Information passes through comm kit (small delay)

-PC receives same bits back.

 

Any help would be much appreciated!

 

Im using CVI version 9

 

 

 

0 Kudos
Message 1 of 9
(15,745 Views)

Hi,

 

Here are the steps you can follow:

 

- Call OpenComConfig with appropriate parameters for COM port number, baud rate, data bits, parity, start/stop bits.

- Call ComWrtByte to send the single byte of information you mentioned.

- Call Delay to wait for some time.

- Call ComRdByte to read the data byte back.

- Call CloseCom to close the port after you are finished with using it. 

 

Do not forget to examine the function help for each of them and handle the error conditions appropriately.

Most common errors are:

 

- Invalid COM port (when you try to use a port that does not exist)

- COM read timeout (when you try to read from the input when there are no or not enough data bytes arriving)

 

Hope this helps, 

S. Eren BALCI
IMESTEK
Message 2 of 9
(15,740 Views)

Thanks for the quick response. Your solution is what I figured I would need to do. When I use the library for ComWrByte im not to sure what to put in for the Byte field, Status field and # Bytes written. Also for the ComRdByte the Bytle field and Status field.. Any advice?

 

Thanks

0 Kudos
Message 3 of 9
(15,736 Views)
Solution
Accepted by topic author kevan5

The byte field should be the data you want to send to the comm kit.

This is something you should know.

 

Status fields give you information about whether the function call performed successfully.

Most of the time 0 means success, and negative values mean error. But you need to read the function help for each function to be sure about that.

 

When you receive an error code you can use GetRS232ErrorString function to get a verbal description of the error.

# bytes written, as the name suggests, represent the number of bytes transfered to the COM port. You expect that value to be equal to the number of bytes you want to send for your application.

 

Hope this helps, 

 

S. Eren BALCI
IMESTEK
Message 4 of 9
(15,728 Views)

Hello all!

I'm novice in LabWindows.

So my problem: I want to make utility for working with COM1 (RS232).

It must scan ports state and indicate when some words are appeared. User button "Stop" must terminate scaanning.

By using sample RS-232RT (from LabWindows 9.0) I did this program, but I think that my program works illegal:(...

Is my code good? Or have I problem?

Thanks all!

 

Project in attachment.

P.S.: String "1234567890" emulates data from COM-port.

0 Kudos
Message 5 of 9
(14,268 Views)

Hello,

 

Unfortunately we do not write code for customers, however, if you are experiencing a specific error, we could work with you to get around this error.

 

It sounds as if you're looking for an example that can help you scan a com port.  I would open CVI and navigate to Help » Find Examples... 

 

This will allow you access to our shipping examples in the NI Example Finder.  There is a file tree in the center of the NI Example Finder.  You can navigate within this file tree to Hardware Input and Output » Serial.  Double click any of the workspace files (they end in .cws) to view them and get started.

 

Also you could look to www.ni.com/devzone and search for example code involving serial communication or serial ports.

 

I hope this helps and good luck on your project!

Regards,

Shawn S. | NIC
Instrument Driver/IVI PSE
National Instruments
0 Kudos
Message 6 of 9
(14,244 Views)

2Shawn S:

Hello! Thank you for answer.

By using two examples I solved my problem.

Thank you for link.

 

Regards!

0 Kudos
Message 7 of 9
(14,236 Views)

I can't find those examples mentioned above. Where are they?

 

I'm trying to do serial comm with a WinSystems PC104 SBC and their 8 port serial I/O board and I expect that the LabWindows RS232 Library will provide the necessary serial code but I would like to see some examples on how to use the library.

 

Thanks,

 

John

0 Kudos
Message 8 of 9
(14,174 Views)

Ok, found an example in the CVI Help under OpenComConfig.

 

Grumble grumble. I find it difficult to find these examples. I think NI should make it a little easier to find examples. Very annoying!

 

John Smiley Mad

0 Kudos
Message 9 of 9
(14,168 Views)