qserialport.sip 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // qserialport.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtSerialPort Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. %If (Qt_6_2_0 -)
  22. class QSerialPort : public QIODevice
  23. {
  24. %TypeHeaderCode
  25. #include <qserialport.h>
  26. %End
  27. %ConvertToSubClassCode
  28. static struct class_graph {
  29. const char *name;
  30. sipTypeDef **type;
  31. int yes, no;
  32. } graph[] = {
  33. {sipName_QSerialPort, &sipType_QSerialPort, -1, -1},
  34. };
  35. int i = 0;
  36. sipType = NULL;
  37. do
  38. {
  39. struct class_graph *cg = &graph[i];
  40. if (cg->name != NULL && sipCpp->inherits(cg->name))
  41. {
  42. sipType = *cg->type;
  43. i = cg->yes;
  44. }
  45. else
  46. i = cg->no;
  47. }
  48. while (i >= 0);
  49. %End
  50. public:
  51. enum Direction /BaseType=Flag/
  52. {
  53. Input,
  54. Output,
  55. AllDirections,
  56. };
  57. typedef QFlags<QSerialPort::Direction> Directions;
  58. enum BaudRate
  59. {
  60. Baud1200,
  61. Baud2400,
  62. Baud4800,
  63. Baud9600,
  64. Baud19200,
  65. Baud38400,
  66. Baud57600,
  67. Baud115200,
  68. };
  69. enum DataBits
  70. {
  71. Data5,
  72. Data6,
  73. Data7,
  74. Data8,
  75. };
  76. enum Parity
  77. {
  78. NoParity,
  79. EvenParity,
  80. OddParity,
  81. SpaceParity,
  82. MarkParity,
  83. };
  84. enum StopBits
  85. {
  86. OneStop,
  87. OneAndHalfStop,
  88. TwoStop,
  89. };
  90. enum FlowControl
  91. {
  92. NoFlowControl,
  93. HardwareControl,
  94. SoftwareControl,
  95. };
  96. enum PinoutSignal /BaseType=Flag/
  97. {
  98. NoSignal,
  99. DataTerminalReadySignal,
  100. DataCarrierDetectSignal,
  101. DataSetReadySignal,
  102. RingIndicatorSignal,
  103. RequestToSendSignal,
  104. ClearToSendSignal,
  105. SecondaryTransmittedDataSignal,
  106. SecondaryReceivedDataSignal,
  107. };
  108. typedef QFlags<QSerialPort::PinoutSignal> PinoutSignals;
  109. enum SerialPortError
  110. {
  111. NoError,
  112. DeviceNotFoundError,
  113. PermissionError,
  114. OpenError,
  115. WriteError,
  116. ReadError,
  117. ResourceError,
  118. UnsupportedOperationError,
  119. TimeoutError,
  120. NotOpenError,
  121. UnknownError,
  122. };
  123. explicit QSerialPort(QObject *parent /TransferThis/ = 0);
  124. QSerialPort(const QString &name, QObject *parent /TransferThis/ = 0);
  125. QSerialPort(const QSerialPortInfo &info, QObject *parent /TransferThis/ = 0);
  126. virtual ~QSerialPort();
  127. void setPortName(const QString &name);
  128. QString portName() const;
  129. void setPort(const QSerialPortInfo &info);
  130. virtual bool open(QIODeviceBase::OpenMode mode) /ReleaseGIL/;
  131. virtual void close() /ReleaseGIL/;
  132. bool setBaudRate(qint32 baudRate, QSerialPort::Directions dir = QSerialPort::AllDirections);
  133. qint32 baudRate(QSerialPort::Directions dir = QSerialPort::AllDirections) const;
  134. bool setDataBits(QSerialPort::DataBits dataBits);
  135. QSerialPort::DataBits dataBits() const;
  136. bool setParity(QSerialPort::Parity parity);
  137. QSerialPort::Parity parity() const;
  138. bool setStopBits(QSerialPort::StopBits stopBits);
  139. QSerialPort::StopBits stopBits() const;
  140. bool setFlowControl(QSerialPort::FlowControl flow);
  141. QSerialPort::FlowControl flowControl() const;
  142. bool setDataTerminalReady(bool set);
  143. bool isDataTerminalReady();
  144. bool setRequestToSend(bool set);
  145. bool isRequestToSend();
  146. QSerialPort::PinoutSignals pinoutSignals();
  147. bool flush() /ReleaseGIL/;
  148. bool clear(QSerialPort::Directions dir = QSerialPort::AllDirections);
  149. QSerialPort::SerialPortError error() const;
  150. void clearError();
  151. qint64 readBufferSize() const;
  152. void setReadBufferSize(qint64 size);
  153. virtual bool isSequential() const;
  154. virtual qint64 bytesAvailable() const;
  155. virtual qint64 bytesToWrite() const;
  156. virtual bool canReadLine() const;
  157. virtual bool waitForReadyRead(int msecs = 30000) /ReleaseGIL/;
  158. virtual bool waitForBytesWritten(int msecs = 30000) /ReleaseGIL/;
  159. bool setBreakEnabled(bool enabled = true);
  160. signals:
  161. void baudRateChanged(qint32 baudRate, QSerialPort::Directions directions);
  162. void dataBitsChanged(QSerialPort::DataBits dataBits);
  163. void parityChanged(QSerialPort::Parity parity);
  164. void stopBitsChanged(QSerialPort::StopBits stopBits);
  165. void flowControlChanged(QSerialPort::FlowControl flow);
  166. void dataTerminalReadyChanged(bool set);
  167. void requestToSendChanged(bool set);
  168. protected:
  169. virtual SIP_PYOBJECT readData(qint64 maxlen) /TypeHint="bytes",ReleaseGIL/ [qint64 (char *data, qint64 maxSize)];
  170. %MethodCode
  171. // Return the data read or None if there was an error.
  172. if (a0 < 0)
  173. {
  174. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  175. sipIsErr = 1;
  176. }
  177. else
  178. {
  179. char *s = new char[a0];
  180. qint64 len;
  181. Py_BEGIN_ALLOW_THREADS
  182. #if defined(SIP_PROTECTED_IS_PUBLIC)
  183. len = sipSelfWasArg ? sipCpp->QSerialPort::readData(s, a0) : sipCpp->readData(s, a0);
  184. #else
  185. len = sipCpp->sipProtectVirt_readData(sipSelfWasArg, s, a0);
  186. #endif
  187. Py_END_ALLOW_THREADS
  188. if (len < 0)
  189. {
  190. Py_INCREF(Py_None);
  191. sipRes = Py_None;
  192. }
  193. else
  194. {
  195. sipRes = PyBytes_FromStringAndSize(s, len);
  196. if (!sipRes)
  197. sipIsErr = 1;
  198. }
  199. delete[] s;
  200. }
  201. %End
  202. virtual SIP_PYOBJECT readLineData(qint64 maxlen) /TypeHint="bytes",ReleaseGIL/ [qint64 (char *data, qint64 maxSize)];
  203. %MethodCode
  204. // Return the data read or None if there was an error.
  205. if (a0 < 0)
  206. {
  207. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  208. sipIsErr = 1;
  209. }
  210. else
  211. {
  212. char *s = new char[a0];
  213. qint64 len;
  214. Py_BEGIN_ALLOW_THREADS
  215. #if defined(SIP_PROTECTED_IS_PUBLIC)
  216. len = sipSelfWasArg ? sipCpp->QSerialPort::readLineData(s, a0) : sipCpp->readLineData(s, a0);
  217. #else
  218. len = sipCpp->sipProtectVirt_readLineData(sipSelfWasArg, s, a0);
  219. #endif
  220. Py_END_ALLOW_THREADS
  221. if (len < 0)
  222. {
  223. Py_INCREF(Py_None);
  224. sipRes = Py_None;
  225. }
  226. else
  227. {
  228. sipRes = PyBytes_FromStringAndSize(s, len);
  229. if (!sipRes)
  230. sipIsErr = 1;
  231. }
  232. delete[] s;
  233. }
  234. %End
  235. virtual qint64 writeData(const char *data /Array/, qint64 maxSize /ArraySize/) /ReleaseGIL/;
  236. public:
  237. %If (Windows)
  238. void *handle() const;
  239. %End
  240. %If (Android || Linux || iOS || macOS || WebAssembly)
  241. int handle() const;
  242. %End
  243. bool isBreakEnabled() const;
  244. signals:
  245. void breakEnabledChanged(bool set);
  246. void errorOccurred(QSerialPort::SerialPortError error);
  247. public:
  248. %If (Qt_6_9_0 -)
  249. bool settingsRestoredOnClose() const;
  250. %End
  251. %If (Qt_6_9_0 -)
  252. void setSettingsRestoredOnClose(bool restore);
  253. %End
  254. signals:
  255. %If (Qt_6_9_0 -)
  256. void settingsRestoredOnCloseChanged(bool restore);
  257. %End
  258. public:
  259. %If (Qt_6_10_0 -)
  260. qint64 writeBufferSize() const;
  261. %End
  262. %If (Qt_6_10_0 -)
  263. void setWriteBufferSize(qint64 size);
  264. %End
  265. };
  266. %End