Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This code was made to discover a serialport device which responds to (Data-Terminal-Ready)
- It will get all the serialports available and list the device which responds with "ARINIT"
- This will basically allow you to quickly find the port your arduino is on and close the port
- ready for when you want to connect to it again by using the listed item.
- Imports System.IO.Ports
- Public Sub scan4arduino()
- Button1.Enabled = False
- ListBox1.Items.Clear()
- Dim ports As String() = SerialPort.GetPortNames()
- Dim response As String = ""
- For i = 0 To ports.Count - 1
- SerialPort1.PortName = ports(i)
- SerialPort1.Open()
- System.Threading.Thread.Sleep(2000) 'Give the serial port chance to respond to DTR
- response = SerialPort1.ReadExisting
- If response.Contains("ARINIT") Then 'Return devices that respond with certain phrase (<> "" for any device)
- ListBox1.Items.Add(ports(i) + " DTR Response: " + response)
- SerialPort1.Close()
- End If
- SerialPort1.Close()
- Next
- If ListBox1.Items.Count = 0 Then
- ListBox1.Items.Add("No serial ports devices found")
- End If
- Button1.Enabled = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment