Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxGetSysDevNames returns NULL

I am using VB 6.0
 
See sample code below
 
Private Sub Command1_Click()
Dim MyName As String
Dim MyString As String
DAQmxErrChk DAQmxGetSysDevNames(MyName, 256)
DAQmxErrChk DAQmxGetDevProductType("Dev2", MyString, 256)
End Sub
 
Using the above code with a USB-6501 connected, Both MyName and MyString return empty (MyName = "",  MyString = "")
 
I know thw device is Dev2 since that is the device I use in the rest of the program that allows me to read and write data.  I am just trying to programaticaly determain the devices connected sinc this is a test system with sveral NI USB devices
 
I am able to get   DAQmxGetDevSerialNum  to return the correct Serial number for  "Dev2"
0 Kudos
Message 1 of 6
(9,055 Views)
Hi CUImsch,

Thank you for posting on the National Instruments forums.

I am seeing the same issue that you are seeing.  Can you let me know what version of DAQmx you are using?  You can find this by going to the Measurement and Automation Explorer, expanding the Software, highlighting NI-DAQmx and looking on the right side for the version.

I am seeing this behavior in NI-DAQmx 8.6.
Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 2 of 6
(9,046 Views)
Hi CUImsch,

The issue that you are seeing is because the string is not initialized to a certain length before it is returned.  Basically, the function that you are calling returns a pointer to a string but doesn't return the length of the string.  If you use this code when you define your variables, you will see the correct values returned.

Dim MyName As String * 50
Dim MyString As String * 10

Where 50 and 10 are the lengths of MyName and MyString respectively.  You will need to make sure to define the variable to be larger than the expected return value.  If the return value is smaller than your defined variable the remaining characters in the strings will be a square character. 
Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 3 of 6
(9,043 Views)

HI guys'

 

I ham having the same problem, can only get the serial number. I have setup my sample code as above and had no luck. It looks like the problem may be due to the buffer variable, it I REM it out the program runs but i get no data, if I use a buffer value the program crashes and closes VB. Attached is my sample code and the Module declarations, any help is walcomed.

 

***Code*** 

 

Private Sub Command1_Click()
  Dim DevNames As String * 50
  Dim DevType As String * 10
  Dim buffer As Long
  Dim MySN As Long
  
  buffer = 256
 
  DAQmxErrChk DAQmxGetSysDevNames(DevNames, buffer)
  DAQmxErrChk DAQmxGetDevProductType("Dev1", DevType, buffer)
  DAQmxErrChk DAQmxGetDevSerialNum("Dev1", MySN)
 
  Text1.Text = DevNames
  Text2.Text = DevType
  Label1.Caption = Hex$(MySN)
End Sub 

 

 

***MODULE***

 

Option Explicit

Public Enum DAQmxLineGrouping
    DAQmx_Val_ChanPerLine = 0
    DAQmx_Val_ChanForAllLines = 1
End Enum

Public Enum DAQmxValGroup
    DAQmx_Val_GroupByChannel = 0
    DAQmx_Val_GroupByScanNumber = 1
End Enum

Public Declare Function DAQmxGetSysDevNames Lib "nicaiu.dll" (ByRef data As String, ByVal bufferSize As Long) As Long
Public Declare Function DAQmxGetDevProductType Lib "nicaiu.dll" (ByVal device As String, ByRef data As String, ByVal bufferSize As Long) As Long
Public Declare Function DAQmxGetDevSerialNum Lib "nicaiu.dll" (ByVal device As String, ByRef data As Long) As Long
Public Declare Function DAQmxGetErrorString Lib "nicaiu.dll" (ByVal errorCode As Long, ByVal errorString As String, ByVal bufferSize As Long) As Long


Public Sub DAQmxErrChk(errorCode As Long)
'
'   Utility function to display a MsgBox showing the DAQmx error code and message.
'
    Dim errorString As String
    Dim bufferSize As Long
    Dim status As Long
    If (errorCode < 0) Then
        ' Find out the error message length.
        bufferSize = DAQmxGetErrorString(errorCode, 0, 0)
        ' Allocate enough space in the string.
        errorString = String(bufferSize, Chr$(0))
        ' Get the actual error message.
        'DAQmxGetErrorString errorCode, errorString, bufferSize
        status = DAQmxGetErrorString(errorCode, errorString, bufferSize)
        ' Trim it to the actual length, and display the message
        errorString = Left(errorString, InStr(errorString, Chr$(0)) - 1)
        MsgBox "DAQmx error code = " & errorCode & vbNewLine & "Error message = " & errorString
        'End
    End If
   
End Sub

0 Kudos
Message 4 of 6
(8,074 Views)

What version of DAQmx do you have?

 

Glenn


Regards,
Glenn
0 Kudos
Message 5 of 6
(8,054 Views)

Sorry, I am using DAQmx ver 8.9.0f4p1 and VB6.0 with service pack3. After some more testing, I think that it may be something with VB6. I found a sample project on the web that works well, but fails when I copy the function or add the form into my project. I tested by copying my function into the sample project and it worked, but also fails if I create a new project and add the form from the sample project to it.

 

Thanks for your support.

GSS

0 Kudos
Message 6 of 6
(8,047 Views)