Private Sub vbMain()
Const MAX_CNT = 200
Dim stat Dim dfltRM Dim sesn Dim retCount Dim buffer | As ViStatus As ViSession As ViSession As Long As String * MAX_CNT |
Rem Begin by initializing the system
stat = viOpenDefaultRM(dfltRM)
If (stat < VI_SUCCESS) Then
Rem Error initializing VISA...exiting
Exit Sub
End If
Rem Open communication with Serial Port 1
Rem NOTE: For simplicity, we will not show error checking
stat = viOpen(dfltRM, "ASRL1::INSTR", VI_NULL, VI_NULL, sesn)
Rem Set the timeout for message-based communication
stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 5000)
Rem Lock the serial port so that nothing else can use it
stat = viLock(sesn, VI_EXCLUSIVE_LOCK, 5000, "", "")
Rem Set serial port settings as needed
Rem Defaults = 9600 Baud, no parity, 8 data bits, 1 stop bit
stat = viSetAttribute(sesn, VI_ATTR_ASRL_BAUD, 2400)
stat = viSetAttribute(sesn, VI_ATTR_ASRL_DATA_BITS, 7)
Rem Ask the device for identification
stat = viWrite(sesn, "*IDN?", 5, retCount)
stat = viRead(sesn, buffer, MAX_CNT, retCount)
Rem Unlock the serial port before ending the program
stat = viUnlock(sesn)
Rem Your code should process the data
Rem Close down the system
stat = viClose(sesn)
stat = viClose(dfltRM)
End Sub |