Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

SerialSession -- configuration through MAX?

I'm trying to figure out how to create a SerialSession that will have its various configuration settings (baud rate, parity bits, etc.) determined through MAX. Let me explain. In MAX, I can browse "Devices and Interfaces" -> "Serial & Parallel" -> "COM21". Here, I can for instance set baud rate to 57600, and press SAVE. Then, in my C# program, I create a SerialSession object in the following way:

SerialSession session = ResourceManager.GetLocalManager().Open(resourceIDString);

The problem is that this object has session.BaudRate = 9600. It apparently has not derived its baud rate from the saved MAX settings. So, my question is, does anybody have a hint for me on how I can either create a SerialSession object that has settings derived from the MAX settings, or how I can access the MAX settings in order to copy them over to my SerialSession. Thanks,

Aviv Keshet
0 Kudos
Message 1 of 6
(4,286 Views)
Hi aviv,
 
i guess this problem is solved with the command
 
session.baudrate = 57600;
 
is this so?
0 Kudos
Message 2 of 6
(4,278 Views)
Not exactly. It's not that I want to set the baud rate to 57600 specifically. It's that I want to be able to set the baud rate from MAX. I want my C# program to use whatever baud rate settings MAX has configured, so that when I talk to different serial devices that require different baud rates, I don't have to change my code or have any settings editing user interface in my code, but can just change the settings in MAX and have them used in my program.
0 Kudos
Message 3 of 6
(4,273 Views)

Hi Aviv,

I am currently looking into this, although I have a couple of suggestions in the meantime.  Have you tried using any of the examples for C# located in C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples\DotNET2.0?  It might be good to try the simple read/write example to see if it imports the serial settings from MAX. 

I know that in LabVIEW, when using VISA functions, the system automatically scans MAX for the baud rate setting if the default fails.  As long as the settings have been saved in MAX, they should be successfully imported into the program.  This leads me to believe that it can be done, and that we simply need to determine which functions enable this setting in C#.

Thanks for your patience and I will contact you with more information!

Lauren L.

Applications Engineering
National Instruments
0 Kudos
Message 4 of 6
(4,246 Views)

Hi Aviv,

In order to import the serial settings from MAX you need to change the Access Mode to 4.  This tells the program to load the configured settings.  For more information on how to use this, I recommend taking a look at the Measurement Studio help guide, under the class library in Reference>>NationalInstruments.VisaNS>>AccessModes Enumeration.

Hope this helps!

Lauren L.

Applications Engineering
National Instruments
0 Kudos
Message 5 of 6
(4,226 Views)
Thanks for your help Lauren. I'll test it out. Seems like something that should be in the documentation for SerialSession.
0 Kudos
Message 6 of 6
(4,219 Views)