euantorano / serial.nim

A Nim library for accessing serial ports.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

readme example has wrong buffer type in 0.18

markprocess opened this issue · comments

From README.md:

import serial # Or: `import serial/serialport`

let port = newSerialPort("COM1")
# use 9600bps, no parity, 8 data bits and 1 stop bit
port.open(9600, Parity.None, 8, StopBits.One)

# You can modify the baud rate, parity, databits, etc. after opening the port
port.baudRate = 2400

var receiveBuffer = newString(1024)
while true:
  let numReceived = port.read(receiveBuffer, len(receiveBuffer))
  port.write(receiveBuffer, numReceived)

compile using 0.18:

test2.nim(12, 25) Error: type mismatch: got <SerialPort, string, int>
but expected one of:
proc read(port: SerialPort; buff: pointer; len: int32): int32
  first type mismatch at position: 2
  required type: pointer
  but expression 'receiveBuffer' is of type: string

expression: read(port, receiveBuffer, len(receiveBuffer))

Good catch. The example should be:

import serial # Or: `import serial/serialport`

let port = newSerialPort("COM1")
# use 9600bps, no parity, 8 data bits and 1 stop bit
port.open(9600, Parity.None, 8, StopBits.One)

# You can modify the baud rate, parity, databits, etc. after opening the port
port.baudRate = 2400

var receiveBuffer = newString(1024)
while true:
  let numReceived = port.read(addr receiveBuffer[0], len(receiveBuffer))
  port.write(addr receiveBuffer[0], numReceived)