7,763
社区成员
发帖
与我相关
我的任务
分享
//...
union VBSingle
{
public:
unsigned char Byte1;
unsigned char Byte2;
unsigned char Byte3;
unsigned char Byte4;
}
//...
void COM_Event () interrupt 4
{
VBSingle SngTemp;
unsigned char dat = 0;
if(RI == 1){
dat = SBUF;
RI = 0;
//...
SendBuffToPort(SngTemp,4);
//...
}else{
TI = 0;
}
}
//...
Public Function ConnectPort(Optional hPort As Integer = 0) As Boolean
'...
On Error Resume Next
MSComm1.PortOpen = False
If Err.Number <> 0 Then
Err.Clear
End If
MSComm1.CommPort = X
MSComm1.Settings = 频率 & ",N,8,1"
MSComm1.PortOpen = True
If Err.Number <> 0 Then
GoTo 错误端口
End If
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.InputMode = comInputModeBinary
'...
End Function
Private Sub MSComm1_OnComm()
Dim TempBytes() As Byte
Dim sngTemp As Single
'...
On Error Resume Next
If MSComm1.CommEvent <> comEvReceive Then Exit Sub
ReadBytes = MSComm1.Input
'...
CopyMemory sngTemp,TempBytes(i),4 '这里将读到的数据放到Single类型变量里
'...
End Sub