作者gecer (gecer)
看板Visual_Basic
标题[VBA ] 请问VB与台达plc通讯
时间Mon Jan 27 14:24:19 2014
Public Class Form1
Private msg As String
Private rxd() As Byte
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SerialPort1.PortName = "COM6"
SerialPort1.BaudRate = 9600
SerialPort1.Parity = IO.Ports.Parity.Even
SerialPort1.DataBits = 7
SerialPort1.StopBits = 1
SerialPort1.Open()
Button1.Text = "Off"
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing '关闭视窗
msg = ":010508000000" & LRC.lrc("010508000000") & Chr(13) & Chr(10)
Me.SerialPort1.Write(msg)
SerialPort1.Close()
Button1.Text = "Off"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Select Case Button1.Text
Case "Off"
msg = ":01050800FF00" & LRC.lrc("01050800FF00") & Chr(13) &
Chr(10)
Me.SerialPort1.Write(msg)
Button1.Text = "On"
Case "On"
msg = ":010508000000" & LRC.lrc("010508000000") & Chr(13) &
Chr(10)
Me.SerialPort1.Write(msg)
Button1.Text = "Off"
End Select
DELAY.delay(360)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
msg = ":010105000001" & LRC.lrc("010105000001") & Chr(13) & Chr(10)
Me.SerialPort1.Write(msg)
DELAY.delay(80)
TextBox2.Text = Me.SerialPort1.ReadExisting
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
小弟想读取PLC节点状态 但是红色部分结果如下图
http://www.fotopu.com/fullsize/516477
连先前的命令码都读取了 请问如何解决?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 36.237.53.235
1F:→ gecer:以解决 利用me.serialport1.discardinbuffer 01/28 09:54