index.d.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. FLOW_CONTROL_RTS:{
  57. FLOW_CONTROL_RTS_TRUE: boolean,
  58. FLOW_CONTROL_RTS_FALSE: boolean,
  59. };
  60. FLOW_CONTROL_DTR:{
  61. FLOW_CONTROL_DTR_TRUE: boolean,
  62. FLOW_CONTROL_DTR_FALSE: boolean,
  63. };
  64. }
  65. export var definitions: DefinitionsStatic;
  66. interface ActionsStatic {
  67. ON_SERVICE_STARTED: string,
  68. ON_SERVICE_STOPPED: string,
  69. ON_DEVICE_ATTACHED: string,
  70. ON_DEVICE_DETACHED: string,
  71. ON_ERROR: string,
  72. ON_CONNECTED: string,
  73. ON_DISCONNECTED: string,
  74. ON_READ_DATA: string
  75. }
  76. export var actions: ActionsStatic;
  77. type DataBits = 5 | 6 | 7 | 8;
  78. type StopBits = 1 | 2 | 3;
  79. type Parities = 0 | 1 | 2 | 3 | 4;
  80. type FlowControls = 0 | 1 | 2 | 3;
  81. type ReturnedDataTypes = 1 | 2;
  82. type Drivers = "AUTO" | "cdc" | "ch34x" | "cp210x" | "ftdi" | "pl2303";
  83. type FlowControlsRTS = 0 | 1;
  84. type FlowControlsDTR = 0 | 1;
  85. interface RNSerialportStatic {
  86. /**
  87. * Starts the service and Usb listener
  88. *
  89. * @memberof RNSerialportStatic
  90. */
  91. startUsbService(): void;
  92. /**
  93. * Stops the service and Usb listener
  94. *
  95. * @memberof RNSerialportStatic
  96. */
  97. stopUsbService(): void;
  98. /**
  99. * Returns status via Promise
  100. *
  101. * @returns {Promise<boolean>}
  102. * @memberof RNSerialportStatic
  103. */
  104. isOpen(): Promise<boolean>
  105. /**
  106. * Returns status boolean via Promise
  107. *
  108. * @returns {Promise<boolean>}
  109. * @memberof RNSerialportStatic
  110. */
  111. isServiceStarted(): Promise<boolean>
  112. /**
  113. * Returns support status
  114. *
  115. * @param {string} deviceName
  116. * @returns {Promise<boolean>}
  117. * @memberof RNSerialportStatic
  118. */
  119. isSupported(deviceName: string): Promise<boolean>;
  120. //Begin setter methods
  121. /**
  122. * Set the returned data type
  123. *
  124. * @param {ReturnedDataTypes} type
  125. * @memberof RNSerialportStatic
  126. */
  127. setReturnedDataType(type: ReturnedDataTypes): void;
  128. /**
  129. * Set the interface
  130. *
  131. * @param {number} iFace
  132. * @memberof RNSerialportStatic
  133. */
  134. setInterface(iFace: number): void;
  135. /**
  136. * Set the data bit
  137. *
  138. * @param {DataBits} bit
  139. * @memberof RNSerialportStatic
  140. */
  141. setDataBit(bit: DataBits): void;
  142. /**
  143. * Set the stop bit
  144. *
  145. * @param {StopBits} bit
  146. * @memberof RNSerialportStatic
  147. */
  148. setStopBit(bit: StopBits): void;
  149. /**
  150. * Set the parity
  151. *
  152. * @param {Parities} parity
  153. * @memberof RNSerialportStatic
  154. */
  155. setParity(parity: Parities): void;
  156. /**
  157. * Set the flow control
  158. *
  159. * @param {FlowControls} control
  160. * @memberof RNSerialportStatic
  161. */
  162. setFlowControl(control: FlowControls): void;
  163. /**
  164. * Set RTS
  165. */
  166. setRTS(controlRTS: FlowControlsRTS): void;
  167. /**
  168. * Set DTR
  169. */
  170. setDTR(controlDTR: FlowControlsDTR): void;
  171. /**
  172. * Set the auto connection baudrate
  173. *
  174. * @param {number} baudRate
  175. * @memberof RNSerialportStatic
  176. */
  177. setAutoConnectBaudRate(baudRate: number): void;
  178. /**
  179. * Set the auto connection status
  180. *
  181. * @param {boolean} status
  182. * @memberof RNSerialportStatic
  183. */
  184. setAutoConnect(status: boolean): void;
  185. /**
  186. * Set the driver type
  187. *
  188. * @param {Drivers} driver
  189. * @memberof RNSerialportStatic
  190. */
  191. setDriver(driver: Drivers): void;
  192. //End setter methods
  193. /**
  194. * Load the default connection settings
  195. *
  196. * @memberof RNSerialportStatic
  197. */
  198. loadDefaultConnectionSetting(): void;
  199. /**
  200. * Returns the device list via Promise
  201. *
  202. * @returns {Promise<Device>}
  203. * @memberof RNSerialportStatic
  204. */
  205. getDeviceList(): Promise<Devices>;
  206. /**
  207. * Connect to device with device name and baud rate
  208. *
  209. * @param {string} deviceName
  210. * @param {number} baudRate
  211. * @memberof RNSerialportStatic
  212. */
  213. connectDevice(deviceName: string, baudRate: number): void;
  214. /**
  215. * Closes the connection
  216. *
  217. * @memberof RNSerialportStatic
  218. */
  219. disconnect(): void;
  220. /**
  221. * Writes bytes to port
  222. *
  223. * @param {ArrayBuffer} data
  224. * @memberof RNSerialportStatic
  225. */
  226. write(data: ArrayBuffer ): void;
  227. /**
  228. * Writes string to port
  229. *
  230. * @param {string} data
  231. * @memberof RNSerialportStatic
  232. */
  233. writeString(data: string): void;
  234. /**
  235. * Writes Base64 string to port
  236. *
  237. * @param {string} data
  238. * @memberof RNSerialportStatic
  239. */
  240. writeBase64(data: string): void;
  241. /**
  242. * Writes hex string to port
  243. *
  244. * @param {string} data
  245. * @memberof RNSerialportStatic
  246. */
  247. writeHexString(data: string): void
  248. /**
  249. * Integer array convert to Utf16 string
  250. *
  251. * @param {Array<number>} intArray
  252. * @returns {string}
  253. * @memberof RNSerialportStatic
  254. */
  255. intArrayToUtf16(intArray: Array<number>): string
  256. /**
  257. * Hex string convert to Utf16 string
  258. *
  259. * @param {string} hex
  260. * @returns {string}
  261. * @memberof RNSerialportStatic
  262. */
  263. hexToUtf16(hex: string): string
  264. }
  265. export var RNSerialport: RNSerialportStatic;