LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to share variables between labview and c#?

Hi : smileyhappy:,

 

I have a c# program that is running as a windows service, it receives data from the hardware. I want to make the user interface in labview, but i need to establish communication between  c#  and labview (send/receive control messages). My first idea was to use windows messages, although as I read in the forum: i cannot use user32.dll to receive messages so easily as I imagine. I also cannot use windows message queue suggested here, since i don't have a window handler as in the example.

Can anyone suggest the best way to do this? Any hint will be welcomed.

 

Thanks

0 Kudos
Message 1 of 8
(4,121 Views)

Hi!

 

i have the same question. Can anyone help me(us)?

0 Kudos
Message 2 of 8
(4,087 Views)

One option would be to use TCP/IP. At least in LabView, that is very convenient, and I guess so is in C#.

 

Felix

Message 3 of 8
(4,074 Views)

Hi Felix,

 

thanks for your reply. Are you suggesting to do the same as in the Simple Data Client.vi and Simple Data server.vi examples? There's no other way to take?

At least now, I have another lead to follow.

 

Thanks

0 Kudos
Message 4 of 8
(4,060 Views)

Yes, the LabView examples show you most of the functionality you have using TCP IP. That isn't really a complicated issue.

You will have to define a protocol (format of messages received and sent) and parse the messages.

I suggest to use a state machine architecture, so you can enhance the code if needed such as to reestablish the connection once it is closed and so on...

 

Felix

0 Kudos
Message 5 of 8
(4,056 Views)

Hi,

 

Yes, TCP/IP is most universal way for the communication. Otherwise you should develop some parts for establish connection / break connection / wait for the data. This way also good when you need to transfer the data across network.

Another possible way is following: you can create DLL from your LabVIEW code, then call this dll from your C# application, and interchange the data through this DLL. Here you can use different techniquies (also TCP/IP as well). The advantage of this method that you will establish LabVIEW<->LabVIEW communication.

In attached example I have create "quick and dirty" project with shared variables. LabVIEW application will write the shared variable, then external application will read this, increment variable, then LabVIEW will read it back. I have used CVI, but you can call SharedLib from C#, here no differences.

Something like that:

 

best regards,

Andrey.

Message Edited by Andrey Dmitriev on 10-28-2008 03:17 PM
Download All
Message 6 of 8
(4,046 Views)

Hi Andrey,

 

thanks for your reply. I try to run your example, but I couldn't run properly UI Application.exe (LabWindows/ CVI v8.5). The two applications are running - UI Application.exe and Test.vi - but i didn't receive anything from the application (test.vi), neither in the Ui Application, it returns always "0".... It's the first time that I'm using LabWindows, maybe i'm doing something wrong... But if it works, I'll adopt your solution :)! It's great :)!

 

Thanks a lot for your help

0 Kudos
Message 7 of 8
(3,990 Views)

This not working on your PC because Variables was not deployed...

I added code for deployment variables. Also added some missing files in zip. See attachment, now it should be OK (hopefully).

 

Useful links for you:

Using the LabVIEW Shared Variables

How do I Deploy Network Shared Variables from a Compiled Executable?

How do I Communicate Between Multiple LabVIEW Executables using Shared Variables?

 

best regards,

Andrey.

 

Message 8 of 8
(3,964 Views)