common.bmx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. ' Copyright (c) 2013-2024 Bruce A Henderson
  2. '
  3. ' Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ' of this software and associated documentation files (the "Software"), to deal
  5. ' in the Software without restriction, including without limitation the rights
  6. ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. ' copies of the Software, and to permit persons to whom the Software is
  8. ' furnished to do so, subject to the following conditions:
  9. '
  10. ' The above copyright notice and this permission notice shall be included in
  11. ' all copies or substantial portions of the Software.
  12. '
  13. ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. ' THE SOFTWARE.
  20. '
  21. SuperStrict
  22. Import BRL.LinkedList
  23. ?win32
  24. Import Text.Regex
  25. ?linux
  26. Import BRL.FileSystem
  27. ?
  28. ?macos
  29. Import "-framework IOKit"
  30. ?win32
  31. Import "-lsetupapi"
  32. ?linux
  33. Import "-lrt"
  34. ?
  35. Import "source.bmx"
  36. Extern
  37. Function bmx_serial_create_nt:Byte Ptr(port:String, baudrate:Int, bytesize:EByteSize, parity:EParityType, stopbits:EStopBits, flowcontrol:EFlowControl, drtcontrol:EDTRControl)
  38. Function bmx_serial_open(handle:Byte Ptr)
  39. Function bmx_serial_close(handle:Byte Ptr)
  40. Function bmx_serial_isopen:Int(handle:Byte Ptr)
  41. Function bmx_serial_available:Int(handle:Byte Ptr)
  42. Function bmx_serial_read:Int(handle:Byte Ptr, buffer:Byte Ptr, size:Int)
  43. Function bmx_serial_readline:String(handle:Byte Ptr, size:Int, eol:String)
  44. Function bmx_serial_write:Int(handle:Byte Ptr, data:Byte Ptr, size:Int)
  45. Function bmx_serial_writestring:Int(handle:Byte Ptr, data:String)
  46. Function bmx_serial_setport(handle:Byte Ptr, port:String)
  47. Function bmx_serial_getport:String(handle:Byte Ptr)
  48. Function bmx_serial_setbaudrate(handle:Byte Ptr, baudrate:Int)
  49. Function bmx_serial_getbaudrate:Int(handle:Byte Ptr)
  50. Function bmx_serial_setbytesize(handle:Byte Ptr, bytesize:EByteSize)
  51. Function bmx_serial_getbytesize:EByteSize(handle:Byte Ptr)
  52. Function bmx_serial_setparity(handle:Byte Ptr, parity:EParityType)
  53. Function bmx_serial_getparity:EParityType(handle:Byte Ptr)
  54. Function bmx_serial_setstopbits(handle:Byte Ptr, stopbits:EStopBits)
  55. Function bmx_serial_getstopbits:EStopBits(handle:Byte Ptr)
  56. Function bmx_serial_setflowcontrol(handle:Byte Ptr, flowcontrol:EFlowControl)
  57. Function bmx_serial_getflowcontrol:EFlowControl(handle:Byte Ptr)
  58. Function bmx_serial_flush(handle:Byte Ptr)
  59. Function bmx_serial_flushinput(handle:Byte Ptr)
  60. Function bmx_serial_flushoutput(handle:Byte Ptr)
  61. Function bmx_serial_sendbreak(handle:Byte Ptr, duration:Int)
  62. Function bmx_serial_setbreak(handle:Byte Ptr, level:Int)
  63. Function bmx_serial_setrts(handle:Byte Ptr, level:Int)
  64. Function bmx_serial_setdtr(handle:Byte Ptr, dtrcontrol:EDTRControl)
  65. Function bmx_serial_waitforchange(handle:Byte Ptr)
  66. Function bmx_serial_getcts:Int(handle:Byte Ptr)
  67. Function bmx_serial_getdsr:Int(handle:Byte Ptr)
  68. Function bmx_serial_getri:Int(handle:Byte Ptr)
  69. Function bmx_serial_getcd:Int(handle:Byte Ptr)
  70. Function bmx_serial_timeout_max:UInt()
  71. Function bmx_serial_timeout_settimeout(handle:Byte Ptr, interByteTimeout:UInt, readTimeoutConstant:UInt, readTimeoutMultiplier:UInt, writeTimeoutConstant:UInt, ..
  72. writeTimeoutMultiplier:UInt)
  73. End Extern
  74. Rem
  75. bbdoc: Possible bytesizes for the serial port.
  76. End Rem
  77. Enum EByteSize
  78. FiveBits = 5
  79. SixBits = 6
  80. SevenBits = 7
  81. EightBits = 8
  82. End Enum
  83. Rem
  84. bbdoc: Possible flow control methods for the serial port.
  85. End Rem
  86. Enum EFlowControl
  87. Rem
  88. bbdoc: Specifies that no flow control is used in the serial communication.
  89. about: When using `None`, data transmission and reception happen without any checks or
  90. controls to manage the flow. This might be suitable for systems that can guarantee data won't be lost if sent continuously.
  91. End Rem
  92. None = 0
  93. Rem
  94. bbdoc: Specifies the use of software-based flow control in the serial communication.
  95. about: With `Software`, special control characters are sent and recognized to pause and
  96. resume data transmission. Common software-based flow control methods include XON/XOFF.
  97. End Rem
  98. Software = 1
  99. Rem
  100. bbdoc: Specifies the use of hardware-based flow control in the serial communication.
  101. about: When using `Hardware`, dedicated signal lines (like RTS/CTS or DTR/DSR) in the
  102. communication interface are employed to control the data flow. This method can offer faster response times compared to software-based flow control.
  103. End Rem
  104. Hardware = 2
  105. End Enum
  106. Rem
  107. bbdoc: Serial port parity types.
  108. End Rem
  109. Enum EParityType
  110. Rem
  111. bbdoc: No parity check occurs.
  112. End Rem
  113. None = 0
  114. Rem
  115. bbdoc: Parity is enabled, with odd parity.
  116. End Rem
  117. Odd = 1
  118. Rem
  119. bbdoc: Parity is enabled, with even parity.
  120. End Rem
  121. Even = 2
  122. Rem
  123. bbdoc: Parity is enabled, and the parity bit is always set to 1.
  124. about: In serial communication, "mark" typically represents a binary "1".
  125. When using `PARITY_MARK`, the parity bit is set to the "mark" state, ensuring that every transmitted data
  126. frame has a parity bit set to 1. This can be useful for specific communication protocols or to detect transmission
  127. errors under certain conditions.
  128. End Rem
  129. Mark = 3
  130. Rem
  131. bbdoc: Parity is enabled, and the parity bit is always set to 0.
  132. about: In serial communication, "space" typically represents a binary "0".
  133. When using `Space`, the parity bit is set to the "space" state, ensuring that every transmitted data frame
  134. has a parity bit set to 0. This can be useful for specific communication protocols or to detect transmission
  135. errors under certain conditions.
  136. End Rem
  137. Space = 4
  138. End Enum
  139. Rem
  140. bbdoc: Possible stop bit configurations for the serial port.
  141. End Rem
  142. Enum EStopBits
  143. Rem
  144. bbdoc: Specifies that one stop bit is used in the serial communication frame.
  145. about: Stop bits are used in serial communication to indicate the end of a byte or character and to provide a gap
  146. before the next byte is transmitted. This constant defines a frame with a single stop bit.
  147. End Rem
  148. One = 1
  149. Rem
  150. bbdoc: Specifies that two stop bits are used in the serial communication frame.
  151. about: In some communication protocols, especially where slow devices are involved, two stop bits might be used to
  152. allow for a longer gap between bytes, ensuring data integrity.
  153. End Rem
  154. Two = 2
  155. Rem
  156. bbdoc: Specifies that one and a half stop bits are used in the serial communication frame.
  157. about: One and a half stop bits are typically used with certain parity settings and character lengths. This setting is
  158. less common but can be required by some legacy systems or specific communication standards.
  159. End Rem
  160. OnePointFive = 3
  161. End Enum
  162. Rem
  163. bbdoc: Possible DTR control configurations for the serial port.
  164. about: DTR stands for "Data Terminal Ready". It is a control signal used in serial communication that allows the
  165. computer to signal to the serial device that the computer is ready to send or receive data. This enum defines the
  166. possible DTR control configurations.
  167. End Rem
  168. Enum EDTRControl
  169. Rem
  170. bbdoc: DTR control disabled.
  171. End Rem
  172. Disable = 0
  173. Rem
  174. bbdoc: DTR control enabled.
  175. End Rem
  176. Enable = 1
  177. Rem
  178. bbdoc: DTR control enabled until the first byte is sent.
  179. End Rem
  180. Handshake = 2
  181. End Enum