LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multi COM ports optimisation

Hello ladies and gentlemen,

 

I'm currently working with two COM/Serial ports and I would like to have the possibility of connecting to each port independently and also both at the same time. At the moment, my code only works if both ports are in use. In the event that one port is disconnected, this throws and error. 

 

Question 1: Does anyone have an idea on how to go about this? currently the only solution I can think of is to implement a case structure to handle the port selection.

 

Question 2Additionally, is it possible to save data from the two loops into one file TDMS file or any file format 

 

Attached is the vi. Heads up: It's a very block diagram but i will clean it up later once I'm done fixing some issues 

0 Kudos
Message 1 of 5
(163 Views)

Please do a "save for previous" (LabVIEW 2020 or below) and attach once more. This way more (including me)  have a chance to look at your VI.

 

You can use as many ports as you want in parallel.

Why are there two loops? Do they run at different rates?

Saving data to file is trivial.

 

Once I can open your VI and see what you are doing, it should be easy to find a solution.

0 Kudos
Message 2 of 5
(141 Views)

I have attached a new vi i really hope it works. 

 

Yes its possible to use two ports in parallel but i have an error handler on each and if one is not enabled. an error is thrown but i want to implement the flexibility of bein able to select one port at a time or both.

 

Ideally the loop should run at the same time. If I have one loop enclosing all the code. i have some error handling issues generated by the unconnected port. Which I why I decide to solve one step at a time starting with com port selection

 

0 Kudos
Message 3 of 5
(102 Views)

Sorry, I cannot really inspect your VI, because my laptop screen is not that gigantic, but from what I see there is some serious code smell.

 

  • Since you know how many bytes to read, why are you polling bytes at port? (start here)
  • Virtually none of your sequence structure make any sense because execution order is already determined by dataflow.
  • You stop almost everything with "stop" (or its local variables), except the lower outer loop that stops with "stop 2".
  • Why are you writing FALSE to the "stop" local twice?
  • Since the termination condition gets read immediately at the start of each iteration, you'll typically get another iteration before the loop can complete. Placing the terminal to the right  of the sequence does not delay the reading.
  • Why is there so much duplicate code?

What you need is a simple state machine that probably fits on a postcard properly modularized and handles all communications as desired (A, B, Both). I would start with simplifying the serial communication, so watch Tim's presentation in the link above.

0 Kudos
Message 4 of 5
(85 Views)

Thanks for the feedback. I will get back to you once I've checked Tim's presentation you linked and also cleaned up the code (i understand it's unnecessarily large). I will reupload a new vi 

 

As far as the current vi status is, the top section of code works as expected when I read from the sensor. The duplicate code was something that I was using to figure out some serial communication stuff and missed correcting some issues related to "stop"

 

0 Kudos
Message 5 of 5
(67 Views)