O
okrus
Guest
Hi,
My C# app controls two stepper with two different Arduinoes, each with its own COM port. I want the app to connect to the correct COM port automatically.
1. C# must first find all available COM ports.
2. Send a string "s" to all available COM ports and only use the two COM ports that respond with "Elevation" and "Azimuth".
For example .... If C# sends a string "s" to COM3 and and COM3 responds with "Azimuth" then AzimuthPort.PortName = "COM3";. My problem is that I can find all available COM ports, but I can't send them a command because the same COM port cannot be accessed from multiple locations.
private void detectCOMPort()
{
detectPort = new SerialPort();
// Get a list of available COM ports
string[] ports = SerialPort.GetPortNames();
// Display each port name
foreach (string port in ports)
{
detectPort.PortName = port;
detectPort.Write("s");
String compare = detectPort.ReadExisting();
if (compare == "Elevation")
myPort.PortName = port;
if (compare == "Azimuth")
myPort2.PortName = port;
}
}
Any help would be appreciated.
Continue reading...
My C# app controls two stepper with two different Arduinoes, each with its own COM port. I want the app to connect to the correct COM port automatically.
1. C# must first find all available COM ports.
2. Send a string "s" to all available COM ports and only use the two COM ports that respond with "Elevation" and "Azimuth".
For example .... If C# sends a string "s" to COM3 and and COM3 responds with "Azimuth" then AzimuthPort.PortName = "COM3";. My problem is that I can find all available COM ports, but I can't send them a command because the same COM port cannot be accessed from multiple locations.
private void detectCOMPort()
{
detectPort = new SerialPort();
// Get a list of available COM ports
string[] ports = SerialPort.GetPortNames();
// Display each port name
foreach (string port in ports)
{
detectPort.PortName = port;
detectPort.Write("s");
String compare = detectPort.ReadExisting();
if (compare == "Elevation")
myPort.PortName = port;
if (compare == "Azimuth")
myPort2.PortName = port;
}
}
Any help would be appreciated.
Continue reading...