Showing results for 
Search instead for 
Did you mean: 

Check if serial port open

Good Morning All,

           I am in the process of writing a VI that takes data from a CompactDAQ (33 channels of Priority Data plus 11 channels of Secondary Data).  It is also reading a GPS and 10DOF sensor through a serial port.  Right now I am working on taking the Serial Port data and putting it in a TDMS file next to the 11 channels of Secondary Data.


         My question is this.  This is for flight testing, once we begin a flight, we need to record the 33 channels of Priority Data.  If we lose the serial port for any reason (USB cable comes loose, lose power to Sensor Pack, etc..) the VI needs to just ignore the loss and continue recording the Priority Data.


        My first thought is to find a property node for the VISA Serial Line that would check for an active port and tie that to a Case Structure that houses the Serial read, but I can't seem to find one that fits that bill.


       Does anyone out there have any ideas?  Thanks for looking.



0 Kudos
Message 1 of 6
If you lose the serial port, you'll get a timeout error when you attempt to read. You would just trap that error. No property node exists or is required.
0 Kudos
Message 2 of 6

If the port is lost (USB comes loose), you will get an error.  If nothing is coming into the port (wire breaks), you will get a timeout error.


My recommendation is to have many loops here.  Have a loop for the serial data, a loop for the priority data, and another loop for the writing to a TDMS file.  You can use a queue to send the data to the file write loop.  This way, if the serial port loop has errors, the other two loops will not care and will not even notice.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 6

Okay, I have tried to run the DAQmx and Serial in the same loop and as probably most of you already know, they wouldn't play nice with each other.


I have begun the process of splitting the Serial and DAQmx into their own loops for a Producer Consumer Setup. is the main VI for this experiment.


So far I have been able to set up two Producer Loops, haven't messed with Queues yet, or the Consumers.  I am getting both systems to display, the only problem is the Serial Loop.  You will see the values flash on the screen and then go back to zero.  It doesn't do this when I run just the Serial in a seperate VI, but when I add the DAQmx, it starts flashing.


I have tried the "Wait for Event" to not do anything until data is present on the serial port but no avail.


There are two more VI's needed, I will post a second reply to add those.


Thanks for the help.  Again, my main question at this point is trying to keep the GPS data on screen constantly even though the DAQmx data is refreshing at  a faster rate.

0 Kudos
Message 4 of 6

This reply is just to add the DAQmx Setup information.

0 Kudos
Message 5 of 6

I looked just briefly at the VI's and cannot comment on all right now, but one thing with the serial port enable event seems not right to me.

Why 'Service Request' event request? I played a couple of weeks ago with the serial port events and the 'Serial TermChar' event was working pretty good. It fires when the serial port sees the termination character, so you are sure that in this moment you can read the complete message.


I think even, without the events, 'Visa Read' will wait for termination character, so in general it is probably the same thing. Just make sure to have the correct termination character code wired to the Serial Port Configuration.


And just a side note: The serial port reading loop may not stop every time, particularly if the loop waits for serial port even, but there are no messages coming in.

0 Kudos
Message 6 of 6