Advertisement
Aveneid

Skanowanie portu com

Nov 15th, 2019
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Private Sub ReadDataSerial()
  2.         If selectedCom IsNot Nothing Then
  3.             Try
  4.                 Dim data As String = Nothing
  5.                 com = My.Computer.Ports.OpenSerialPort(selectedCom)  'otwieranie portu com
  6.                 com.BaudRate = CInt(9600)                            'i ustawianie predkosci na 9600 bitow/s
  7.                'com.ReadTimeout = 10000
  8.                Do
  9.                     If cancelling = True Then
  10.                         Exit Do
  11.                     Else
  12.                         If com IsNot Nothing Then
  13.                             data = com.ReadLine()                     'odczytywanie portu
  14.                             If data IsNot Nothing Then                'jesli sa jakies dane
  15.                                'MsgBox(data)
  16.                                Logs.RichTextBox1.ReadOnly = False
  17.                                 Logs.RichTextBox1.AppendText(vbNewLine & "Scanned data: " & data)  'dodaj je do pola tekstowego
  18.                                Logs.RichTextBox1.ReadOnly = True
  19.                                 SendKeys.Flush()
  20.                                 My.Computer.Clipboard.SetText(data)
  21.  
  22.                                 SendKeys.SendWait("^V")
  23.                             End If
  24.                             data = Nothing
  25.                         End If
  26.                         Thread.Sleep(10) 'uspij watek na 10ms
  27.  
  28.                     End If
  29.                 Loop
  30.  
  31.             Catch ex As Exception
  32.                 Dim extype = ex.GetType
  33.                 If extype = GetType(TimeoutException) Then 'jestli jest exception i jest typu timeout
  34.                    Logs.RichTextBox1.AppendText("Error: read timeout (10s)") 'to daj o tym znac
  35.                End If
  36.                 com.Close() 'zamknij port com
  37.                com = Nothing
  38.                 ReadDataSerial()
  39.             End Try
  40.         End If
  41.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement