欧美鲁鲁_啦啦啦啦在线观看_日韩精品短视频_玩偶姐姐作品在线观看_天天综合天天做天天综合_国产综合图区

tangfeng
學海無涯
級別: 探索解密
精華主題: 0
發帖數量: 44 個
工控威望: 143 點
下載積分: 922 分
在線時間: 98(小時)
注冊時間: 2010-01-24
最后登錄: 2025-07-19
查看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位數據  用串口監測軟件看一下數據結構應該很好理解

主站蜘蛛池模板: 91最新视频在线观看 | 亚洲一级电影 | 校园激情久久 | 国产精品又黄又爽又色无遮挡 | 日日夜夜干| 日日夜夜澡 | hd极品free性xxx护士 | 精品熟女少妇av免费久久 | 久久艹国产精品 | 佐山爱av在线 | 亚洲天堂手机在线观看 | 天堂网www.| 中文字幕88av | 91操bb | 亚洲精一区 | 婷婷在线免费 | 一区二区视频传媒有限公司 | 国产在线不卡一区 | 亚洲AV无码日韩AV无码网站冲 | 国产伦精品一区二区三区免.费 | 综合天天 | 少妇愉情理仑片高潮 | 91精品一区二区三区四区 | 中文在线资源观看视频网站免费不卡 | 97五月婷婷 | 亚洲人成色7777在线观看不卡 | 赤兔gay帅仔chinese | 九一国产在线 | 91成年人视频在线观看 | 亚洲精品网站免费 | 国产特一级黄色片 | 啊轻点灬太粗嗯太深了啊 | 国产三级精品三级在线观看国产 | 国产伦精品一区二区三区免费视频 | 国产精品熟女一区二区 | 在线观看免费不卡av | 偷 拍 自 拍 在线视频 | 久久国产热这里只有精品 | 国产福利毛片 | 无翼乌之侵犯工口全彩老师 | chinese老太交70years |