Dobry den. Mam zarizeni se kterym komunikuji po seriovem portu. Mam napsany tento program ve visual basicu 2010 expres:
Public Class Form1
Dim inputData As String = "@00RO#013"
Public Event DataReceived As IO.Ports.SerialDataReceivedEventHandler
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Set values for some properties
SerialPort1.PortName = "COM3"
SerialPort1.BaudRate = 9600
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.Handshake = IO.Ports.Handshake.None
SerialPort1.RtsEnable = True
' Open the Serial Port
SerialPort1.Open()
'Writes data to the Serial Port output buffer
If SerialPort1.IsOpen = True Then
SerialPort1.Write("MicroCommand")
End If
End Sub
' Receive data from the Serial Port
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived
inputData = SerialPort1.ReadExisting 'or SerialPort1.ReadLine
Me.Invoke(New EventHandler(AddressOf DoUpdate))
End Sub
'Show received data on UI controls and do something
Public Sub DoUpdate()
TextBox1.Text = TextBox1.Text & inputData
End Sub
Private Sub Form1_FormClosed(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosedEventArgs) _
Handles MyBase.FormClosed
' Close the Serial Port
SerialPort1.Close()
End Sub
End Class
Kde inputData je retezec, ktery za pouziti programu terminal mi vrati data. Bohuzel tento program mi do textoveho pole nic nevraci. Ledka na redukci USB na RS485 pri spusteni programu problikne, takze se neco posila. Muzete mi nekdo prosim poradit jak zjistim co posilam, a jestli neco prijimam? Dekuji, Pratos
|