W
wjwwj
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做的用轮询法查看单片机里面有没有数据,我用下面的代码处理串口,这段代码是放在一个定时器的,就是用定时器不断的发命令
If MSCom_Assess.PortOpen And g_PortOpened = False then
MSCom_Assess.PortOpen = False
MSCom_Assess.InBufferSize = InBSize
MSCom_Assess.OutBufferSize = OutBSize
MSCom_Assess.InputMode = comInputModeBinary '设置数据接收模式为二进制形式
MSCom_Assess.CommPort = PortNum
MSCom_Assess.PortOpen = True
g_PortOpened = True
End If
If MSCom_Assess.PortOpen = False And g_PortOpened = False then
MSCom_Assess.InBufferSize = InBSize
MSCom_Assess.OutBufferSize = OutBSize
MSCom_Assess.InputMode = comInputModeBinary '设置数据接收模式为二进制形式
MSCom_Assess.CommPort = PortNum
MSCom_Assess.PortOpen = True
g_PortOpened = True
End If
MSCom_Assess.OutBufferCount = 0
MSCom_Assess.InBufferCount = 0
MSCom_Assess.Output = "FFAA0"
会出现"port already open"的提示,但我查看MSCom_Assess.PortOpen确是false,但是一运行到MSCom_Assess.PortOpen = True时就会出现"port already open"的提示,我又用MSCom_Assess.PortOpen = False来试,却提示"the device is not open",之后串口就怎么也不能用了,只有重启计算机才正常。
这是什么问题呢?我的分只有这么多了,请各位不吝赐教,谢谢!!!
If MSCom_Assess.PortOpen And g_PortOpened = False then
MSCom_Assess.PortOpen = False
MSCom_Assess.InBufferSize = InBSize
MSCom_Assess.OutBufferSize = OutBSize
MSCom_Assess.InputMode = comInputModeBinary '设置数据接收模式为二进制形式
MSCom_Assess.CommPort = PortNum
MSCom_Assess.PortOpen = True
g_PortOpened = True
End If
If MSCom_Assess.PortOpen = False And g_PortOpened = False then
MSCom_Assess.InBufferSize = InBSize
MSCom_Assess.OutBufferSize = OutBSize
MSCom_Assess.InputMode = comInputModeBinary '设置数据接收模式为二进制形式
MSCom_Assess.CommPort = PortNum
MSCom_Assess.PortOpen = True
g_PortOpened = True
End If
MSCom_Assess.OutBufferCount = 0
MSCom_Assess.InBufferCount = 0
MSCom_Assess.Output = "FFAA0"
会出现"port already open"的提示,但我查看MSCom_Assess.PortOpen确是false,但是一运行到MSCom_Assess.PortOpen = True时就会出现"port already open"的提示,我又用MSCom_Assess.PortOpen = False来试,却提示"the device is not open",之后串口就怎么也不能用了,只有重启计算机才正常。
这是什么问题呢?我的分只有这么多了,请各位不吝赐教,谢谢!!!