index.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. export interface IDevice {
  2. name: string;
  3. vendorId: number;
  4. productId: number;
  5. }
  6. export type Devices = Array<IDevice> | null;
  7. export interface IOnReadData {
  8. payload: string | Array<number>
  9. }
  10. export interface IOnError {
  11. status: boolean;
  12. errorCode: number;
  13. errorMessage: string;
  14. exceptionErrorMessage?: string;
  15. }
  16. export interface IOnServiceStarted {
  17. deviceAttached: boolean
  18. }
  19. interface DefinitionsStatic {
  20. DATA_BITS: {
  21. DATA_BITS_5: number
  22. DATA_BITS_6: number;
  23. DATA_BITS_7: number;
  24. DATA_BITS_8: number;
  25. };
  26. STOP_BITS: {
  27. STOP_BITS_1: number;
  28. STOP_BITS_15: number;
  29. STOP_BITS_2: number;
  30. };
  31. PARITIES: {
  32. PARITY_NONE: number;
  33. PARITY_ODD: number;
  34. PARITY_EVEN: number;
  35. PARITY_MARK: number;
  36. PARITY_SPACE: number;
  37. };
  38. FLOW_CONTROLS: {
  39. FLOW_CONTROL_OFF: number;
  40. FLOW_CONTROL_RTS_CTS: number;
  41. FLOW_CONTROL_DSR_DTR: number;
  42. FLOW_CONTROL_XON_XOFF: number;
  43. };
  44. RETURNED_DATA_TYPES: {
  45. INTARRAY: number;
  46. HEXSTRING: number;
  47. };
  48. DRIVER_TYPES: {
  49. AUTO: string,
  50. CDC: string,
  51. CH34x: string,
  52. CP210x: string,
  53. FTDI: string,
  54. PL2303: string
  55. };
  56. }
  57. export var definitions: DefinitionsStatic;
  58. interface ActionsStatic {
  59. ON_SERVICE_STARTED: string,
  60. ON_SERVICE_STOPPED: string,
  61. ON_DEVICE_ATTACHED: string,
  62. ON_DEVICE_DETACHED: string,
  63. ON_ERROR: string,
  64. ON_CONNECTED: string,
  65. ON_DISCONNECTED: string,
  66. ON_READ_DATA: string
  67. }
  68. export var actions: ActionsStatic;
  69. type DataBits = 5 | 6 | 7 | 8;
  70. type StopBits = 1 | 2 | 3;
  71. type Parities = 0 | 1 | 2 | 3 | 4;
  72. type FlowControls = 0 | 1 | 2 | 3;
  73. type ReturnedDataTypes = 1 | 2;
  74. type Drivers = "AUTO" | "cdc" | "ch34x" | "cp210x" | "ftdi" | "pl2303";
  75. interface RNSerialportStatic {
  76. /**
  77. * Starts the service and Usb listener
  78. *
  79. * @memberof RNSerialportStatic
  80. */
  81. startUsbService(): void;
  82. /**
  83. * Stops the service and Usb listener
  84. *
  85. * @memberof RNSerialportStatic
  86. */
  87. stopUsbService(): void;
  88. /**
  89. * Returns status via Promise
  90. *
  91. * @returns {Promise<boolean>}
  92. * @memberof RNSerialportStatic
  93. */
  94. isOpen(): Promise<boolean>
  95. /**
  96. * Returns status boolean via Promise
  97. *
  98. * @returns {Promise<boolean>}
  99. * @memberof RNSerialportStatic
  100. */
  101. isServiceStarted(): Promise<boolean>
  102. /**
  103. * Returns support status
  104. *
  105. * @param {string} deviceName
  106. * @returns {Promise<boolean>}
  107. * @memberof RNSerialportStatic
  108. */
  109. isSupported(deviceName: string): Promise<boolean>;
  110. //Begin setter methods
  111. /**
  112. * Set the returned data type
  113. *
  114. * @param {ReturnedDataTypes} type
  115. * @memberof RNSerialportStatic
  116. */
  117. setReturnedDataType(type: ReturnedDataTypes): void;
  118. /**
  119. * Set the interface
  120. *
  121. * @param {number} iFace
  122. * @memberof RNSerialportStatic
  123. */
  124. setInterface(iFace: number): void;
  125. /**
  126. * Set the data bit
  127. *
  128. * @param {DataBits} bit
  129. * @memberof RNSerialportStatic
  130. */
  131. setDataBit(bit: DataBits): void;
  132. /**
  133. * Set the stop bit
  134. *
  135. * @param {StopBits} bit
  136. * @memberof RNSerialportStatic
  137. */
  138. setStopBit(bit: StopBits): void;
  139. /**
  140. * Set the parity
  141. *
  142. * @param {Parities} parity
  143. * @memberof RNSerialportStatic
  144. */
  145. setParity(parity: Parities): void;
  146. /**
  147. * Set the flow control
  148. *
  149. * @param {FlowControls} control
  150. * @memberof RNSerialportStatic
  151. */
  152. setFlowControl(control: FlowControls): void;
  153. /**
  154. * Set RTS
  155. */
  156. setRTS(FLOW_CONTROL_RTS: boolean): void;
  157. /**
  158. * Set DTR
  159. */
  160. setRTS(FLOW_CONTROL_DTR: boolean): void;
  161. /**
  162. * Set the auto connection baudrate
  163. *
  164. * @param {number} baudRate
  165. * @memberof RNSerialportStatic
  166. */
  167. setAutoConnectBaudRate(baudRate: number): void;
  168. /**
  169. * Set the auto connection status
  170. *
  171. * @param {boolean} status
  172. * @memberof RNSerialportStatic
  173. */
  174. setAutoConnect(status: boolean): void;
  175. /**
  176. * Set the driver type
  177. *
  178. * @param {Drivers} driver
  179. * @memberof RNSerialportStatic
  180. */
  181. setDriver(driver: Drivers): void;
  182. //End setter methods
  183. /**
  184. * Load the default connection settings
  185. *
  186. * @memberof RNSerialportStatic
  187. */
  188. loadDefaultConnectionSetting(): void;
  189. /**
  190. * Returns the device list via Promise
  191. *
  192. * @returns {Promise<Device>}
  193. * @memberof RNSerialportStatic
  194. */
  195. getDeviceList(): Promise<Devices>;
  196. /**
  197. * Connect to device with device name and baud rate
  198. *
  199. * @param {string} deviceName
  200. * @param {number} baudRate
  201. * @memberof RNSerialportStatic
  202. */
  203. connectDevice(deviceName: string, baudRate: number): void;
  204. /**
  205. * Closes the connection
  206. *
  207. * @memberof RNSerialportStatic
  208. */
  209. disconnect(): void;
  210. /**
  211. * Writes string to port
  212. *
  213. * @param {string} data
  214. * @memberof RNSerialportStatic
  215. */
  216. writeString(data: string): void;
  217. /**
  218. * Writes Base64 string to port
  219. *
  220. * @param {string} data
  221. * @memberof RNSerialportStatic
  222. */
  223. writeBase64(data: string): void;
  224. /**
  225. * Writes hex string to port
  226. *
  227. * @param {string} data
  228. * @memberof RNSerialportStatic
  229. */
  230. writeHexString(data: string): void
  231. /**
  232. * Integer array convert to Utf16 string
  233. *
  234. * @param {Array<number>} intArray
  235. * @returns {string}
  236. * @memberof RNSerialportStatic
  237. */
  238. intArrayToUtf16(intArray: Array<number>): string
  239. /**
  240. * Hex string convert to Utf16 string
  241. *
  242. * @param {string} hex
  243. * @returns {string}
  244. * @memberof RNSerialportStatic
  245. */
  246. hexToUtf16(hex: string): string
  247. }
  248. export var RNSerialport: RNSerialportStatic;