G
Guest
Hello,
I'm trying to communicate with a TEC Controller Newport 350B using their
..dll and VB.NET. I was able to use their example code with VB6. However,
I've got following error when using VB.NET:
"Access Violation Exception was unhandled. Attempted to read or write
protected memory. This is often an indication that other memory is corrupt."
I have no problem when send commands to my TEC Controller (using
"SendAsciiA" - see below for the code). But, I always got error when trying
to query the TEC Controller using "GetAsciiA." Thanks in advance!
Here is the declaration on my code:
Declare Function InitSystem _
Lib "M530DLL.dll" () As Integer
Declare Function SendAsciiA _
Lib "M530DLL.dll" Alias "SendAscii" _
(ByVal deviceID As Integer, _
ByVal command As String, _
ByVal length As Integer) As Integer
Declare Function GetAsciiA _
Lib "M530DLL.dll" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
Here is the code to call the function:
Public Function NPWriteRead(ByVal NPCommand As String, ByVal DeviceID As
Short) As String
Dim strRes As String = New String(" ", 64)
Dim bytesRead As Integer
Dim ret As Integer
Call NPWrite(NPCommand, DeviceID) 'this procedure will send the
command to the instrument.
ret = GetAsciiA(DeviceID, strRes, bytesRead) -> this is where the
error occurs
If ret = M530USBINVALIDADDRESS Then
MsgBox("USB Address Invalid", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530ERROR Then
MsgBox("USB Communication Error", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530USBADDRESSNOTFOUND Then
MsgBox("USB Address not Found", vbOKOnly + vbCritical, "M530")
End If
Return Trim(strRes)
End Function
I'm trying to communicate with a TEC Controller Newport 350B using their
..dll and VB.NET. I was able to use their example code with VB6. However,
I've got following error when using VB.NET:
"Access Violation Exception was unhandled. Attempted to read or write
protected memory. This is often an indication that other memory is corrupt."
I have no problem when send commands to my TEC Controller (using
"SendAsciiA" - see below for the code). But, I always got error when trying
to query the TEC Controller using "GetAsciiA." Thanks in advance!
Here is the declaration on my code:
Declare Function InitSystem _
Lib "M530DLL.dll" () As Integer
Declare Function SendAsciiA _
Lib "M530DLL.dll" Alias "SendAscii" _
(ByVal deviceID As Integer, _
ByVal command As String, _
ByVal length As Integer) As Integer
Declare Function GetAsciiA _
Lib "M530DLL.dll" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
Here is the code to call the function:
Public Function NPWriteRead(ByVal NPCommand As String, ByVal DeviceID As
Short) As String
Dim strRes As String = New String(" ", 64)
Dim bytesRead As Integer
Dim ret As Integer
Call NPWrite(NPCommand, DeviceID) 'this procedure will send the
command to the instrument.
ret = GetAsciiA(DeviceID, strRes, bytesRead) -> this is where the
error occurs
If ret = M530USBINVALIDADDRESS Then
MsgBox("USB Address Invalid", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530ERROR Then
MsgBox("USB Communication Error", vbOKOnly + vbCritical, "M530")
ElseIf ret = M530USBADDRESSNOTFOUND Then
MsgBox("USB Address not Found", vbOKOnly + vbCritical, "M530")
End If
Return Trim(strRes)
End Function