成全高清免费完整观看,日韩一区二区三免费高清,欧美在线看欧美视频免费,日本无码专区无码二区

tangfeng
學海無涯
級別: 探索解密
精華主題: 0
發帖數量: 44 個
工控威望: 143 點
下載積分: 922 分
在線時間: 97(小時)
注冊時間: 2010-01-24
最后登錄: 2025-06-28
查看tangfeng的 主題 / 回貼
樓主  發表于: 2017-09-02 16:50
'在窗體的Load事件中加入下列代碼對串口進行初始化:
Private Sub Form_Load()
  MSComm1.CommPort = 1                  ' 設置通信端口號為COM1
  MSComm1.InputMode = 1                 ' 接收二進制型數據
  MSComm1.RThreshold = 1                ' 設置并返回要接收的字符數
  MSComm1.SThreshold = 1                ' 設置并返回發送緩沖區中允許的最小字符數
  MSComm1.Settings = "9600,E,7,1"       ' 設置串口1通信參數
  MSComm1.PortOpen = True               ' 打開通信端口1
  Timer1.Enabled = False
End Sub
'向PLC發送指令:02 30 31 30 30 30 32 30 03 35 36,功能是從D0開始讀取32個字節數據
Private Sub Cmdsend_Click()
  MSComm1.Output = Chr(&H2) & Chr(&H30) & Chr(&H31) & Chr(&H30) & Chr(&H30) & Chr(&H30) & Chr(&H32) & Chr(&H30) & Chr(&H3) & Chr(&H35) & Chr(&H38)
  Timer1.Enabled = True
End Sub
'獲得各輸入端口狀態
Private Sub Timer1_Timer()
  Dim Inbyte() As Byte
  Dim buffer As String
  ReDim Inbyte(100)
  Inbyte = MSComm1.Input                         '返回的數據串
  For i = LBound(Inbyte) To UBound(Inbyte)
     buffer = buffer + Hex(Inbyte(i)) + Chr(32)
  Next i
  'Text1.Text = buffer                            '顯示返回的數據串,需自己添加TextBox
  If Hex(Inbyte(2)) = "31" Then                  '31表示觸點閉合
    Shape1(0).FillColor = QBColor(12)
  Else                                           '30表示觸點斷開
    Shape1(0).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(6)) = "31" Then
    Shape1(1).FillColor = QBColor(12)
  Else
    Shape1(1).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(10)) = "31" Then
    Shape1(2).FillColor = QBColor(12)
  Else
    Shape1(2).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(14)) = "31" Then
    Shape1(3).FillColor = QBColor(12)
  Else
    Shape1(3).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(18)) = "31" Then
    Shape1(4).FillColor = QBColor(12)
  Else
    Shape1(4).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(22)) = "31" Then
    Shape1(5).FillColor = QBColor(12)
  Else
    Shape1(5).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(26)) = "31" Then
    Shape1(6).FillColor = QBColor(12)
  Else
    Shape1(6).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(30)) = "31" Then
    Shape1(7).FillColor = QBColor(12)
  Else
    Shape1(7).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(34)) = "31" Then
    Shape1(8).FillColor = QBColor(12)
  Else
    Shape1(8).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(38)) = "31" Then
    Shape1(9).FillColor = QBColor(12)
  Else
    Shape1(9).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(42)) = "31" Then
    Shape1(10).FillColor = QBColor(12)
  Else
    Shape1(10).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(46)) = "31" Then
    Shape1(11).FillColor = QBColor(12)
  Else
    Shape1(11).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(50)) = "31" Then
    Shape1(12).FillColor = QBColor(12)
  Else
    Shape1(12).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(54)) = "31" Then
    Shape1(13).FillColor = QBColor(12)
  Else
    Shape1(13).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(58)) = "31" Then
    Shape1(14).FillColor = QBColor(12)
  Else
    Shape1(14).FillColor = QBColor(10)
  End If
  If Hex(Inbyte(62)) = "31" Then
    Shape1(15).FillColor = QBColor(12)
  Else
    Shape1(15).FillColor = QBColor(10)
  End If
  Timer1.Enabled = False
End Sub
'當退出程序時,關閉串行口
Private Sub Cmdquit_Click()
  MSComm1.PortOpen = False           '關閉串口
  Unload Me
End Sub
// 讀不到PLC 輸入點,下標越界,望高手指點修改
yhtxiao
級別: 探索解密
精華主題: 0
發帖數量: 36 個
工控威望: 145 點
下載積分: 496 分
在線時間: 69(小時)
注冊時間: 2011-05-19
最后登錄: 2025-05-24
查看yhtxiao的 主題 / 回貼
1樓  發表于: 2017-09-07 21:33
反饋數據是8位數據  用串口監測軟件看一下數據結構應該很好理解

<sup id="t49uz"><pre id="t49uz"></pre></sup>
    <xmp id="t49uz"><sup id="t49uz"><pre id="t49uz"></pre></sup>
    <sup id="t49uz"><font id="t49uz"></font></sup>
    <sup id="t49uz"></sup>
    主站蜘蛛池模板: 南皮县| 国产永久精品大片wwwApp| 子洲县| 日本无翼乌邪恶大全彩| 成人亚洲A片V一区二区三区蜜月| 宜章县| 柘城县| 欧美肥老太牲交视频| 新巴尔虎左旗| 日韩网红少妇无码视频香港| 商水县| 一本在线不卡免费观看| 欧洲亚洲中日韩在线观看手机版| 潜山县| 欧美专区日韩视频人妻| 成全电影大全在线观看国语版| 中国CHINA露脸自拍性HD| 三年片在线观看大全| 日本妇人成熟a片| 成全在线观看免费完整| 宁陕县| 乱熟女高潮一区二区在线| 日本熟妇色在线视频不卡| 福海县| 欧美人妖aa1片| 欧美牲交a欧美牲交aⅴ视频| 奇台县| 小秘书好紧bd| 乐山市| 噼里啪啦国语在线播放| 梓潼县| 欧美亚韩一区二区三区| 罗源县| 三年在线观看免费大全| 久久久成人毛片无码| 欧美观看免费全部完| 色欲狠狠躁天天躁无码中文字幕| 日本国产网曝视频在线观看| 保靖县| 汕头市| 新密市|