08-17-2022 04:58 AM
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~
08-17-2022 05:39 AM
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
08-17-2022 06:40 AM
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.
08-18-2022 01:40 AM
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
08-18-2022 07:44 PM
Need to someone help to build a program with labview to communicate with printer like C# printer communication protocol ,thanks
08-18-2022 08:09 PM
@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.
08-19-2022 02:04 AM
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.
08-19-2022 04:17 AM
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.