How to get list of serial devices to a string array

Hello .
I’m a beginner in oFx . So not experienced in c++
Recently I was trying to use serial and I made it working with my Arduino

Now I want to make it pretty and hence using SimpleGUITOO addon to dynamically select the serial device from the list.

The method for simpleGUIToo dropdown select panel is it takes a string array to make the list.

Now by using

vector <ofSerialDeviceInfo> deviceList = serial.getDeviceList();

I get a vector but a vector of what datatype?

is not a datatype but a function.

So I was thinking of converting the vector to string by ::

vector <ofSerialDeviceInfo> deviceList = serial.getDeviceList();
ofSerialDeviceInfo *deviceArray = &deviceList[0];

Now this doesn’t return me a array of device lists for sure …

Also may be how can I use


to make a array of strings and each string is a serial Device[either id, or device name or device path --> anything works when it comes to open a serial port - right?] from the list.

Help a beginner earn your karma > :slightly_smiling:

Thanks in advance

ofSerialDeviceInfo has to be a datatype, otherwise it would not be possible to put it in a vector. Which IDE are you using? with xcode or qtcreator you can simply put a debugger and inspect vector <ofSerialDeviceInfo>.

I’m using X_code…
What’s the println(); equivalent for oFx in xCode


vector <ofSerialDeviceInfo> deviceList = serial.getDeviceList();
auto last = deviceList.back()

Put a breakpoint as explained here and see what’s the content of last.

To put a breakpoint, click on the line number after the snippet that I’ve posted. If the debug is on (as explained in the link), when you press the play button the program should stop at the desired point.

PS, if you are not familiar with xcode, I would suggest you to read all that page.

Thanks I’ll take a look

Okay some c++ learning happened over time :: For other who might face similar problems

So code snippet is basically commented for you to understand

vector <ofSerialDeviceInfo> deviceList = serial.getDeviceList();
//this was a vector from oFx by default to enumerate serial devices 
//with device infos in them <> 

//Now create a vector list to store the names of the serial devices
//Why not string array? as it is not dynamic and you need to predefine the size for memory allocation.
vector<string> deviceNames;

//going through all the devices from the devicelist vector
//and putting them in the deviceNames vector list
for (int i = 0; i < deviceList.size(); i++){
     // pushing back for proper memory allocation and avoiding garbage

// use the generated string array to be used in the GUI drop down element
// as the  gui.addComboBox class has two signatures one which takes string array with size defined
// and other that also takes vector list .. Yipeee .. So decided up there to use vector list and ditched the whole string array conversion problem
gui.addComboBox("serialDevices", serialDevices, deviceNames);
1 Like