08-05-2011 10:37 AM
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?
08-05-2011 10:06 PM - edited 08-05-2011 10:07 PM
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.
08-08-2011 03:05 AM - edited 08-08-2011 03:06 AM
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).
08-08-2011 04:00 AM
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!
08-08-2011 06:28 AM
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?
08-08-2011 07:10 AM
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?
08-08-2011 08:09 AM
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.
08-08-2011 08:24 AM
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.
08-08-2011 09:11 AM
Understood Reese, thanks very much for the help you've given me so far!
08-08-2011 12:07 PM
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!