LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can you configure a VISA serial port in MAX to use in LabVIEW?

Solved!
Go to solution

I've been doing serial comms with LabVIEW for many years and have always manually set all of my baud rate settings in the program itself- basically never using MAX for anything other than some initial troubleshooting.

 

I have a new application where a program needs to talk to a handful of devices. These devices use the same protocol but may be connected using TCP, or serial at baud rate A, or serial at baud rate B. It's not exactly this, but pretend I have three power supplies- all SCPI compatible- but one is Ethernet, one is serial at baud 115200, and one is serial at baud 9600.*

 

I'd like my program to not care about the particulars of the device and interface. I thought I could configure each specific device's connection parameters within MAX, then just pick that VISA resource from the program, call VISA Open.vi, and I'm off to the races. My users wouldn't need to pick a VISA resource, then figure out what baud rate it was and set that, etc. As long as someone else set up the MAX properties and made a descriptive alias, they could just pick "Power Supply 1" or "Power Supply 2".

 

So, I went into MAX and set the baud rate for a serial connection, and made sure I had an Ethernet listing as well. In LabVIEW, I just wire a VISA Resource to VISA Open.vi. If I pick the Ethernet option, this works fine. But if I pick the Serial option, it outputs the wrong baud rate (confirmed via oscilloscope). The baud rate coming out of LabVIEW doesn't match the one set in MAX.

 

If I use the serial test panel in MAX, I can set the baud rates and it sticks.

 

Perhaps my Google-fu is weak, but I can only find pages that SAY that VISA abstracts the hardware layer- but no examples showing how it's done.

 

Do I need to manually write my baud rate settings etc. within LabVIEW, or can I pre configure that stuff in MAX? If so... what does that baud rate setting in MAX even do?

 

*Side note- this example isn't actually what I'm trying to do, it's just for reference. I'm not using SCPI but it's a similar concept. I just need to know if I can pre-set baud rates in MAX or if it must be done in LabVIEW. If I need to handle the various settings in my program that's totally fine, I'm just hoping to save some work.

0 Kudos
Message 1 of 7
(531 Views)

Well I found this old thread from 2010:

 

https://forums.ni.com/t5/LabVIEW/Get-Serial-Settings-saved-in-Max-loaded-into-LabVIEW/td-p/1089691

 

The post there says "You don't have to do anything to get the serial settings into LabVIEW. As long as you don't use the VISA Configure Serial Port, the settings will persist and you just have to do your reads and writes with the correct resource. Put simply, if you set the baud rate in MAX for Com1 to be 56000, in LabVIEW if you write to Com1, it will occur at 56000 baud."

 

Not sure why that doesn't seem to be the case for my system...

0 Kudos
Message 2 of 7
(507 Views)

I found This Doc   which states something different from your old post:

NI-VISA itself does not limit the range of baud rates you use. Instead, the baud rate request passes directly to the device driver for the serial interface. In LabVIEW, the baud rate is set using the VISA Configure Serial Port VI. If the baud rate set is not supported by the serial port, NI-VISA will return an error saying the attribute is not valid.

Which means that you HAVE to use the CONFIGURE vi.

If that's the case, then there seems to be NO POINT in using VISA at all.
I thought the purpose of VISA was to abstract-ify the connections - the code refers to "My Connection", and MAX defines "My Connection" to be Com1 At 9600 baud, or a TCP connection to 127.0.0.1:50000 or GPIB something, or smoke signals and the code DOES NOT CARE.

But that little blurb says that I have to go thru the serial setup crap ANYWAY, so why bother?

Seriously, why set it up in MAX, if LabVIEW is going to ignore the settings?

0 Kudos
Message 3 of 7
(492 Views)
Solution
Accepted by topic author BertMcMahan

Maybe This doc explains it:

When you open a Serial port, the VISA specification defines the default communication settings to be 9600 baud, 8 data bits, 1 stop bit, no parity, and no flow control. If you have configured the settings to a different value in theNI-VISAconfiguration utility (MAX on Windows,visaconfon UNIX), then you must pass the valueVI_LOAD_CONFIG (4)as theAccessModeparameter toviOpen(). This parameter will cause the configured settings to be used; otherwise, if theAccessModeis 0 or VI_NULL, the default settings will be used.

You have to OPEN the session with option 4, to coerce LabVIEW to pay attention to MAX.

Message 4 of 7
(486 Views)

Ah, that did indeed work!

 

For the pictorially minded:

 

BertMcMahan_0-1767914378294.png

 

Using the "Load Configured Settings" flag on VISA Open.vi will use the settings from MAX. Without it, it defaults to the values Steve mentioned above.

 

Reading the manual... now, why didn't I think of that? 😉

Message 5 of 7
(461 Views)

@BertMcMahan wrote:

 

Reading the manual... now, why didn't I think of that? 😉


Probably because you've been caught in the loop of bad documentation before:

Kyle97330_0-1767921829087.png

 

(not saying NI does this, but it happens a lot...)

0 Kudos
Message 6 of 7
(434 Views)

Ha, very true 🙂

 

I feel quite silly now that I double check... I could've sworn I read through VISA Open.vi's help, but looking again it's right there, plain as day:

 

BertMcMahan_0-1767977380902.png

 

I'll blame it on running out of coffee beans in the break room 😄

0 Kudos
Message 7 of 7
(370 Views)