LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bi-directional communication with an instrument using VISA

Hi there,

Given an instrument of which has two operating modes.:
1) User mode: it can be timed or polled. I can configure it manually so far.
2) Link mode: it has a list of commands that i would like to use.
------------------------------
My problem is that i can't get the instrument to work in 'link mode' in order to be able to configure it with Labview.
To start link mode i have to send command CMD1 to the instrument. Then i should be waiting for response. In response i should receive MESSAGE1 as response.
Result shows i keep on getting the following data trough UART:
29.01.19,17:09:33,000.2 ppm,000.2 ppm,000.2 ppm,000.2 ppm,000.2 ppm,000.2 ppm,0000

I'd like to make sure if my VI works as desired for bi directional communication.

Could someone please tell me if it does?
Kind regards,
Balázs

0 Kudos
Message 1 of 2
(1,850 Views)

Don't be offended, but I'm about to yell something because I keep seeing people do this and I have no idea why.

 

DON'T USE BYTES AS PORT!  It is the wrong thing to use 99% of the time.

 

Actually  I kind of know why.  The LabVIEW example VISA Simple Write/Read uses it.  And it is a very poor example of serial communication.  But the one thing it uses that you left out is the wait between the write and the read.

 

What happens in your VI?  You write a command.  You immediately check how many bytes are at port.  It is almost certainly zero since you didn't give the device enough time to receive the command, process it, and return a response.  So you'll read zero bytes.  (or maybe a few if a couple bytes did get back quickly.)  Next iteration 500 msec later, you write a command, check bytes at port.  It will probably be longer and you'll get the response from the previous Write.  Or it might only be a partial response.  Who knows.

 

I'm going to assume your device uses termination characters.  Read the manual for this device! Most ASCII type communication will end with a carriage return or a line feed.  Your VISA configure is already set up by default to have the termination character enabled and as a line feed.  The command you write should end end with a termination character.  Then get rid of Bytes at Port.  Wire a constant into the VISA Read that is larger than the longest message you ever expect to receive.  Now the VISA Read will wait until all those bytes come in, or until it receives the termination character.  Now you have a complete message.

 

Get rid of the metronome Wait.  You won't need it as the VISA communication will control the speed of the loop.  If you do use a Wait, use the regular Wait function.  It is a better choice than the Wait Until Next msec  metronome function.

 

Also, you have an infinite While Loop because you have a False wired to the stop terminal.  That means the only way to end your VI is to hit the Abort button.  And thus the VISA Close will never actually execute.  It will leave the Com port hanging open.

Message 2 of 2
(1,818 Views)