Can Serial.Open() report open yet delay the actual opening?

Rhodan

Active member
Joined
Apr 7, 2015
Messages
41
Programming Experience
10+
I've got a strange problem on one PC. My application uses the code below to open the port. For some reason the program doesn't report any problems but my writes report the port not open several times then I see a port open message just before the application locks up. It's fine on my production machine. Both are Windows 10. Or maybe I'm missing something basic and the code just keeps going after failing to open the port?

Here's the Open() code
Code:
                try
                {
                    ArduinoPort.Open();
                    AddTextToTerminal("## " + comPort + "@" + baudRate + " opened."); // Display in status textbox
                }
                catch (Exception ex)
                {
                    if (ex is UnauthorizedAccessException)
                    {
                        MessageBox.Show("Can't open " + comPort + " is it in use?",
                            ex.GetType().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (ex is IOException)
                    {
                        MessageBox.Show("Can't open " + comPort + "\nPort name or settings invalid.", ex.GetType().FullName,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Can't open " + comPort, ex.GetType().FullName,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return;
                }
And the sending code

Code:
           if (ArduinoPort.IsOpen)
            {
                try
                {
                    if (value.Length > 0) command += " " + value;
                    command = "%" + command; // All commands from configurator have this first for extra feedback ASCOM can't handle.
                    ArduinoPort.WriteLine(command);
                }
                catch (Exception ex)
                {
                    if (ex is InvalidOperationException)
                    {
                        MessageBox.Show(ArduinoPort.PortName + " not open. is it in use?",
                            ex.GetType().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (ex is ArgumentNullException)
                    {
                        MessageBox.Show("Attempt to send null value", ex.GetType().FullName,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ArduinoPort.PortName + " error.", ex.GetType().FullName,
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
            }
            else
            {
                AddTextToTerminal("Serial port not open. (" + command + ")");
                Disconnect();
                MessageBox.Show(ArduinoPort.PortName + " unexpectedly closed?",
                            "Serial Port Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 

Rhodan

Active member
Joined
Apr 7, 2015
Messages
41
Programming Experience
10+
Actually I just had a thought, I don't actually know how fast the other computer is, maybe I'm just packing up the buffers at 500ms per update request and it can't deal. Going to try something slower.
 
Top Bottom