Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Programs developed with VISA.dll always crash in win10?

Solved!
Go to solution

 

The same program works normally in win7, but often crashes in win10. At the beginning of the computer boot, the probability of crash is very high, and no error is reported. Then open the program several times before it works properly. It's not always wrong, just occasionally.
Programs generally crash after the "TextBox 1. Text" display device ID. It's strange that if "TextBox 1. Text" already shows the ID, the function is running out. But why did it crash?
The DEBUG mode of VS2017 is used. It won't crash.
VISA.dll is installed in Agilent IOlibrary. I use VB.NET, VS2017.

 

The code:

 

Declare Function viOpenDefaultRM Lib "VISA32.DLL" Alias "#141" (sesn As Long) As Long
Declare Function viGetDefaultRM Lib "VISA32.DLL" Alias "#128" (sesn As Long) As Long
Declare Function viFindRsrc Lib "VISA32.DLL" Alias "#129" (ByVal sesn As Long, ByVal expr As String, vi As Long, retCount As Long, ByVal desc As String) As Long
Declare Function viFindNext Lib "VISA32.DLL" Alias "#130" (ByVal vi As Long, ByVal desc As String) As Long

Declare Function viOpen Lib "VISA32.DLL" Alias "#131" (ByVal sesn As Long, ByVal viDesc As String, ByVal mode As Long, ByVal timeout As Long, vi As Long) As Long
Declare Function viClose Lib "VISA32.DLL" Alias "#132" (ByVal vi As Long) As Long

Declare Function viVSPrintf Lib "VISA32.DLL" Alias "#205" (ByVal vi As Long, ByVal Buffer As String, ByVal writeFmt As String, params As Long) As Long
Declare Function viVScanf Lib "VISA32.DLL" Alias "#272" (ByVal vi As Long, ByVal readFmt As String, params As String) As Long

 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim status As Long
Dim defrm As Long
Dim vi As Long
Dim strRes As String
Dim strRes1 As String
Dim strRes2 As String
Dim actual As Long
status = viOpenDefaultRM(defrm) 


status = viOpen(defrm, "GPIB0::7::INSTR", 0, 0, vi)


status = viVPrintf(vi, "*IDN?" + vbCrLf, 0)


System.Threading.Thread.Sleep(10)'Increasing delay time reduces the probability of crash


status = viVScanf(vi, "%t", strRes) 

TextBox1.Text = strRes 

End Sub

 

 

 

 

 

0 Kudos
Message 1 of 4
(2,681 Views)
Solution
Accepted by topic author xiaochouyu

Solved. Change "string" to "String Builder"!!!!!

 

Declare Function viVScanf Lib "VISA32.DLL" (ByVal vi As Integer, ByVal readFmt As String, ByRef params As StringBuilder) As Integer

 

but why?

0 Kudos
Message 3 of 4
(2,644 Views)
Solution
Accepted by topic author xiaochouyu

Correction: The initial value of params should be set very large.

For example:

Public strRes As String = “000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000”

 

Then use "viVScanf" to work properly.

 

status = viVScanf(vi, "%t", strRes)

 

Because no matter "string" or "string builder" for the computer's memory allocation space is limited. When the data uploaded by VI exceeds the limit, it may overwrite the wrong memory space and cause EXE to crash.

0 Kudos
Message 4 of 4
(2,635 Views)