Results 1 to 2 of 2

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

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2015
    Posts
    37
    Rep Power
    45

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

    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);
                }
            }

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2015
    Posts
    37
    Rep Power
    45
    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.

Similar Threads

  1. Question Open Multiple instances
    By carlin in forum VS.NET General Discussion
    Replies: 0
    Last Post: 05-10-2016, 7:53 AM
  2. open a .dll
    By morgana in forum C# General Discussion
    Replies: 1
    Last Post: 07-05-2015, 7:52 PM
  3. Conditionally open a file for output
    By phudgens in forum C# General Discussion
    Replies: 4
    Last Post: 07-08-2014, 5:37 PM
  4. How to re-open a form after closing?
    By DoJa in forum Windows Forms
    Replies: 2
    Last Post: 05-09-2014, 10:12 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •