09-04-2007 10:00 AM
09-05-2007 09:33 AM
09-05-2007 12:42 PM
08-17-2009 11:15 AM
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
08-18-2009 05:41 PM
What version of DAQmx do you have?
Glenn
08-18-2009 08:33 PM
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