From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-17-2015 09:56 AM
I followed a tutorial online to start learning basic serial communication. The tutorial involved shorting pins 1 and 3 on the Comm 1 port, and writing a simple program (attached). I edited the program a little, to show the varied results that I get when trying to write and read a simple phrase via serial port.
Could someone explain what causes the kind of result shown in "Serial Comm Example.png"? I believe it has to do with timing. Why would only parts of the phrase be transmitted?
Thanks,
Sarah
Solved! Go to Solution.
03-17-2015 10:50 AM
@sarahzig wrote:
The tutorial involved shorting pins 1 and 3 on the Comm 1 port
Shouldn't that be pins 2 and 3? On a standard DB-9 serial port, pin 2 is the Recieve and pin 3 is the Transmit.
Now for your code...
1. Move the Configure Serial Port to be before the loop. You only need to configure the port once.
2. Close the port after the loop.
3. Handle your error after the close.
4. Stop your loop on an error or the stop button was pressed. You will need an OR in there.
5. No need for the Flush Buffer function. Remove it.
6. Using the Bytes At Port is a dangerous thing. It introduces all kinds of interesting race conditions. Instead, tell the VISA Read to read the number of bytes you expect to read.
6a. Alternatively, be sure to send an End Of Line character at the end of your sent data and set the number of bytes to read to something a lot more than you would ever expect to read. The VISA Read will stop reading when it a) sees the number of bytes it was told to read, b) sees the termination character (currently enabled and set to a Line Feed, which is part of the End Of Line), or c) the timeout happens. Whichever happens first.
7. With 6, the wait is no longer needed.
03-17-2015 01:19 PM
Thanks for the help. I followed all your steps and am getting consistent writing + reading.
Sarah
03-17-2015 02:44 PM
How should I go about communicating with the pressure calibrator?I have two documents from the manufacturer. Would I write the commands into the "Write buffer" control on my VI?
03-17-2015 06:25 PM
08-17-2015 03:45 PM
Hi crossrulz,
I wanted to thank you for your comment on item 6a, I've been working on a program that contains a serial read component and had this issue of using Bytes At Port causing a race condition and I couldn't figure it out how to correct for until I read this.
I will add a Kudos!
Thanks.
Mike