LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems on serial communication with an instrument

Hello everybody!
I'm having some problems interfacing with an Optical Spectrum Analyser from Anritsu via RS232. It has a GPIB interface that works well already, but i need to make communication work thru the serial port. If i use Measurement and Automation, i can write and read the commands alright. But, if i use a self made Labview vi, it doesn't work at all.

My vi consisted on:

ViOpen - ViWrite - ViRead - ViClose

Normally, i can know when the communication initialized alright with the OSA because the instrument enters a "communication state". When i use M&A, it enters on that state. When i use Labview, it doesn't.
I used NI Spy to see what differences were between the M&A and Labview. Here is a list of comm
ands issued by M&A:

viOpen(...,"ASRL1::INSTR",...)
viInstallHandler(...) *
viEnableEvent(...)
viWriteAsync(...)
viReadAsync(...)
viClose(...)

My Labview VI issues the following commands:

viOpen(...,"ASRL1::INSTR",...)
viWriteAsync(...)
viReadAsync()
viWaitonEvent()
viWaitonEvent()
...
viWaitonEvent()
viTerminate()
viClose()

Labview returns a "problems in serial read" error, but i know that the program doesn't even begins communication with the OSA. I suspect that the error lies on that viInstallHandle function, that is ran in the M&A routine but it isn't on Labview, but i can't find a way to make a vi that runs this function.
Anyone can help??? I am really frustrated because i know that serial communication works, but on M&A only!!!

Thanks in advance

Felipe
0 Kudos
Message 1 of 9
(3,930 Views)
Felipe, I'm sure there are a bunch of folks here who can answer your question in detail, but maybe this would help in the meanwhile..
In the NI library is a program called Loopback.vi which is used to test the serial port - and I used it as the basis to build a serial controller for an Ontrak data acq. system that is fiber isolated from the PC. I'm attaching a little serial test program based on that vi.
Hope this helps in looking for the problem..
-Dave
0 Kudos
Message 2 of 9
(3,930 Views)
Thanks for your comment, but i tested the serial read and write functions that you used on your program and they didn't work...
0 Kudos
Message 3 of 9
(3,930 Views)
Hmm, I'm running Labview 6.1. Look at the underlying VIs, its possible that your version of Labview either doesn't have those serial vi primitives, or something like that.
I just saved the entire hierarchy as an llb, try this:
0 Kudos
Message 4 of 9
(3,930 Views)
I consulted the document "VISA and Serial Communication" from ni.com. It
was helpful. I'm using Labview 6.

I don't know how to get Labview to tell me what it is doing at the level of
viTerminate(), etc., so I suppose I may not be able to contribute anything
to you, but I did get my serial port working in Labview recently.

I used a loopback test, by shorting pins 2 and 3, to verify that Labview was
successfully sending and receiving from the chosen serial port.

I made a .vi that let me do one thing at a time, initialize, write, and
read. This helped me realize that the instrument wasn't very fast at
getting back to me, when I was nailing down what I thought was a receiving
problem.

To get Labview to use the serial port on this system I had to uninstall a
graphics tablet driver that was taking control of the port on bootup. VISA
would report that there was a problem until I did this. Maybe if M&A runs
first your OS still thinks the port is being used and won't let Labview use
it.

Also, depending on what serial .vi I was using, I needed to verify that I
identified the port correctly. Port 0 in Labview, in my case, corresponds
to COM1, this is for the "compatibility" .vis. When using VISA serial .vis,
I discovered that COM1 was identified by VISA as ASRL1. However the default
resource name that came up when putting a VISA serial .vi into a diagram was
ASRL2 which does not exist on this system. Manually changing the "2" to a
"1" in the front panel solved my problems.

Your M&A and Labview VISA seem to agree on ASRL1, which might indicate that
isn't the problem.

I used the VISA interactive control to tell me how VISA was doing
identifying the ports and which ports it thought it could use during any
given session. This is available on my system in the VISA program group. If
there are yellow question marks on ports in this program, the port in
question has wandered away.

There are some examples and functions in the directory:

Labview 6\vi.llb\instr\serial.llb

and also in the directory

Labview 6\examples\instr\simplserl.llb,

as well as

Functions --> Instrument I/O --> Serial

and

Functions --> Instrument I/O --> I/O Compatibility --> Serial
Compatibility

"Felipe Ferri" wrote in message
news:50650000000500000004140100-1042324653000@exchange.ni.com...
> Thanks for your comment, but i tested the serial read and write
> functions that you used on your program and they didn't work...
0 Kudos
Message 5 of 9
(3,930 Views)
Thanks Felt and David for your help. The loopbacktest.vi worked and i will try to use it just to see if i can communicate with my OSA.

Felipe
0 Kudos
Message 6 of 9
(3,930 Views)
It worked!!
And i really can't believe that the error was so elementar and stupid... i feel ashamed...
The error was that the "end of command" characters that i had to send to the Spectrum Analyser were a carriage return and a '\n'. Just because of that carriage return thingie that i didn't write the program didn't work...
I'm so happy! 😄
thanx again for the help, anyway. I learned a lot about serial communication on labview on these days and i owe a little to you too...

Felipe
0 Kudos
Message 7 of 9
(3,930 Views)
I got likely problem in that I can send command to control SA MS2665G via RS232C but I cannot read data from SA. The SA setting can be changed propery but when I tried to query data, there was no response. I'm using VB program.
0 Kudos
Message 8 of 9
(3,544 Views)
Not only did you resurect an old thread, you resurected an old thread in the LabVIEW forum. Post a new question to the Measurement Studio for VB6 or Instrument Control board.
0 Kudos
Message 9 of 9
(3,532 Views)