VB与三菱PLC编程口通信

[复制链接]
查看1486 | 回复1 | 2011-4-13 23:19:00 | 显示全部楼层 |阅读模式
-------------------------------------------------------------- Private Sub Form_Load() '调用MSCOMM控件 With MSComm1 .Settings = "9600,e,7,1" .CommPort = 1 .RTSEnable = True End With End Sub --------------------------------------------------------------- Private Sub Command5_Click() ' 置位Y2 Y2 = Chr$(2) + "7" + "0205" + Chr$(3) + "01" MSComm1.Output = Y2 End Sub ---------------------------------------------------------------- Private Sub Command6_Click() '复位Y2 Y2A = Chr$(2) + "8" + "0205" + Chr$(3) + "02" MSComm1.Output = Y2A End Sub 以上代码测试过OK了,请问有谁知道要怎么读取PLC的Y2点状态,来控制shape1控件,就是Y2为置位时shape1控件为红色,Y2为OFF时shape1控件为绿色
missile_v2011 | 2011-7-16 11:13:00 | 显示全部楼层
\'强制Y2_ON_OFF Private Sub Command5_Click() Dim AckStr As String Dim sendstr As String If Shape_Y2.FillColor = QBColor(10) Then sendstr = Chr$(2) + "70205" + Chr$(3) + "01" \'强制Y2_ON MSComm1.Output = sendstr AckStr = MSComm1.Input \'m1 = Asc(AckStr) If AckStr = Chr(15) Then \'用返回值<>chr(6)来解决初始状态点击无用, Shape_Y2.FillColor = QBColor(10) \'反向 Else Shape_Y2.FillColor = QBColor(12) \'反向 End If Else sendstr = Chr$(2) + "80205" + Chr$(3) + "02" \'强制Y2_OFF MSComm1.Output = sendstr AckStr = MSComm1.Input If AckStr = Chr(6) Then Shape_Y2.FillColor = QBColor(10) Else Shape_Y2.FillColor = QBColor(12) End If End If End Sub
您需要登录后才可以回帖 登录 | 注册哦

本版积分规则