Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub ReadDataSerial()
- If selectedCom IsNot Nothing Then
- Try
- Dim data As String = Nothing
- com = My.Computer.Ports.OpenSerialPort(selectedCom) 'otwieranie portu com
- com.BaudRate = CInt(9600) 'i ustawianie predkosci na 9600 bitow/s
- 'com.ReadTimeout = 10000
- Do
- If cancelling = True Then
- Exit Do
- Else
- If com IsNot Nothing Then
- data = com.ReadLine() 'odczytywanie portu
- If data IsNot Nothing Then 'jesli sa jakies dane
- 'MsgBox(data)
- Logs.RichTextBox1.ReadOnly = False
- Logs.RichTextBox1.AppendText(vbNewLine & "Scanned data: " & data) 'dodaj je do pola tekstowego
- Logs.RichTextBox1.ReadOnly = True
- SendKeys.Flush()
- My.Computer.Clipboard.SetText(data)
- SendKeys.SendWait("^V")
- End If
- data = Nothing
- End If
- Thread.Sleep(10) 'uspij watek na 10ms
- End If
- Loop
- Catch ex As Exception
- Dim extype = ex.GetType
- If extype = GetType(TimeoutException) Then 'jestli jest exception i jest typu timeout
- Logs.RichTextBox1.AppendText("Error: read timeout (10s)") 'to daj o tym znac
- End If
- com.Close() 'zamknij port com
- com = Nothing
- ReadDataSerial()
- End Try
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement