关于VB,mscomm控件和西门子plc通行的问题

soller_T 2014-04-10 10:50:26
Private Sub MSComm1_OnComm()
If Command2.Caption = "停止接受" Then
Select Case CommEvent
Case comEvReceive
temp = MSComm1.Input
ReDim Preserve temp(UBound(temp)) As Byte
For i = LBound(temp) To UBound(temp)
Text2 = Text2 & str$(temp(i)) & " "
Next i
End Select

End If

End Sub

usb/ppi电缆的发送信号和接受信号都亮起,但是没有显示到text2上,是代码有问题还是其他什么原因,希望各位提供帮助,不甚感激~
...全文
319 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
of123 2014-05-22
  • 打赏
  • 举报
回复
If Command2.Caption = "停止接收" Then '首先检查这里,字符串是否与命令按钮显示的相同
    Select Case CommEvent
        Case comEvReceive
            temp = MSComm1.Input
            If MSComm1.InputMode=comInputModeText Then
                Text2 = StrConv(temp, vbUnicode)
            Else
                For i = LBound(temp) To UBound(temp)
                    Text2 = Text2 & IIf(Text2 = "", "", " ") & Right("0" & Hex(temp(i)), 2)
                Next i
            End If
    End Select
End If
熊孩子开学喽 2014-05-21
  • 打赏
  • 举报
回复
首先你得知道temp到底有没有收到数据

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧