Serial Port stops working

I’m using very basic code similar the one given in the examples to control two servos programming in C++. Everything is working fine for a couple of seconds. Can read out the servos and can move them like I want. But suddently communication gets lost.

In such a case I’m getting an error in following code (WriteFile fails) even when input data is correct (have debugged that).

int MaestroConnector_C::WriteBytes(const QByteArray &buf)
{
    if ( ! _data->_initialized || _data->_handle == INVALID_HANDLE_VALUE ) {
        throw NotInitialized_C();
    }
    DWORD written = 0;
    if ( ! WriteFile(_data->_handle, buf.data(), buf.length(), &written, 0) ) {
        Logger.errorStream() << "Error: Unable to open serial port.  Error code " << GetLastError(); // This happens often after a few seconds working
        return -1;
    }
    return (int) written;
}

After this happened I can’t even reconnect the servos by re-initialization. I get an ERROR_FILE_NOT_FOUND error in that case in following code:

void MaestroConnector_C::Initialize(const QString &port_name)
{
    if ( _data->_initialized ) {
        throw AlreadyInitialized_C();
    }
    _data->_handle = CreateFileA(port_name.toLocal8Bit(), GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    if ( _data->_handle == INVALID_HANDLE_VALUE ) {

        switch(GetLastError())
        {
        case ERROR_ACCESS_DENIED:	
            Logger.errorStream() << "Error: Access denied.  Try closing all other programs that are using the device.";
            break;
        case ERROR_FILE_NOT_FOUND:
             Logger.errorStream() << "Error: Serial port not found. Make sure that " << port_name << "is the right port name. Try closing all programs using the device and unplugging the device, or try rebooting.";
            break;
        default:
            Logger.errorStream() << "Error: Unable to open serial port.  Error code " << GetLastError();
            break;
        }

        throw InitializationFailed_C();
    }
   ...
}

Device manager shows that given com port is still working. But I get the whole stuff only running if I reconnect the servers by disconnect/connect the USB cable. Any idea what that could be caused by?

Hello.

I am sorry you are having trouble with your Maestro. I would like to understand your system better. What type of Maestro do you have? A link to the product page would be useful. What computer model do you have and what version of Windows is it running? What is connected to the Maestro? A complete wiring diagram and some pictures of your setup would really help. When communication is lost, what are the Maestro’s red, green, and yellow LEDs doing? Does the problem happen even if you disconnect everything from the Maestro except USB? Could you save your Maestro settings file using the Maestro Control Center and post it here so I can check your settings?

–David

Hello.

Did you ever fix your problem with the Maestro? I was going to suggest trying a USB cable with a ferrite bead, but I wanted to know more about the problem first.

–David