日本JAPANESE熟睡人妻_久久99热只有频精品6狠狠_欧美一区内射最近更新_美女露100‰奶头18禁_日韩性生活一级片_国产三级无码内射在线看

tangfeng
學海無涯
級別: 探索解密
精華主題: 0
發帖數量: 44 個
工控威望: 143 點
下載積分: 922 分
在線時間: 96(小時)
注冊時間: 2010-01-24
最后登錄: 2025-03-25
查看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 輸入點,下標越界,望高手指點修改
roger614
級別: 略有小成
精華主題: 0
發帖數量: 78 個
工控威望: 235 點
下載積分: 472 分
在線時間: 154(小時)
注冊時間: 2007-10-28
最后登錄: 2018-09-26
查看roger614的 主題 / 回貼
1樓  發表于: 2018-03-10 14:15
用4樓方法編寫簡單

主站蜘蛛池模板: 女调教脚奴网站 | 久久久免费播放 | 久久日韩精品一区二区五区 | 老外黑人欧美一级毛片 | 国产超碰人人爽人人做人人添 | 久久精品国产国产精品四凭 | 91精产国品 | 国产一二三四区乱码免费 | 久久99热久久99精品 | 精品亚洲在线 | 日本网站一区二区三区 | BBWBBW高潮喷水 | 亚洲一区二区三区四区不卡 | 亚洲综合无码无在线观看 | 午夜av亚洲女人剧场se | 日韩AV高清在线看片 | 亚洲日韩精品无码专区 | 国产国拍亚洲精品在线 | 一个人在线视频免费观看WWW | 99精品热视频只有精品10 | 国产精品久久久久久影院8一贰佰 | 粗暴进入娇小呻吟痛呼 | 国产精品人人妻人人爽人人牛 | 国产久艹视频 | 久草在线视频新 | 高潮潮喷奶水飞溅视频无码 | 免费看国产成年无码AV | 久青草国产在视频在线观看 | 中国帅男同志gayxxxx | 91九色麻豆 | 91欧美一区二区三区蜜臀 | 美女总裁的贴身保镖短剧 | 久久精品国内一区二区三区 | 国产一级做a爰片在线看免费 | 四虎黄色网址 | 99热这里只有精品首页 | 精品国产一区二区三区性色av | 国产精品97在线 | 蜜臀久久99精品久久久酒店新书 | 九一福利视频 | 欧洲色情三级欧美三级视频 |