LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LabVIEW control an external serial (RS232) device via a USB port on a Mac?

Solved!
Go to solution
Using LabVIEW 6 and a Mac G4 running OS9, it was once possible to use a USB port to control and acquire data from a pH meter in our lab. We just used "Serial Port Init.vi" and wired it to port #0, which designated the USB port. We connected the pH meter's DB9 connector to the Mac's USB port via a USB-to-DB9 adapter. LabVIEW 6 could then send commands to the pH meter and acquire pH values from it using serial port read and write icons. I'm attempting to do the same thing now using LabVIEW 8.6 on a Mac Pro running OS 10.5.6, and getting nowhere. The simplicity of LabVIEW 6 is long gone, and it seems to be necessary to use VISA icons. When I write the vi using VISA serial icons, three potential serial ports seem to be available. However, the vi gives an error message unless I choose a specific one of these, ASRL2::INSTR, as the Resource Name, in which case the vi runs but there is no communication with the pH meter. I can't figure out which physical connector on the Mac chassis corresponds to ASRL2::INSTR, but is doesn't appear to be the USB. I've attempted to write the vi using LabVIEW's VISA USB icons, but that requires knowledge of USB communications protocols that is beyond the expertise of this chemist. So, I'm pretty much at a loss as to what to try next. I could buy an RS232 serial card to install into a PCI Express slot in the Mac, hoping that it will be recognized and can be addressed by using VISA serial icons. However, since it was once trivial to perform this communications task via the Mac's USB port, it seems like it shouldn't be necessary to buy another card. LabVIEW keeps getting bigger and more complicated and, if it gets improved any more, it may not work at all. I've been programming LabVIEW on Macs for almost ten years and it has become progressively more frustrating. Anyway, has anyone out there fought the USB / serial communications battle on a new Mac and won? If that is now impossible, has anyone succeeded in communicating through an RS232 serial card installed in a Mac Pro? Any help will be appreciated. Thanks.
0 Kudos
Message 1 of 14
(11,732 Views)

Ken1 wrote:
Using LabVIEW 6 and a Mac G4 running OS9, it was once possible to use a USB port to control and acquire data from a pH meter in our lab. We just used "Serial Port Init.vi" and wired it to port #0, which designated the USB port. We connected the pH meter's DB9 connector to the Mac's USB port via a USB-to-DB9 adapter. LabVIEW 6 could then send commands to the pH meter and acquire pH values from it using serial port read and write icons. I'm attempting to do the same thing now using LabVIEW 8.6 on a Mac Pro running OS 10.5.6, and getting nowhere. The simplicity of LabVIEW 6 is long gone, and it seems to be necessary to use VISA icons. When I write the vi using VISA serial icons, three potential serial ports seem to be available. However, the vi gives an error message unless I choose a specific one of these, ASRL2::INSTR, as the Resource Name, in which case the vi runs but there is no communication with the pH meter. I can't figure out which physical connector on the Mac chassis corresponds to ASRL2::INSTR, but is doesn't appear to be the USB. I've attempted to write the vi using LabVIEW's VISA USB icons, but that requires knowledge of USB communications protocols that is beyond the expertise of this chemist. So, I'm pretty much at a loss as to what to try next. I could buy an RS232 serial card to install into a PCI Express slot in the Mac, hoping that it will be recognized and can be addressed by using VISA serial icons. However, since it was once trivial to perform this communications task via the Mac's USB port, it seems like it shouldn't be necessary to buy another card. LabVIEW keeps getting bigger and more complicated and, if it gets improved any more, it may not work at all. I've been programming LabVIEW on Macs for almost ten years and it has become progressively more frustrating. Anyway, has anyone out there fought the USB / serial communications battle on a new Mac and won? If that is now impossible, has anyone succeeded in communicating through an RS232 serial card installed in a Mac Pro? Any help will be appreciated. Thanks.

What USB to serial port converter are you using. I remember various discussions on Info-LabVIEW that there were serious problems with particular brands and sometimes specific types of USB-RS232 adapters. From what I remember Keyspan adapters were considered to work well, but they also had some low cost models that did seem to cause regular trouble.

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 14
(11,721 Views)

Ken1,

 

VISA does require a bit of a learning curve, but is worth the effort.  I have used USB-serial devices under LV 8.x on the Mac, although not an Intel Mac and I do not recall which OS version.

 

Part of the problem is that serial devices do not have any defined identification protocol, so you cannot automatically determine which device is connected to which port. This applies to any OS and to hard wired serial ports as well as adapters.  If your serial device has an identification protocol, you can run through the available ports and see which one gives the correct response.  If you need to change serial port parameters like baud or parity, remember to change them back on any port which does not have your device connected.

 

If your serial device is powered from the handshaking lines of the serial port, all kinds of exasperating and undocumented things can happen.  Like the handshaking lines de-activating after each character!

 

As Rolf asked, please indicate the type of adapter and the type(s) of instruments you are trying to use.

 

Lynn 

 

0 Kudos
Message 3 of 14
(11,701 Views)

Rolf and Lynn,

 

Thanks very much for your replies.  The USB-to-DB9 adapter is an old Keyspan model USA-19 (or possibly USA-10, hard to read), and the pH meter is a fairly ancient Orion model 520A.  Although this hardware is old, it does still work with our Mac G4 and LV 6, so a hardware fault doesn't appear to be the problem.  My suspicion is that the meter has no identification protocol, since all the serial port information on the Mac Pro remains the same irrespective of whether the meter is connected, powered on, etc.  But, again, I don't know if the VI is even talking to the USB port where the meter is plugged in or if it's interrogating some entirely different port.  In case it is of any help, a jpeg of my VI for this is attached, though I've also tried unsuccessful modifications using VISA USB vi's instead of the VISA Serial vi's shown.  It seems like this should be straightforward.  Any other suggestions?

 

- Ken1 

0 Kudos
Message 4 of 14
(11,681 Views)

Ken1,

 

1. Except for the Waits you do not need the sequence structure.  Dataflow defines when things will execute.

 

2. Because of dataflow you do not know whether the Wait in any frame will execute before or after the other code.  Using the Express VI Time Delay will solve both 1 and 2.  See the image below for an example of how to change a small portion of your VI.

 

3. When you send the "rem" command (frame 2) does the display on the meter indicate that it is in Remote mode? (I am guessing that that is what that does.)  That will tell you that something is happening.  Similarly, what shows in the Log-On String.. indicator.  This is probably the Identification response that I asked about earlier.  If you get back the identification of the meter, then you know it is connected and talking.

 

4. Do you get any error messages?  If so, what are they.  If not, exactly what happens when you run that VI?

 

I will try to remember to bring my USB to serial adapter in tomorrow to see if it works with the Intel Mac.  hmmmm, ... trying to think what serial device I might have here to check it....

 

Lynn

 

Dataflow example.png 

0 Kudos
Message 5 of 14
(11,665 Views)

Hi Lynn -

 

You are completely right about not needing the sequence structure.  I included it to make the new LV8.6 VI as similar as possible to the one that worked in LV6.1.  I have rewritten the VI to eliminate the sequence structure and use Time Delays, as you suggested.  It still executes as before (i.e., fails to communicate).  I also tried placing the Time Delays before the serial read/write steps instead of after, just in case that is the order of execution when using the sequence structure.  That didn't help.  You are correct that writing the "rem" string  to the pH meter places it in the remote-control mode.  With the LV6.1 VI on the old Mac G4, the pH meter responds to that message with a log-on string that is the codes-display equivalent of "rem", followed by two line feeds, "ORION Meter type 520A Logged on:", a line feed, and "(Enter help to view the menu)."  The display on the pH meter shows the pH value and "ready" continuously while the VI is running successfully (i.e., the pH meter display does not show "rem" even though the meter has been placed in the remote mode by the VI).  For the new LV8.6 VI running on the Mac Pro, the indicator that should show the log-on string received from the pH meter is blank, as is the pH string indicator.  So, if the meter is sending any messages to the computer, they are not being received.  I doubt the initial "rem" message is getting from the computer to the meter.

 

Regarding error messages, when the new LV8.6 VI runs it does give error messages that depend on which of the three VISA reference names I provide to VISA Configure Serial Port.  Using ASRL1::INSTR produces the message "Error -1073807246 occurred at Property Node(arg1) in VISA Configure Serial Port (Instr).vi.  Possible reason(s): VISA: (Hex 0xBFFF0072)  The resource is valid, but VISA cannot currently access it."  Using PXI2::0::INSTR as the reference name produces the message "Error -1073807331 occurred at Property Node(arg2) in VISA Configure Serial Port (Instr).vi.  Possible reason(s): VISA: (Hex 0xBFFF001D)  The specified attribute is not defined or supported by the reference resource."  The only reference name that works is ASRL2::INSTR, which allows the VI to run to completion without giving any error messages.  So, in that case the VI appears to execute, but there is just no communication with the pH meter.  It really performs as though the cable from the pH meter just should be plugged into some other port on the computer besides the USB.  I doubt if it's relevant, but this Mac Pro contains an NI DAQ card (a #PCIe-6251M), which is connected to a BNC-2120 via a cable purchased from NI.  The old Mac G4 also contains an NI DAQ card.

 

Thanks for working on this problem.  I'll be interested to learn the result of the serial communication test you mentioned.

 

- Ken1 

0 Kudos
Message 6 of 14
(11,648 Views)

The way that you have done the program, it's pretty hard for errors to happen in certain cases. It there is a problem with the USB-RS232 converter or with your cable, the instrument will not receive a command. Without receiving a command, it will not send anything back and you will have 0 bytes in the buffer. In that situation, you would be telling VISA Read to read nothing and no error will occur.

 

I would concentrate on checking the cable and the converter. First try a simple loopback by shorting Tx and Rx. Do a write and then a read of a single character (specify the byte count of 1). If you get a timeout, try a different converter or cable.

0 Kudos
Message 7 of 14
(11,640 Views)
Solution
Accepted by Ken1

Ken1,

 

I did not get a chance to check the USB-serial last night.  I will make myself a note to try again tonight.

 

Dennis is right.  You need to focus on just determining what is working or not in the communications.  Look at the System Profiler (Apple menu >> About this Mac >> More info..).  Then select the USB item in the Contents list on the left column.  See if any of the USB devices look like they might be serial port emulators.  I do not remember exactly what they are called.  If the device only shows up as USB Raw, it probably means that no driver was installed.  You can unplug the device and see what changes.  This will tell you whether the OS sees the device.

 

Lynn 

Message 8 of 14
(11,622 Views)

Ken1,

 

I tried my old Belkin USB-Serial device.  On my PPC G5 at home with LV 8.5 it works fine.  When I brought it to work and connected it to the MacPro, the OS recognizes it.  System Profiler shows USB-232 adapter and get the Vendor ID and serial number.

 

VISA Find Resource also sees it, but as a USB RAW device.  The two ASRLx::INSTR devices show up whether the adapter is connected or not.  From LV the Basic Serial Write and Read.vi it does not see or talk to the device.  I suspect that a driver is needed.  Belkin does not list any adapters on their web site and does not recognize the part number of the adapter I have so I could not download a driver.  I'll have to see if I can find the original disk at home.

 

Lynn 

0 Kudos
Message 9 of 14
(11,589 Views)

Lynne -

 

Your previous message started me thinking that maybe all I needed was to download a driver for the Keyspan USB-to-RS232 adapter.  So, I downloaded one and, whoopteezing!, a new "ASRL7::INSTR" resource name option appeared and everything now functions correctly!  This Keyspan adapter was already in use on the old Mac G4 when I took over the lab, and it still works fine on that machine.  Frankly I had overlooked the possibility that we might need a new driver for the Mac Pro.  In retrospect this is now obvious, but it is one of those things that can slip through the cracks with a change in personnel.  Anyway, I want to thank you and the others who were kind enough to respond to my question with insight and suggestions.

 

Ken1 

0 Kudos
Message 10 of 14
(11,515 Views)