//---------------------------------------------------------------- void ofSerial::buildDeviceList(){ deviceType = "serial"; devices.clear(); std::vector <std::string> prefixMatch; prefixMatch.push_back("ttyS"); prefixMatch.push_back("ttyUSB"); prefixMatch.push_back("rfc"); DIR *dir; struct dirent *entry; dir = opendir("/dev"); std::string deviceName = ""; int deviceCount = 0; if (dir == NULL){ std::cout << "buildDeviceList(): error listing devices in /dev" << "\r\n"; } else { //for each device while((entry = readdir(dir)) != NULL){ deviceName = (char *)entry->d_name; //we go through the prefixes for(int k = 0; k < (int)prefixMatch.size(); k++){ //if the device name is longer than the prefix if( deviceName.size() > prefixMatch[k].size() ){ //do they match ? if( deviceName.substr(0, prefixMatch[k].size()) == prefixMatch[k].c_str() ){ devices.push_back(ofSerialDeviceInfo("/dev/"+deviceName, deviceName, deviceCount)); deviceCount++; break; } } } } closedir(dir); } //here we sort the device to have the aruino ones first. partition(devices.begin(), devices.end(), isDeviceArduino); //we are reordering the device ids. too! for(int k = 0; k < (int)devices.size(); k++){ devices[k].deviceID = k; } bHaveEnumeratedDevices = true; }
//---------------------------------------------------------------- void ofSerial::buildDeviceList(){ deviceType = "serial"; devices.clear(); std::vector <std::string> prefixMatch; enumerateWin32Ports(); std::cout << "found " << nPorts << " devices" << "\r\n"; for (int i = 0; i < nPorts; i++){ //NOTE: we give the short port name for both as that is what the user should pass and the short name is more friendly devices.push_back(ofSerialDeviceInfo(std::string(portNamesShort[i]), std::string(portNamesShort[i]), i)); } //here we sort the device to have the aruino ones first. partition(devices.begin(), devices.end(), isDeviceArduino); //we are reordering the device ids. too! for(int k = 0; k < (int)devices.size(); k++){ devices[k].deviceID = k; } bHaveEnumeratedDevices = true; }
//---------------------------------------------------------------- void ofSerial::buildDeviceList(){ deviceType = "serial"; devices.clear(); std::vector <std::string> prefixMatch; #ifdef TARGET_OSX prefixMatch.push_back("cu."); prefixMatch.push_back("tty."); #endif #ifdef TARGET_LINUX prefixMatch.push_back("ttyS"); prefixMatch.push_back("ttyUSB"); prefixMatch.push_back("rfc"); #endif #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) DIR *dir; struct dirent *entry; dir = opendir("/dev"); string deviceName = ""; int deviceCount = 0; if (dir == NULL){ ofLog(OF_LOG_ERROR,"ofSerial: error listing devices in /dev"); } else { //for each device while((entry = readdir(dir)) != NULL){ deviceName = (char *)entry->d_name; //we go through the prefixes for(int k = 0; k < (int)prefixMatch.size(); k++){ //if the device name is longer than the prefix if( deviceName.size() > prefixMatch[k].size() ){ //do they match ? if( deviceName.substr(0, prefixMatch[k].size()) == prefixMatch[k].c_str() ){ devices.push_back(ofSerialDeviceInfo("/dev/"+deviceName, deviceName, deviceCount)); deviceCount++; break; } } } } closedir(dir); } #endif //--------------------------------------------- #ifdef TARGET_WIN32 //--------------------------------------------- enumerateWin32Ports(); //ofLogNotice() << "ofSerial: listing devices (" << nPorts << " total)"; for (int i = 0; i < nPorts; i++){ //NOTE: we give the short port name for both as that is what the user should pass and the short name is more friendly ofSerialDeviceInfo ifo; ifo.devicePath=portNamesShort[i]; ifo.deviceID=i; devices.push_back(ifo); } //--------------------------------------------- #endif //--------------------------------------------- //here we sort the device to have the aruino ones first. partition(devices.begin(), devices.end(), isDeviceArduino); //we are reordering the device ids. too! for(int k = 0; k < (int)devices.size(); k++){ devices[k].deviceID = k; } bHaveEnumeratedDevices = true; }
//---------------------------------------------------------------- void ofSerial::buildDeviceList(){ deviceType = "serial"; devices.clear(); vector <string> prefixMatch; #ifdef TARGET_OSX prefixMatch.push_back("cu."); prefixMatch.push_back("tty."); #endif #ifdef TARGET_LINUX #ifdef TARGET_RASPBERRY_PI prefixMatch.push_back("ttyACM"); #endif prefixMatch.push_back("ttyS"); prefixMatch.push_back("ttyUSB"); prefixMatch.push_back("rfc"); #endif #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) DIR *dir; dir = opendir("/dev"); string deviceName = ""; if(dir == nullptr){ ofLogError("ofSerial") << "buildDeviceList(): error listing devices in /dev"; } else { int deviceCount = 0; //for each device struct dirent *entry; while((entry = readdir(dir)) != nullptr){ deviceName = (char *)entry->d_name; //we go through the prefixes for(int k = 0; k < (int)prefixMatch.size(); k++){ //if the device name is longer than the prefix if(deviceName.size() > prefixMatch[k].size()){ //do they match ? if(deviceName.substr(0, prefixMatch[k].size()) == prefixMatch[k].c_str()){ devices.push_back(ofSerialDeviceInfo("/dev/"+deviceName, deviceName, deviceCount)); deviceCount++; break; } } } } closedir(dir); } #endif #ifdef TARGET_WIN32 enumerateWin32Ports(); ofLogNotice("ofSerial") << "found " << nPorts << " devices"; for(int i = 0; i < nPorts; i++){ //NOTE: we give the short port name for both as that is what the user should pass and the short name is more friendly devices.push_back(ofSerialDeviceInfo(string(portNamesShort[i]), string(portNamesShort[i]), i)); } #endif //here we sort the device to have the aruino ones first. partition(devices.begin(), devices.end(), isDeviceArduino); //we are reordering the device ids. too! for(int k = 0; k < (int)devices.size(); k++){ devices[k].deviceID = k; } bHaveEnumeratedDevices = true; }
//---------------------------------------------------------------- void ofSerial::buildDeviceList(){ deviceType = "serial"; devices.clear(); vector <string> prefixMatch; #ifdef TARGET_OSX prefixMatch.push_back("cu."); prefixMatch.push_back("tty."); #endif #ifdef TARGET_LINUX prefixMatch.push_back("ttyACM"); prefixMatch.push_back("ttyS"); prefixMatch.push_back("ttyUSB"); prefixMatch.push_back("rfc"); #endif #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) ofDirectory dir("/dev"); int deviceCount = 0; for(auto & entry: dir){ std::string deviceName = entry.path(); //we go through the prefixes for(auto & prefix: prefixMatch){ //if the device name is longer than the prefix if(deviceName.size() > prefix.size()){ //do they match ? if(deviceName.substr(0, prefix.size()) == prefix.c_str()){ devices.push_back(ofSerialDeviceInfo("/dev/"+deviceName, deviceName, deviceCount)); deviceCount++; break; } } } } #endif #ifdef TARGET_WIN32 enumerateWin32Ports(); ofLogNotice("ofSerial") << "found " << nPorts << " devices"; for(int i = 0; i < nPorts; i++){ //NOTE: we give the short port name for both as that is what the user should pass and the short name is more friendly devices.push_back(ofSerialDeviceInfo(string(portNamesShort[i]), string(portNamesShort[i]), i)); } #endif #if defined( TARGET_OSX ) //here we sort the device to have the aruino ones first. partition(devices.begin(), devices.end(), isDeviceArduino); //we are reordering the device ids. too! int k = 0; for(auto & device: devices){ device.deviceID = k++; } #endif bHaveEnumeratedDevices = true; }