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