Public Sub psubInitComPort(intMsCommIndex As Integer, intComNo As Integer, strSettings As String, intInBuffSize As Integer, intRThreshold As Integer, blnPortOpen As Boolean)
On Error GoTo err_proc
If blnPortOpen Then '--打開串口
MSComm(intMsCommIndex).CommPort = intComNo '--使用端口Com1~8
MSComm(intMsCommIndex).Settings = strSettings '"1200,N,8,1" '--設置端口屬性,設置波特率1200、無奇偶校驗、8數據位和1停止位
MSComm(intMsCommIndex).InBufferSize = intInBuffSize '1024 '--設置接收緩沖區大小為1024個字節
MSComm(intMsCommIndex).RThreshold = intRThreshold ' 12 '--設置每接收n個字節觸發OnComm()事件
MSComm(intMsCommIndex).InBufferCount = 0 '--清空接收緩沖區
MSComm(intMsCommIndex).InputLen = 0 '--使用Input屬性時在接收緩沖區讀取的字符數,0為讀取整個接收緩沖區內容
MSComm(intMsCommIndex).InputMode = comInputModeBinary '--Input屬性取的數據是二進制數據
If Not MSComm(intMsCommIndex).PortOpen Then '--打開串口
MSComm(intMsCommIndex).PortOpen = True
End If
Else
If MSComm(intMsCommIndex).PortOpen Then '--關閉串口
MSComm(intMsCommIndex).PortOpen = False
End If
End If
Exit Sub
err_proc:
End Sub