作者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