index.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 the auto connection baudrate
  155. *
  156. * @param {number} baudRate
  157. * @memberof RNSerialportStatic
  158. */
  159. setAutoConnectBaudRate(baudRate: number): void;
  160. /**
  161. * Set the auto connection status
  162. *
  163. * @param {boolean} status
  164. * @memberof RNSerialportStatic
  165. */
  166. setAutoConnect(status: boolean): void;
  167. /**
  168. * Set the driver type
  169. *
  170. * @param {Drivers} driver
  171. * @memberof RNSerialportStatic
  172. */
  173. setDriver(driver: Drivers): void;
  174. //End setter methods
  175. /**
  176. * Load the default connection settings
  177. *
  178. * @memberof RNSerialportStatic
  179. */
  180. loadDefaultConnectionSetting(): void;
  181. /**
  182. * Returns the device list via Promise
  183. *
  184. * @returns {Promise<Device>}
  185. * @memberof RNSerialportStatic
  186. */
  187. getDeviceList(): Promise<Devices>;
  188. /**
  189. * Connect to device with device name and baud rate
  190. *
  191. * @param {string} deviceName
  192. * @param {number} baudRate
  193. * @memberof RNSerialportStatic
  194. */
  195. connectDevice(deviceName: string, baudRate: number): void;
  196. /**
  197. * Closes the connection
  198. *
  199. * @memberof RNSerialportStatic
  200. */
  201. disconnect(): void;
  202. /**
  203. * Writes string to port
  204. *
  205. * @param {string} data
  206. * @memberof RNSerialportStatic
  207. */
  208. writeString(data: string): void;
  209. /**
  210. * Writes Base64 string to port
  211. *
  212. * @param {string} data
  213. * @memberof RNSerialportStatic
  214. */
  215. writeBase64(data: string): void;
  216. /**
  217. * Writes hex string to port
  218. *
  219. * @param {string} data
  220. * @memberof RNSerialportStatic
  221. */
  222. writeHexString(data: string): void
  223. /**
  224. * Integer array convert to Utf16 string
  225. *
  226. * @param {Array<number>} intArray
  227. * @returns {string}
  228. * @memberof RNSerialportStatic
  229. */
  230. intArrayToUtf16(intArray: Array<number>): string
  231. /**
  232. * Hex string convert to Utf16 string
  233. *
  234. * @param {string} hex
  235. * @returns {string}
  236. * @memberof RNSerialportStatic
  237. */
  238. hexToUtf16(hex: string): string
  239. }
  240. export var RNSerialport: RNSerialportStatic;