From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.net function to labview

Solved!
Go to solution

hello all,

 

I have a the .net code of a function to open a rs232 port using a dll.

 

here is the code:

 

 

public static Rf OpenDriver(int comPort, int baudRate, int rfRetries)
        {
            TParamList rs232_settings = new TParamList();
            TParamList rf_settings = new TParamList();
            Rf rf_module = new Rf();
            
            rs232_settings.Add(SettingsConst.RS232.COMPORT_PARAM, comPort);
            rs232_settings.Add(SettingsConst.RS232.BAUDRATE_PARAM, baudRate);
            
            //Automatically open COM Port on Init
            rf_settings.Add(SettingsConst.RF.OPEN_COM_CHANNEL_PARAM, 1);
            //Let the driver manage the  power
            rf_settings.Add(
            SettingsConst.RF.RFMASTER_SMART_POWER,
            SettingsConst.RF.RFMasterSmartPowerValues.RFMASTER_SMART_POWER);
            //Number of retries
            rf_settings.Add(SettingsConst.RF.RF_RETRIES, rfRetries);
            TParamList init_settings = new TParamList();
            init_settings.Add(SettingsConst.Sections.RS232, rs232_settings);
            init_settings.Add(SettingsConst.Sections.RF, rf_settings);
            init_settings.Add(SettingsConst.RF.RF_AFC, true);
            //Launching init of driver
            if (rf_module.Init(ref init_settings) == EProdLayerRetValue.NoError)
            {
                //Waiting for init to complete
                while (rf_module.GetInitCloseState() == EProdLayerRetValue.InitInProgress)
                    Thread.Sleep(50);
                //Checking return code
                if (rf_module.GetInitCloseState() == EProdLayerRetValue.InitOK)
                    return rf_module;
                else
                    return null;
            }
            else
                return null;
        }

 

I'm trying to implement this code in labview, but I'm having some dificulties.

 

I've attached an image that displays my troubles.

.net implementation.png

 

any help would be apreciated.

 

thanks,

 

Adam

0 Kudos
Message 1 of 9
(3,158 Views)

Is there a reason you're not just using the VISA functions to communicate over the serial port? Seems like it would be a lot less hassle...

 

TParamList rs232_settings = new TParamList();
TParamList rf_settings = new TParamList();

These indicate that you need to use the constructor to create two objects that are of the TParamList class type.

 

Rf rf_module = new Rf();

This is an instantiation of an object of the RF class. Same thing: constructor.

 

rs232_settings.Add(SettingsConst.RS232.COMPORT_PARAM, comPort);

rs232_settings.Add(SettingsConst.RS232.BAUDRATE_PARAM, baudRate);

 

Simple method calls. You are using the Property node. You need to use the Invoke node.

 

 

I could go on... do you know .NET?

 

 

0 Kudos
Message 2 of 9
(3,129 Views)

thanks for the reply,

 

I'm not using the Visa functions because I don't know the commands to send to the device. All I have are the dlls and an small example in visual studio c#. If there is another way to do this I can try it as long as it is in Labview.

 

I'm not very experienced in visual studio c#.

 

If I understood correctly this is how I should program the .net function in labview.

.net

However I still don't know how to input the com port or the baudrate. They should be integers however I have .net class in paramValue instead.

 

thanks again,

 

Adam

0 Kudos
Message 3 of 9
(3,123 Views)

What is the instrument/device that you are trying to talk to? Do you at least have the documentation on the .NET API? Where did you get this .NET API?

0 Kudos
Message 4 of 9
(3,115 Views)

It's a RF signal emitter that connects to the PC using the serial port.

 

All I have from the .NET API is a small example in visual studio c# that implements some basic functions using various dlls. I've tried the code in visual studio and it works.

 

That's why I am trying to replicate the visual studio code in labview. If I can understand how to implement this function I think I will be able to understand the rest of the VS code.

 

tks

 

Adam

0 Kudos
Message 5 of 9
(3,107 Views)

Manufacturer? Model Number? Link?

 

If you don't have the documentation, then I don't see how we can help you. For instance, in the function you cited, comPort is an integer. Does this refer to a com port number? If so, does 0 mean COM1, or does 0 mean the first available COM port (so it could be, for example, COM3)? Is this a Windows.Forms application, or is it a console application?

 

You're not giving much information for us to go on...

0 Kudos
Message 6 of 9
(3,096 Views)

Hello,

 

It´s a custom RF emitter built here at the company. I don't have documentation all I have is the code and it works in visual studio so I know that for example the function in the first post "public static Rf OpenDriver(int comPort, int baudRate, int rfRetries)" is called using the following arguments:

 

OpenDriver(1, 9600, 3) where "1" is COM1, "9600" is the baudrate and "3" number of retries all integers. My problem is that I don´t know how to translate the code in the function to labview code. 

 

It´s a windows.forms.application and I'm sorry that I don't have any more info.

 

Any help in decoding the function to LabView would be very appreciated.

 

tks!

 

Adam

0 Kudos
Message 7 of 9
(3,079 Views)
Solution
Accepted by topic author _Adam_

OK. Well, based on that, and seeing the code, it appears to me that the Add method's signature is basically Add(string paramName, Object paramValue). In this case you'd have to use the To .NET Object to connect a constant of 1 (for example for the COM port) to the paramValue input. As for the other parameter I can't really say because I can't see the rest of the C# code. I may be able to decode it if you upload the .NET assembly(ies) that you're using in LabVIEW.

0 Kudos
Message 8 of 9
(3,065 Views)

I was able to replicate C# code in labview successfully Smiley Happy

 

Thanks for your help!

 

Adam

0 Kudos
Message 9 of 9
(3,054 Views)