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
--
xblessing 3 9336
On Sep 18, 7:34 pm, xblessing <xbless...@discussions.microsoft.com>
wrote:
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
--
xblessing
Could you post the VB6 sample... Most likely, there is a problem with
your delarations.
--
Tom Shelton
"xblessing" <xb*******@discussions.microsoft.comschrieb
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!
[...]
Declare Function GetAsciiA _
Lib "M530DLL.dll" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
I guess it must be "ByRef bytesRead As Integer". Probably, in the VB6 code,
there is neither ByVal nor ByRef. Unspecified, it's ByRef by default. In
VB.Net, unspecified, it's auto-completed with ByVal.
Armin
Tom and Armin,
Thanks for the reply. I tried to change the last byVal to byRef. The code
is working well now. Thanks a lot for your help.
------
xblessing
"Armin Zingler" wrote:
"xblessing" <xb*******@discussions.microsoft.comschrieb
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!
[...]
Declare Function GetAsciiA _
Lib "M530DLL.dll" Alias "GetAscii" _
(ByVal deviceID As Integer, _
ByVal response As String, _
ByVal bytesRead As Integer) As Integer
I guess it must be "ByRef bytesRead As Integer". Probably, in the VB6 code,
there is neither ByVal nor ByRef. Unspecified, it's ByRef by default. In
VB.Net, unspecified, it's auto-completed with ByVal.
Armin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: William Brogden |
last post by:
I am trying to use the php_java.dll and php5servlet.dll
- from pecl-5.1.4-win32.zip - dated 5/04/2006
to execute php in a Tomcat5.5.9 servlet environment. Java 1.5.0
I finally got a configuration...
|
by: Curten |
last post by:
Hi,
I want to read data from a txt-file that looks like this:
aaa 4 12.45
bbb 3 7.34
ccc 12 3.45
and store the data in an array of structures. The struct and array are defined...
|
by: Lee |
last post by:
Hi all, been playing with some code overriding WndProc to get
information about mouse events.
So far I've tried to capture when the left mouse button is pressed
using the code below.
Sometimes...
|
by: pbaldridge |
last post by:
I'm just starting my first C++ class and have a very basic question. We are to write a program that is going to be using the pow10(int m) function and we are not to use the pow10 function from the...
|
by: Kirzak pascuale |
last post by:
ok I made this exercise, for a compiler design course. it is not urgent as the assignment was due 2 days ago. i got a 4 out of 10 for effort. mainly because i did not just rehash code examples from...
| |
by: Johnex |
last post by:
Hi!
I am currently writing a tiny webserver that i can attach to all my applications to give them web functionality. I first started of making all the socket and helper classes to handle the...
|
by: zubair1 |
last post by:
Hello,
I have a program which deletes files from cache
for exampe:-
Temporary Internet Cache
History Cache
Cookie Cache
and finally TEMP cache
|
by: amungen |
last post by:
I am getting the following error from my code:
Traceback (most recent call last):
File "<pyshell#309>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line...
|
by: dantz |
last post by:
Hi Everyone,
Currently I am having this exception:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I am still debugging which part of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |