LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA writing/reading problems

Hello forum,

 

I really hope to get an snwer to this thread, because I'm getting pretty desperate for help now.

 

My current problem is how to use VISA in LabVIEW 7.0 to control a system via RS232. The

first problem I have is in writing commands to the external unit. For example, in my very simple

LabVIEW Serial modified2.vi (attached) I send a command "Pnnnn\n" to change the parameter

'P' to the value 'nnnn' with the '\n' line feed terminator.

 

I have the port COM1 on my computer wired via serial cable to the system's RS232 port but when

I run the VI, nothing happens to the external system. I have tried using the NI VISA test panels

to see what's going on, but it doesn't return any errors when I try using the write panel.

 

The other problem is with reading. So for example, if I send the command "GTS\n" this will get the

parameter TS which I then read with the VISA Read VI, but this always seems to return warning

1073670294. Using the test panels, I tried getting the system's status byte, but it returned only an

error code.

 

Can anybody help?

 

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
Download All
Message 1 of 18
(4,308 Views)

Something like this will work.  You may have to make some minor modifications.  Are you intending to use the termination character?  You have it enabled on your Visa config serial port, so I included a check for that.  If not, disable it.  As far as the error, make sure you are using the correct serial port and that it is configure properly.  Part of the problem with your VI is you do not give a delay when reading the serial port.  Visa will stop receiving as soon as the terminating character is received.  The loop will exit when it's detected.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Message 2 of 18
(4,292 Views)

Hi, thanks for your reply but I don't have LabVIEW at home so I couldn't check this out until I got back to work.

 

The attachment is saved in LabVIEW 10, any chance you could repost it in 7.0 so I can open it, or just post a screen capture of the block diagram?

 

I am definitely using the right serial port with the correct baud rate, parity, etc, that has been checked and triple checked. I'll try disabling the termination character (as mentioned above, I was using "\n" but I tried "\r" and "\r\n" but that seemed to hinder, not help).

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
Message 3 of 18
(4,252 Views)

Never mind, I got a screen grab of the VI from the downconvert thread.

 

It looks very similar to what I have at the moment; I'll try it out and let you know how it goes!

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
Message 4 of 18
(4,239 Views)

Here is my attempt at modifying your code to fit my circumstances.

 

The value I receive from the device when I send the "GTS" command is two hex bytes. In the manual, it says the following:

 

"response: 2 Bytes

 (1)00hex .. FFhex high byte of SHG temperature

     [degrees centigrade*10]

 (2)00hex .. FFhex low byte"

 

So in order to get the temperature as a decimal, I first need to convert the hex number to decimal (probably a stupid question, but presumably I need both bytes?), and then divide by ten.

What's the best way to accomplish this in LabVIEW 7.0? I've tried using typecast but I couldn't figure out how the type descriptors work, and I tried using hexadecimal string to number but it kept returning a blank field.

 

Also, I'm having some trouble using the other commands in a meaningful way. For example, after getting the temperature, I also need to get the value of a voltage (using the command "GZ"), but when I just do the two sets of write and read in parallel, I of course get the results all mixed up so that often the read operations will receive the other value to what I want. Any advice?

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
Message 5 of 18
(4,229 Views)

Are you sure the internal while loop is not stopping before any data has been received?  My concern is there is not delay between your write/read operations and your depending upon blind timing to capture the incoming data stream.  You of course will need to remove the stop button eventually.  I assume it is only there for testing purposes.  What is the hex data being returned?

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Message 6 of 18
(4,223 Views)

Ok, this is my current VI. I added ni another 100ms wait after the read to be sure that the timing is correct.

 

The internal loop is definitely getting data as when I have it set to "Get Piezo Voltage" the data I receive matches exactly what I'd expect. So for example, on the Piezo setting, I get back 07D0 when the device is set to 2000, and the temperature reads something like 00FF when the temp I'd expect is around 25-26 celsius so it seems to be giving valid data but I'd just like to convert it to decimal for ease of reading.

 

The stop button is effectively just there for testing purposes, yes.

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
Message 7 of 18
(4,215 Views)

I am currently at work but will try to get back with you at a more opportune time.  Someone else may chime in with assistance before then.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 8 of 18
(4,207 Views)

Understood Reese, thanks very much for the help you've given me so far!

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
0 Kudos
Message 9 of 18
(4,199 Views)

In order that anyone who finds this thread interesting is up to date, I have successfully implemented the "GTS" and "GZ" commands in series by placing a 300ms delay before each one. This is too slow for real-time update, but sufficient for a one-time update "refresh" button, which is satisfactory for my purposes.

 

I'm still not sure how to get the returned data back into decimal though, and I'm having trouble setting up other commands such as the set voltage command "P" which I mentioned in my first post. I'll post my full VI with the problem in context tomorrow if it'll help. Thanks once again to Reese for trying to help me out! 

---------------------------------------------------------------------
LabVIEW 2013, Windows 7

He who asks the question is a fool for five minutes; he who does not ask the question remains a fool forever.
0 Kudos
Message 10 of 18
(4,187 Views)