Skip to content

Ref #46 - altered flush() for posx to use tcdrain rather than tcflush #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/serial/private/serialport/serialport_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ type
Two = 2,
OnePointFive = 3

InvalidSerialPortError* = object of Exception
InvalidSerialPortError* = object of ValueError

TimeoutError* = object of IOError

InvalidSerialPortStateError* = object of IOError

InvalidBaudRateError* = object of Exception
InvalidBaudRateError* = object of ValueError

InvalidDataBitsError* = object of Exception
InvalidDataBitsError* = object of ValueError

InvalidStopBitsError* = object of Exception
InvalidStopBitsError* = object of ValueError

ReceivedError* {.pure.} = enum
## Types of error detected by the operating system whilst reading from/writing to a serial port.
Expand Down
16 changes: 10 additions & 6 deletions src/serial/private/serialport/serialport_posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ proc initPort(port: SerialPort | AsyncSerialPort, tempHandle: cint, baudRate: in
setSpeed(addr settings, baudRate)

settings.c_cflag = settings.c_cflag or (CLOCAL or CREAD)
settings.c_lflag = settings.c_lflag and (not (ICANON or ECHO or ECHOE or ISIG))
settings.c_oflag = settings.c_oflag and (not OPOST)
settings.c_iflag = settings.c_iflag and (not (INLCR or IGNCR or ICRNL))
settings.c_lflag = settings.c_lflag and (not (ICANON or ECHO or ECHOE or ECHOK or ECHONL or ISIG or IEXTEN))
settings.c_oflag = settings.c_oflag and (not (OPOST or ONLCR or OCRNL))
settings.c_iflag = settings.c_iflag and (not (INLCR or IGNCR or ICRNL or IGNBRK or PARMRK))

setParity(settings, parity)
setDataBits(settings, dataBits)
Expand Down Expand Up @@ -637,7 +637,9 @@ proc open*(port: SerialPort, baudRate: int32, parity: Parity, dataBits: byte, st
if port.isOpen():
raise newException(InvalidSerialPortStateError, "Serial port is already open.")

let tempHandle = posix.open(port.name, O_RDWR or O_NOCTTY or O_NONBLOCK)
let portName = cstring(port.name)

let tempHandle = posix.open(portName, O_RDWR or O_NOCTTY or O_NONBLOCK)
if tempHandle == -1:
raiseOSError(osLastError())

Expand All @@ -655,7 +657,9 @@ proc open*(port: AsyncSerialPort, baudRate: int32, parity: Parity, dataBits: byt
if port.isOpen():
raise newException(InvalidSerialPortStateError, "Serial port is already open.")

let tempHandle = posix.open(port.name, O_RDWR or O_NOCTTY)
let portName = cstring(port.name)

let tempHandle = posix.open(portName, O_RDWR or O_NOCTTY)
if tempHandle == -1:
raiseOSError(osLastError())

Expand Down Expand Up @@ -834,7 +838,7 @@ proc flush*(port: SerialPort | AsyncSerialPort) =
if not port.isOpen():
raise newException(InvalidSerialPortStateError, "Port must be open in order to be flushed")

if tcflush(cint(port.handle), TCIOFLUSH) == -1:
if tcdrain(cint(port.handle)) == -1:
raiseOSError(osLastError())

proc close*(port: SerialPort | AsyncSerialPort) =
Expand Down