Go Down

Topic: [ error ] ofSerial: setup(): unable to open COM# (Read 873 times) previous topic - next topic

SoulRyder

Hi,

So I am programming an application (In openFrameworks, C++), where you can connect an arduino. You can type the COM port in an input box and it will create a class that manages the arduino connected to it, which has his own instance of the ofSerial class that connects the arduino.

All is working perfectly. When connecting the arduino by typing the COM port and pressing enter, it will all work fine the first time.

Strangely, if you retype the COM port in the input box, it will create an error, not being able to connect to the Arduino. Which is strange because the Arduino is still connected according to serial->enumerateDevices(); Every time you type the new com port, it will delete the old instance and create a new instance of the ArduinoController class I made, and a delete and add a new instance of the serial class.

Restarting my application is the only option. But I don't understand what the difference is in starting the application again.

Because every time I create a whole new instance of my class, of the ofSerial class, the arduino is still connected, and it is still shown in the serial->enumerateDevices();

Here is a part of my code that tries to connect to the arduino:

void erArduinoController::setup(string DevicePort, int baud, erGuiDeviceNode* devNode){
   cout << this << endl;
   deviceNode = devNode;
   if (serial != nullptr) {
      delete serial;
   }
   serial = new ofSerial();
   bSendSerialMessage = false;
   cout << serial << endl;
   serial->enumerateDevices();
   serial->setup(DevicePort, baud);
}


And the corresponding console output:

05BD0490
05BAE588
[notice ] ofSerial: found 3 devices
[notice ] ofSerial: [ 0 ] = COM1
[notice ] ofSerial: [1] = COM15
[notice ] ofSerial: [2] = COM17
05BD0400
05BADFB0
[notice ] ofSerial: found 3 devices
[notice ] ofSerial: [ 0 ] = COM1
[notice ] ofSerial: [1] = COM15
[notice ] ofSerial: [2] = COM17
[ error ] ofSerial: setup(): unable to open COM15



Anyone that has an idea why this is happening?

PaulS

Quote
Every time you type the new com port, it will delete the old instance and create a new instance of the ArduinoController class I made, and a delete and add a new instance of the serial class.
I absolutely HATE anonymous printing. How much more difficult is it to use
Code: [Select]
cout << "Serial: " << serial << endl;
instead? There is NO excuse for guess what a value on the output device means.

Closing the serial port before you banish it is a  good idea. We have no idea what your constructor or destructor look like.
The art of getting good answers lies in asking good questions.

SoulRyder

Closing the serial port before you banish it is a  good idea. We have no idea what your constructor or destructor look like.
Closing the port (serial->close()) before creating a new instance works, thanks!

Go Up