ser_intf.bas

来自「HP GPIB的VB和C语言库文件,参考范例.」· BAS 代码 · 共 59 行

BAS
59
字号

'  set_intf.bas
'  This program does the following:
'  1) gets the current configuration of the serial port
'  2) sets it to 9600 baud, no parity, 8 data bits, and
'     1 stop bit
'  3) prints the old configuration
Sub main ()
   Dim intf As Integer
   Dim baudrate As Long
   Dim parity As Long
   Dim databits As Long
   Dim stopbits As Long
   Dim parity_str As String
   Dim msg_str As String

   ' open RS-232 interface session
   intf = iopen("COM1")
   Call itimeout(intf, 10000)

   ' get baud rate, parity, data bits, and stop bits
   Call iserialstat(intf, I_SERIAL_BAUD, baudrate)
   Call iserialstat(intf, I_SERIAL_PARITY, parity)
   Call iserialstat(intf, I_SERIAL_WIDTH, databits)
   Call iserialstat(intf, I_SERIAL_STOP, stopbits)

   ' determine string to display for parity
   Select Case parity
   Case I_SERIAL_PAR_NONE
      parity_str = "NONE"
   Case I_SERIAL_PAR_ODD
      parity_str = "ODD"
   Case I_SERIAL_PAR_EVEN
      parity_str = "EVEN"
   Case I_SERIAL_PAR_MARK
      parity_str = "MARK"
   Case Else
      parity_str = "SPACE"
   End Select

   ' set to 9600,NONE,8, 1
   Call iserialctrl(intf, I_SERIAL_BAUD, 9600)
   Call iserialctrl(intf, I_SERIAL_PARITY, I_SERIAL_PAR_NONE)
   Call iserialctrl(intf, I_SERIAL_WIDTH, I_SERIAL_CHAR_8)
   Call iserialctrl(intf, I_SERIAL_STOP, I_SERIAL_STOP_1)

   ' display previous settings
   msg_str = "Old settings: " + Str$(baudrate) + "," + parity_str + "," + Str$(databits) + "," + Str$(stopbits)
   MsgBox msg_str, MB_ICON_EXCLAMATION

   ' close port
   Call iclose(intf)

'  Tell SICL to cleanup for this task
   Call siclcleanup

End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?