Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Multiple serial devices with ofxSerial and ofxIO

$
0
0

@lumooo wrote:

Hey there,

I'm trying to get multiple arduino's working with my application.
Is this possible with the add-ons I'm using?

The code I was using for connecting 1 arduino was just the example code.
My thoughts were just duplicating the device setup like this:

ofx::IO::SerialDevice device;
ofx::IO::SerialDevice device2;

However, this doesn't work like this. I can't really find anything about multiple connection in the examples on github. When i try calling this twice, like above, the application starts throwing exceptions.

The code i use for setting up the ports is as following:

oid communication::setup(){

    std::vector<ofx::IO::SerialDeviceInfo> devicesInfo = ofx::IO::SerialDeviceUtils::listDevices();

    ofLogNotice("ofApp::setup") << "Connected Devices: ";

    for (std::size_t i = 0; i < devicesInfo.size(); ++i)
    {
        ofLogNotice("ofApp::setup") << "\t" << devicesInfo[i];
    }

    if (!devicesInfo.empty())
    {
         // Connect to the first matching device.
        bool success = device.setup(devicesInfo[0], 9600);

        if(success)
        {
            ofLogNotice("ofApp::setup") << "Successfully setup " << devicesInfo[0];
        }
        else
        {
            ofLogNotice("ofApp::setup") << "Unable to setup " << devicesInfo[0];
        }
    }
    else
    {
         ofLogNotice("ofApp::setup") << "No devices connected.";
    }
}

Thanks a lot!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles