[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
Public Class Form1
Private WithEvents BackgroundWorker1 As New System.ComponentModel.BackgroundWorker
Private SerialPort1 As New System.IO.Ports.SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
If SerialPort1.IsOpen = False Then
SerialPort1.PortName = System.IO.Ports.SerialPort.GetPortNames()(0)
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = System.IO.Ports.Parity.None
SerialPort1.StopBits = System.IO.Ports.StopBits.One
SerialPort1.Open()
End If
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
Try
Static rxcnt As Integer = 0
Static rxbuf(1024) As Byte
While True
If SerialPort1.BytesToRead <> 0 Then
rxcnt = SerialPort1.Read(rxbuf, rxcnt, SerialPort1.BytesToRead)
BackgroundWorker1.ReportProgress(0, rxbuf)
End If
End While
Catch ex As Exception
End Try
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.ProgressChangedEventArgs) _
Handles BackgroundWorker1.ProgressChanged
Dim rxbuf() As Byte = e.UserState
TextBox1.Text = rxbuf(0)
End Sub
End Class
04 | 2025/05 | 06 |
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |