Port
#struct PortA serial port and the line settings it was opened with.
| Name | Type | Description |
|---|---|---|
number | int = 0 | The port number. |
baud | int = 115200 | The baud rate. |
data_bits | int = 8 | The number of data bits, 8 unless changed. |
parity | int = 0 | The parity setting: PARITY_NONE, PARITY_EVEN or PARITY_ODD. The board layer keeps only the baud rate, so this field is a record for your own use. |
stop_bits | int = 1 | The number of stop bits, 1 unless changed. Like parity, a record for your own use. |
import hw.board
import hw.uart
func main:
port := uart.Open(1, 9600)
println uart.PARITY_NONE, uart.PARITY_EVEN, uart.PARITY_ODD
uart.WriteStr(port, "hi")
uart.WriteByte(port, 33)
println board.SimTaken(1), board.SimTaken(1), board.SimTaken(1)
println uart.Available(port), uart.ReadByte(port)
board.SimInject(1, 111)
board.SimInject(1, 107)
board.SimInject(1, 10)
println uart.Available(port)
println uart.ReadLine(port)
println uart.Available(port)
end0 1 2 104 105 33 false -1 true ok false