LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel processing using visa with a serial port

Hello everyone,

I'm a begginer with Labview and recently had to write a Labview programme to monitor and control the power supply of a superconducting magnet. The power supply is connected to the PC by a USB to Serial cable. I studied carefully most of the VISA examples and started programming. The structure of the programme is composed by an initialisation stage followed by the output reading and issuing commands to ramp the field, etc. Ideally, the output reading should be independent from the rest and should be reading at all times.

The problem is there is only one common communication channel so whenever I do a VISA Read, doesn't matter where it's issued, it always reads the last request made, i.e. let's suppose I request the magnet output. doing a VISA Write to send the command. If between the VISA Write and VISA Read - to read the magnet output string - there was another VISA Write in another branch of the programme, requesting another thing, the string returned is stacked on top of the last one so the programme reads the wrong string, corresponding to another request.

I tried to write the programme in only one branch and it went fine because it was processing in sequence, always waiting for the last request and doing one thing at the time until I needed to have this big subvi in the middle that waited while the magnet was ramping from one point to another. During this stage there was no output reading, of course.

Is there a way to have multichannel communication is this case? Is there a way to protect (encapsulate?) the Write->Read sequences in order to read only the corresponding string?

Sorry for my english and thanks in advance,

Pedro
0 Kudos
Message 1 of 4
(2,733 Views)
Pedro,

One way to protect the resource (the serial port in your case) is to use a single VI which does all the writes and reads to and from the port. It can have several functions or modes of operation. An Initialiazation mode sets the port to the proper baud rate, handshaking and other settings. Read and Write are obvious. To solve your particular synchronization issue add a Write then Read mode. The VI writes a command to the magnet and waits until it has Read the response before it returns. No other part of the program can call the VI while it is waiting for the read. The VI should probably also have an exit mode where it releases the port after the program is done with it. Search the Forum for "Action Engine." There are examples of how to implement this type of VI.

Lynn
0 Kudos
Message 2 of 4
(2,721 Views)

I would suggest to have a separate loop for just VISA communication. This loop should be triggered by the other parts of the program to Wr and Rd through many different commands. This COM loop can be done in such a way that when each command is triggered by the main loop/loops, each command will be carried out in sequence (you can use Q structure for this). So by doing this way, you can ensure that each command's response is correct each & every time. So here the main point is having only one loop for communication since all your Rd/Wr operations are through a single COM port.

0 Kudos
Message 3 of 4
(2,710 Views)
Thanks very much for the reply. I will consider both suggestions. Deepu: Could you please tell me what do you mean with Q structure?

Thanks,

Pedro
0 Kudos
Message 4 of 4
(2,694 Views)