国产一区视频在线观看-国产重口老太和小伙-亚洲v高-中文岛国精品亚洲一区亚-免费a级毛片出奶水-黄网站入口

tangfeng
學海無涯
級別: 探索解密
精華主題: 0
發帖數量: 44 個
工控威望: 143 點
下載積分: 922 分
在線時間: 98(小時)
注冊時間: 2010-01-24
最后登錄: 2025-07-10
查看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 輸入點,下標越界,望高手指點修改
duquanplc
DDD
級別: 略有小成
精華主題: 0
發帖數量: 260 個
工控威望: 404 點
下載積分: 703 分
在線時間: 220(小時)
注冊時間: 2008-08-25
最后登錄: 2025-06-08
查看duquanplc的 主題 / 回貼
1樓  發表于: 2017-09-08 21:57
為什么不用專用協議做呢?格式一或格式四都可。

主站蜘蛛池模板: 性欧美俄罗斯乱妇| 狠狠亚洲婷婷综合色香五月| 人妻丰满熟妇av无码区hd| 亚洲中文字幕琪琪在线| 波多野结衣一区二区三区高清| 中国老熟妇自拍hd发布| 97精品依人久久久大香线蕉97 | 国产成人18黄网站| 精品无人区一区二区三区在线| 国产精品久久久久久婷婷| 国产末成年女av片一区二区| 一区二区亚洲精品国产精华液| 无码人妻精品一区二区蜜桃网站| 欧美亚洲日本国产综合在线| 亚洲在线国产日韩欧美| 国产在沙发上午睡被强| 国产乡下妇女做爰| 欧美日韩一本无线码专区| 男女啪动最猛动态图| 精品久久久久久久久午夜福利| 狠狠躁天天躁无码中文字幕| 色翁荡息又大又硬又粗又爽| 强行糟蹋人妻hd中文| 日本不卡三区| 国产亚洲精品aa片在线观看网站| 人妻精品久久无码区| 欧美18videosex性欧美黑吊| 少妇熟女视频一区二区三区| 精品日韩亚洲欧美高清a| 青青久在线视频免费观看| 午夜影院91| 性中国videossexo另类| 少妇人妻精品一区二区| 婷婷五月婷婷五月| 又色又爽又高潮免费观看| 国产一区二区三区导航| 久久99国产精品久久99| 亚洲国产美国国产综合一区| 伊人情人色综合网站| 久久久久人妻精品区一| 国产成人亚洲精品狼色在线|