Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Public Class Form1
Dim strline As String
Dim myPort As Array
Delegate Sub setTextCallBack(ByVal [text] As String)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
PortComboBox.Items.AddRange(myPort)
comokLabel.Enabled = False
Button2.Enabled = False
Button1.Enabled = False
End Sub
Private Sub openButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openButton.Click
If (PortComboBox.Text = "") + (BaudComboBox.Text = "") Then
MessageBox.Show("เลือก Comport หรือ BaudRate")
Else
SerialPort1.PortName = PortComboBox.Text
SerialPort1.BaudRate = BaudComboBox.Text
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.Open()
comokLabel.Enabled = True
openButton.Enabled = False
Button2.Enabled = True
Button1.Enabled = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Close()
openButton.Enabled = True
Button1.Enabled = False
Button2.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
System.Threading.Thread.Sleep(100)
TextBox1.Text = sendTextBox.Text & "="
SerialPort1.Write(sendTextBox.Text & vbLf)
System.Threading.Thread.Sleep(100)
sendTextBox.Text = ("")
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If Me.TextBox1.InvokeRequired Then
Dim x As New setTextCallBack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.TextBox1.Text &= (text)
End If
End Sub
Private Sub addrComboBox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles addrComboBox.SelectedIndexChanged
End Sub
End Class
ตั้งค่า visual basic 2010 ให้อ่าน ภาษาไทยอย่างไรครับ ตอนนี้อ่านได้ เครื่องหมายแบบนี้ ?????
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Public Class Form1
Dim strline As String
Dim myPort As Array
Delegate Sub setTextCallBack(ByVal [text] As String)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
PortComboBox.Items.AddRange(myPort)
comokLabel.Enabled = False
Button2.Enabled = False
Button1.Enabled = False
End Sub
Private Sub openButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openButton.Click
If (PortComboBox.Text = "") + (BaudComboBox.Text = "") Then
MessageBox.Show("เลือก Comport หรือ BaudRate")
Else
SerialPort1.PortName = PortComboBox.Text
SerialPort1.BaudRate = BaudComboBox.Text
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.Open()
comokLabel.Enabled = True
openButton.Enabled = False
Button2.Enabled = True
Button1.Enabled = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Close()
openButton.Enabled = True
Button1.Enabled = False
Button2.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
System.Threading.Thread.Sleep(100)
TextBox1.Text = sendTextBox.Text & "="
SerialPort1.Write(sendTextBox.Text & vbLf)
System.Threading.Thread.Sleep(100)
sendTextBox.Text = ("")
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If Me.TextBox1.InvokeRequired Then
Dim x As New setTextCallBack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.TextBox1.Text &= (text)
End If
End Sub
Private Sub addrComboBox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles addrComboBox.SelectedIndexChanged
End Sub
End Class