30-06-19, 06:44 PM
(آخر تعديل لهذه المشاركة : 30-06-19, 06:45 PM {2} بواسطة sniperjawadino.)
قم بإضافة أداة SerialPort1 Button1 Textbox1
وضع هذا الكود في Button1
مع تغيير الإعدادات التي تناسب الآلة PortName BaudRate
ثم ضع هذا الكود في الفورم
وضع هذا الكود في Button1
مع تغيير الإعدادات التي تناسب الآلة PortName BaudRate
كود :
SerialPort1.PortName = COM1
SerialPort1.BaudRate = 9600
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.DataBits = 8
'SerialPort1.Handshake = IO.Ports.Handshake.None
'SerialPort1.Encoding = System.Text.Encoding.ASCII
SerialPort1.Open()ثم ضع هذا الكود في الفورم
كود :
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting()) 'Automatically called every time a data is received at the SerialPort1
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data
Private Sub ReceivedText(ByVal [text] As String)
'compares the ID of the creating Thread to the ID of the calling Thread
If Me.rtbReceived.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.rtbReceived.Text &= [text]
Me.TextBox1.Text = [text]
End If
End Sub
