08-02-2023 05:52 AM
Is it possible to work with such a datatype in C#? For example, I need to establish a VISA connection, but I am unsure how to pass my IP address to the method since the IP address is a string, but the method requires a pointer. Does anyone have an idea on how to solve this?
I've also included my attempted solution in the images below.
Thank you in advance!
08-02-2023 06:42 AM - edited 08-02-2023 06:45 AM
Unfortunately your VISA Resource is in C terms actually a so called VISA Session handle and not directly compatible with a string form. The LabVIEW VISA Session Control is a convenience control that associates a sessions name to the underlaying VISA Session Handle.
What you need to do is to change the according parameter to a string control and then rebuild your DLL. Make sure that the Control is being configured as a C String Pointer in the DLL interface configuration of your DLL build specification.
Then you can pass a C String pointer from your C# program. But this must be a Zero Terminated ASCII string, not IntPtr to a C# string (which would be a UTF-16 string).
Alternatively you could also choose to build a .Net Assembly from LabVIEW code, instead of a classical DLL. This would make several things easier as you do not need to do your own Interop marshalling to call that assembly. You still need to make the VISA resource a string though, C# doesn't have a VISA Session Control equivalent, this is really a special LabVIEW convenience feature.
08-02-2023 07:54 AM
Or you can just program NI-VISA in C#.
08-03-2023 01:56 AM
Thanks for the answer. I will do my best to bring it work