免费国精产品自偷自偷免费看_在线看片成人_www.77伦理bt.com_特级黄色一级片_免费夜色污私人影院在线观看_国严精品久久久久久亚洲影视

tangfeng
學海無涯
級別: 探索解密
精華主題: 0
發帖數量: 44 個
工控威望: 143 點
下載積分: 922 分
在線時間: 96(小時)
注冊時間: 2010-01-24
最后登錄: 2025-05-12
查看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 輸入點,下標越界,望高手指點修改
gafika
級別: 略有小成
精華主題: 0
發帖數量: 17 個
工控威望: 395 點
下載積分: 2341 分
在線時間: 41(小時)
注冊時間: 2018-02-16
最后登錄: 2025-05-02
查看gafika的 主題 / 回貼
1樓  發表于: 2018-03-10 18:26
ASCII 跟 HEX 要先搞清楚。

主站蜘蛛池模板: 国产精品人妻无码免费 | 69xxxxx国产 | 少妇大叫又粗又大太爽A片 久久人人爽亚洲精品天堂 粉嫩一区二区三区 | 99久久国产综合精品尤物酒店 | 亚洲v天堂v手机在线 | 青青久操视频 | 91?网在线?看| 91欧美在线 | 97无码欧美熟妇人妻蜜 | 久久超碰在线 | 爱爱免费| 性欧美麻豆 | 97色国产 | 亚洲一区二区三区免费 | 粗壮挺进人妻水蜜桃成熟 | 日本一区二区三区视频免费看 | 亚洲一区AV在线观看 | 国产久操视频 | www.夜夜操.com| 午夜在线视频观看 | 国产护士囗交吞精视频 | 日韩欧美成 | 亚洲国产日韩在线 | 久久产精品一区二区三区污欧美 | 成人av片在线观看 | 久久手机免费视频 | 亚洲福利第一页 | 欧美欧美欧美欧美首页 | 亚洲中文字幕久久精品无码2021 | 亚洲精品无码专区 | 国产精品色网站 | 免费播放大片免费观看视频 | 海角在线观看91一区二区 | 亚洲高清视频免费看 | 国产高清女同学巨大乳在线观看 | 九一欧美| 亚洲一区天堂 | 国产v精品成人免费视频400条 | 羞羞午夜爽爽爽爱爱爱爱人人人 | 久久久久国内精品 | 成人午夜免费剧场 |