LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate the dll library base on C# code and for labview call this library node

Hi, All

 

I faced a problem, I have the C# code to communicate with printer via USB port, I want to generate the dll library code base on C# source code command(I'm not familiar with C#), how to generate the dll file base on attached code for labview call.it will communicate with printer via labview,can you help me to generate dll or provide a demo base on attached code, thanks so much~

0 Kudos
Message 1 of 8
(984 Views)

I also add the C++ code for read and read MAC from printer with USB port, attachment is communicate protocol , how to use the labview to communicate with this printer?thanks

0 Kudos
Message 2 of 8
(973 Views)

Hello,

 

you are asking two question at once.

To answer (halfly) your first question, how to create a dll in C# that can be called from LabVIEW, I made as an example a .NET library (and attached the solution) and call it from LabVIEW in "Call cSharp- Lib.vi".

This can only be a broad hint how to create a Library Project in Visual Studio and how to access the compiled dll from LabVIEW.

 

I think, it is now your task to port your Windows App to a library and this forum is definitely the wrong place to search for help with that.

 

Greets, Dave
0 Kudos
Message 3 of 8
(963 Views)

Thanks, actually, I need you build the dll sample base on my program due to it include the USB communication and command to printer, can you help to build a sample base on it ?thanks 

0 Kudos
Message 4 of 8
(921 Views)

Need to someone help to build a program with labview to communicate with printer like C# printer communication protocol ,thanks 

0 Kudos
Message 5 of 8
(900 Views)

@Lchjxlz wrote:

Need to someone help to build a program with labview to communicate with printer like C# printer communication protocol ,thanks 


Do you mean, you want to hire someone to do the work for you? - there are several LabVIEW freelancers who can support you on such work at a reasonable cost.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 6 of 8
(896 Views)

Hello,

 

sorry for not answering yesterday.

As far as I see the problem, you want to convert a windows App with a GUI to a .NET library. Since this is a LabVIEW- forum nobody will help you with this, especially with your demanding C# - code and very nested class relations.

I showed you how to create a .NET library and define public class properties (it's the same with methods) and how to access them in LabVIEW.

It is now your task to wrap the relevant code into a class and implement properties and methods to control the core functionality the same way you would do with the GUI of the APP. But this is the wrong place to search vor advice how to do that. Try Stackoverflow.

 

Greets, Dave
0 Kudos
Message 7 of 8
(866 Views)

Actually, the USB Backend seems to be a thin C++ wrapper around the WinUSB API. That would be not a lot of work to create a simple DLL from to use from LabVIEW through the Call Library Node. Still you need a Visual C compiler and the ability to create the project correctly and make that DLL. It is used for some of the communication in the main program through an executable called USBBackend.

 

But!!!! The C Sharp code in the other archive is indeed quite convoluted and uses a lot of other interfaces.

1) it access the ArtDAQ hardware through .Net Interop into the according DLL.

2) it interfaces also to WinUSB on its own through .Net Interop to communicate with some of the USB components.

3) there is a HslCommunication.dll that seems to not directly be referenced but hard to know from this.

 

Porting that to LabVIEW in any reasonable manner is going to be a serious project. First the WinUSB Interop Layer would need to be ported to LabVIEW. There are some libraries out there trying to do that but the underlaying setupdi API that needs to be accessed too for the enumeration of Windows USB components is not suited to directly be interfaced from LabVIEW. It's possible but a lot of convoluted work and should rather be done in an external library programmed in C(++) to translate those APIs into a more LabVIEW friendly interface. The USBBackend source code could be a starting point for that.

 

The current architecture with doing part of the USB work through the external USBbackend.exe command line tool and part through its own internal WinUSB Interop layer is probably the result of organically growing code but rather ugly and inefficient.

 

I suspect someone threw you this code on the desk and told you to get this somehow working in LabVIEW. And you should probably have it finished yesterday. If so all I can say is good luck but that is not gonna fly for sure. You have in my opinion two options:

- Hire someone competent with LabVIEW and C programming and let them create a reasonable framework to do the USB interfacing through a generic WinUSB low level driver and multiple higher level drivers for the different specific USB resources. This is not a quick and dirty hacking job that can be done in a week or two!

- Try to plough through this on your own and likely fail in a few months when management decides that it has cost enough and they pull the plug from this project.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 8
(845 Views)