From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to talk to different serial ports simultaniously?

I need to be able to read from/write to four different serial ports simultaniously.

I'm trying to make a subvi called Tip.vi that handles all the actual writing, reading and parsing of data from a single port. I want to use 4 (instances/copies/whatever) of Tip.vi within a Main.vi.

Main.vi deals with user interactions, data gathering etc. Tip.vi has a string that get's updated with whatever bytes are currently available at the port. I want to keep this string within Tip.vi, not have to pass this to/from Main.vi.

I had all this working great with just one Tip.vi. When I added a second Tip.vi bad things happend.


  1. if two copies of the same code, named differently was used, one Tip.vi seemed to keep the second Tip.vi from running enough.

  2. if just the code Tip.vi reentrent the strings would get jumbled together, not stay seperate.

  3. if the code Tip.vi and all of it's subvi's reentrent still the strings would get jumbled.

  4. I tried making a template out of Tip.vi (so it's Tip.vit) but it wouldn't instantiate in Main.vi



I recognize that the VISA Read used in every Tip.vi will all happen serially, I can't figure out how to make VISA Read reentrenet.

I give up. How can I read/write to two ports simultaniously. Some sample code would be great.

Thanks very much for the help-
Ariel
0 Kudos
Message 1 of 5
(3,533 Views)
Using two copies of the same program with different names is the simplest approach and should work. Did you put them in two separate while loops or have a data dependency between them? If you don't want them in separate loops, use VI server to start them. To do this, use Open VI Reference with the path and name of the VI you want to run and then use an Invoke Node and select the method Run VI. Wire a false constant to the Wait Until done input. Do this for each subVI and you'll have each VI executing in parallel.

p.s. There's really no need to post the same question 3 times.
0 Kudos
Message 2 of 5
(3,528 Views)
Hi Dennis,

Yeah, sorry about the repeated post, when I tried to post, my computer would hang, so I'd stop, hit the back button and try to post again. Only on the third post did the computer not hang, I saw my mistake but didn't know how to erase it.


I've tried the differently named subvi's, but it seems that one subvi runs all the time, the other hardly at all. I assume this is because they use all the same subvi's. I could try to rename all the subvi's, but this doesn't seem a workable solution to have 10 different subvi's each renamed 4 times. I'm still trying to develop this, and keeping track of which subvi's are modified seems like a nightmare.
0 Kudos
Message 3 of 5
(3,522 Views)
Hello Ariel,

I am not sure what your code looks like, however, it is possible that you have enough parallel processes running that two of your serial port operations are being scheduled in the same thread. If this is the case, you will want to be sure that you are doing your VISA writes and reads Asynchronously so that thread is not locked by a given port until the entire VISA function completes (item 0. below describes how to check this). This will help allow better "interleaving" of operations within a given thread which may be servicing multiple processes.

In any event, I haven't seen your code but I think the following would be interesting to try (it will ensure that you are alternating operations between ports, so that one will not get services more than the other):

0. For sanity, right click on each VISA write and read function and make sure that the last item in the shortcut menu says "Do I/O Synchronously" (this means that the operation is currently being done Asynchronously!) This is shown in the second link below!

1. Write a simple program to communicate via your two serial ports (with whatever they are connected to), however, use dataflow (specifically the error cluster) to force a write and read on one port and then a write and read on another port to occur "one after the other." You can put this whole thing in a loop if you'd like; you can even do a write to port 1 then a write to port 2, then a read on port 1 then a read on port 2. The order really doesn't matter (unless timing is an issue); what we are going for here is programmatically forcing both ports to be serviced an equal number of times! Of course, a given write or read operation will occur based on the which VISA resource name (or corresponding duplicate) has been wired to it... so these will not be wired serially though all the VISA functions. The error cluster, however, should be wired serially (one after the other) through the functions, where we will then be dictating the flow of execution programmatically via dataflow.


Links:
------
UART FIFO Sizes and Performance:
http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/2d5f972cd550bbc386256f0b005e9a63?OpenDocument

Ansynchronous vs. Synchronous VISA Execution and Performance:
http://digital.ni.com/public.nsf/websearch/ECCAC3C8B9A2A31186256F0B005EEEF7?OpenDocument


Repost if you are still having problems!

Thank you,

JLS
Best,
JLS
Sixclear
0 Kudos
Message 4 of 5
(3,494 Views)
Thanks for the response, the problem was that the RS485 network didn't have any bias resistors. Some ports worked always, some ports worked sometimes, some never worked. With the bias resistors in place, they all work all the time.

Thanks,
Ariel
0 Kudos
Message 5 of 5
(3,472 Views)