LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial port read then write

Hello,

I need to read serial data on a com port that could arrive anytime then respond with a message that varies depending on what's been read. Using the Basic_Serial_Write_and_Read vi I can read the data that is being sent but I'm not sure how to respond. Also it seems like this vi waits for the programmed amount of time then displays the read buffer. I need to be able to communicate with the device that is talking to the serial port. IE always be waiting and receiving data until something is received then write something back then receive again. Also I'm not always sure how many bytes may be sent by the device.

This is the string I receive "999999999999" Can it be displayed as hex instead of ascii?



Thanks,
Jared
0 Kudos
Message 1 of 4
(2,951 Views)

it seems like this vi waits for the programmed amount of time then displays the read buffer. I need to be able to communicate with the device that is talking to the serial port. IE always be waiting and receiving data until something is received then write something back then receive again. Also I'm not always sure how many bytes may be sent by the device.


The serial read VI tries to read X bytes from the serial buffer, and if it doesn't find X bytes, it waits until the timeout set using the VISA Configure VI expires, then returns with a timeout error. If you're not receiveing on a regular basis, you can use the Bytes at Serial Port property (which is located on the serial palette) to detect if you have data waiting by placing it inside a while loop and using comparison function to stop the loop.

You can respond by using the VISA Write VI which can also be found in the serial palette. Just wire the VISA Resource name and\or error terminals from the read to the write to force the write to happen after the read. There are also several other ways to do this. You can select how to respond by using a case structure.


This is the string I receive "999999999999" Can it be displayed as hex instead of ascii?

Do you want to display the ascii values in hex or do you want to display the numeric value (9999)? For the first you can simply right click the string indicator and select Hex Display. For the second, you will need to identify each block (apparently starting and ending with 144 ascii) and use the string functions to extract the number and then convert it to a hex number.

To learn more, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here is one you can start with and here is another. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide.


___________________
Try to take over the world!
Message 2 of 4
(2,932 Views)
OK -- Thanks Much
0 Kudos
Message 3 of 4
(2,921 Views)
I also learned many from you, i doing some experiment for serial this moment.
Simon
0 Kudos
Message 4 of 4
(2,878 Views)