TIA V16 RT advanced用MSComm串口通信,只能接收调试工具发送的单个字符(或单个十六进制数),若一次发送多个字符(>=2个字符),则显示InBufferCount为0;
若RThreshold=2,则还是只能发送单个字符,但识别(显示)时,是按Unicode码显示的(如:0x61,0X00,对应'a'因为TIA RT advanced只支持WString,再发送,则会覆盖‘a’)
' 打开串口,因为直接操作PortOpen属性无效。
objMSComm1.CommPort=3
objMSComm1.Settings="9600,N,8,1"
objMSComm1.RThreshold=1
objMSComm1.SThreshold=0
' 以二进制形式接收
objMSComm1.InputMode=1
objMSComm1.InBufferCount=0
' 每次读取全部数据
objMSComm1.InputLen=0
' objMSComm1.Enabled=True
' 打开串口
tagPortOpen.Value=True
OnComm部分:
' 读取InBufferCount值
tagCount.Value=objMSComm1.InBufferCount
' 读取接收数据
strTemp=CStr(objMSComm1.Input)
' 将接收数据显示
tagRecBuffer.Value=strTemp
若InputMode=0,只能正确接收调试工具第一次发送的单个字符,再发送时,InBufferCount就变为0了。