Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qextserialenumerator_unix.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /****************************************************************************
  2. ** Copyright (c) 2000-2003 Wayne Roth
  3. ** Copyright (c) 2004-2007 Stefan Sander
  4. ** Copyright (c) 2007 Michal Policht
  5. ** Copyright (c) 2008 Brandon Fosdick
  6. ** Copyright (c) 2009-2010 Liam Staskawicz
  7. ** Copyright (c) 2011 Debao Zhang
  8. ** All right reserved.
  9. ** Web: http://code.google.com/p/qextserialport/
  10. **
  11. ** Permission is hereby granted, free of charge, to any person obtaining
  12. ** a copy of this software and associated documentation files (the
  13. ** "Software"), to deal in the Software without restriction, including
  14. ** without limitation the rights to use, copy, modify, merge, publish,
  15. ** distribute, sublicense, and/or sell copies of the Software, and to
  16. ** permit persons to whom the Software is furnished to do so, subject to
  17. ** the following conditions:
  18. **
  19. ** The above copyright notice and this permission notice shall be
  20. ** included in all copies or substantial portions of the Software.
  21. **
  22. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. **
  30. ****************************************************************************/
  31. #include "qextserialenumerator.h"
  32. #include "qextserialenumerator_p.h"
  33. #include <QtCore/QDebug>
  34. #include <QtCore/QStringList>
  35. #include <QtCore/QDir>
  36. void QextSerialEnumeratorPrivate::platformSpecificInit()
  37. {
  38. }
  39. void QextSerialEnumeratorPrivate::platformSpecificDestruct()
  40. {
  41. }
  42. QList<QextPortInfo> QextSerialEnumeratorPrivate::getPorts_sys()
  43. {
  44. QList<QextPortInfo> infoList;
  45. #ifdef Q_OS_LINUX
  46. QStringList portNamePrefixes, portNameList;
  47. portNamePrefixes << QLatin1String("ttyS*"); // list normal serial ports first
  48. QDir dir(QLatin1String("/dev"));
  49. portNameList = dir.entryList(portNamePrefixes, (QDir::System | QDir::Files), QDir::Name);
  50. // remove the values which are not serial ports for e.g. /dev/ttysa
  51. for (int i = 0; i < portNameList.size(); i++) {
  52. bool ok;
  53. QString current = portNameList.at(i);
  54. // remove the ttyS part, and check, if the other part is a number
  55. current.remove(0,4).toInt(&ok, 10);
  56. if (!ok) {
  57. portNameList.removeAt(i);
  58. i--;
  59. }
  60. }
  61. // get the non standard serial ports names
  62. // (USB-serial, bluetooth-serial, 18F PICs, and so on)
  63. // if you know an other name prefix for serial ports please let us know
  64. portNamePrefixes.clear();
  65. portNamePrefixes << QLatin1String("ttyACM*") << QLatin1String("ttyUSB*") << QLatin1String("rfcomm*");
  66. portNameList += dir.entryList(portNamePrefixes, (QDir::System | QDir::Files), QDir::Name);
  67. foreach (QString str , portNameList) {
  68. QextPortInfo inf;
  69. inf.physName = QLatin1String("/dev/")+str;
  70. inf.portName = str;
  71. if (str.contains(QLatin1String("ttyS"))) {
  72. inf.friendName = QLatin1String("Serial port ")+str.remove(0, 4);
  73. }
  74. else if (str.contains(QLatin1String("ttyUSB"))) {
  75. inf.friendName = QLatin1String("USB-serial adapter ")+str.remove(0, 6);
  76. }
  77. else if (str.contains(QLatin1String("rfcomm"))) {
  78. inf.friendName = QLatin1String("Bluetooth-serial adapter ")+str.remove(0, 6);
  79. }
  80. inf.enumName = QLatin1String("/dev"); // is there a more helpful name for this?
  81. infoList.append(inf);
  82. }
  83. #endif
  84. return infoList;
  85. }
  86. bool QextSerialEnumeratorPrivate::setUpNotifications_sys(bool setup)
  87. {
  88. Q_UNUSED(setup)
  89. return false;
  90. }