1

Resolved

v1033 - Mayhem crash - MSP430 & Arduino

description

If you have a task set up with MSP or Arduino, with everything plugged in and turned on and working, then unplug the device from the computer and attempt to trigger the task again, Mayhem crashes, giving the following error in the IDE:

IOException was Unhandled
The port COM(whatever) does not exist.

public void Write(string portName, byte[] buffer, int length)
    {
        lock (locker)
        {
            if (!ports.ContainsKey(portName))
            {
                throw new ArgumentException("The given port is not open", "portName");
            }

            SerialPort port = ports[portName];

            // We have to verify that the port is open here if we try to write
            if (!port.IsOpen)
            {
                // This is needed to attempt to reattach if they unplug, then replug in
                // the com port.
                try
                {
                    port.Open();
                }
                catch
                {
                    // This will throw if they unplug the cable, then try to trigger.
                }
            }

            if (port.IsOpen)
            {
                port.Write(buffer, 0, length); //////THIS IS THE LINE THE ERROR POINTS AT
            }
            Thread.Sleep(110);
        }
    }

comments

garr1985 wrote Dec 4, 2012 at 12:18 AM

Resolved. Added a try/catch in the write() method of the serial manager and errorlog output for the user. Added a try/catch in the remove() method of the serial manager as well so that the port is removed correctly when disabling/enabling the event/reaction after the device is plugged back in.

garr1985 wrote Dec 11, 2012 at 1:56 AM

Added uniform try/catch error messages across all methods (write to port, close port, open port) will help in situations when: 1) trigger occurs when event/reaction is enabled and device becomes unplugged or unavailable, 2) user tries to disable recipe when device has been unplugged, and 3) enable recipe when the device is unavailable and port unplugged.