Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Conrad USB 4x relay board

I thought you said wizard created a VI for each function in the dll.
0 Kudos
Message 11 of 16
(3,382 Views)

Yes, but the createFile function is one of the kernel32.dll. I just figured out while I was analysing a Visual C++ example:

 

Public Class Form1
    ' Needed to create a handle to access the CP2104
    <DllImport("kernel32.dll")> Private Shared Function _
    CreateFile(ByVal lpFileName As String, _
        ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, _
        ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, _
        ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer
    End Function
    ' Needed to close the handle 
    <DllImport("kernel32.dll")> Private Shared Function _
         CloseHandle(ByVal hObject As Integer) As Integer
    End Function
    ' For more information please check http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx

    ' constants needed for "CreateFile" 
    Public Const GENERIC_ALL As Integer = &H10000000
    Public Const GENERIC_READ As Integer = &H80000000
    Public Const GENERIC_WRITE As Integer = &H40000000
    Public Const GENERIC_EXECUTE As Integer = &H20000000
    Public Const OPEN_EXISTING As Integer = 3
    Public Const FILE_SHARE_READ = &H1
    Public Const FILE_SHARE_WRITE = &H2
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Public Const FILE_FLAG_OVERLAPPED = &H40000000

 I will try to implement this somehow into LabVIEW tomorrow 😉 Maybe it exists an easy way to call kernel32 functions?

 

 

0 Kudos
Message 12 of 16
(3,378 Views)
Sorry, I did not pick up that the function was not part of the dll.
0 Kudos
Message 13 of 16
(3,372 Views)

Is it possible to open a COM-Port with VISA and create the COM-Handle (needed for the device-dll-functions) based on the "VISA resource name" instead of calling the kernel32.dll-function "createFile" (which is still not working)?

0 Kudos
Message 14 of 16
(3,340 Views)
No, the vendor's dll would have to use VISA functions to do the reads and writes.

I am not that experienced with kernel32 but perhaps if you attached the code you are using to run it, someone else could look at it.

Have you tried contacting the vendor to see if they can provide the actual serial commands? What about using portmon to capture them?
0 Kudos
Message 15 of 16
(3,329 Views)

@Olikel wrote:

Is it possible to open a COM-Port with VISA and create the COM-Handle (needed for the device-dll-functions) based on the "VISA resource name" instead of calling the kernel32.dll-function "createFile" (which is still not working)?


It is rather ironic that in saving about 20 Euros on purchasing the 4x relay board instead of the 8x relay with the serial port support, you are going through all of this hassle.

 

Here is an example about how to call kernel32.dll from LabVIEW. https://decibel.ni.com/content/docs/DOC-17820

You will having to do something very similar. The CreateFile function returns an integer.

You pass in string and a bunch of either integers or long integers.  Look at the VB.NET example.

 

 

 

0 Kudos
Message 16 of 16
(3,325 Views)