Merge pull request #159 from AndreRenaud/feature/drain-support
Feature/drain support
This commit is contained in:
@@ -26,6 +26,9 @@ type Port interface {
|
|||||||
// Returns the number of bytes written.
|
// Returns the number of bytes written.
|
||||||
Write(p []byte) (n int, err error)
|
Write(p []byte) (n int, err error)
|
||||||
|
|
||||||
|
// Wait until all data in the buffer are sent
|
||||||
|
Drain() error
|
||||||
|
|
||||||
// ResetInputBuffer Purges port read buffer
|
// ResetInputBuffer Purges port read buffer
|
||||||
ResetInputBuffer() error
|
ResetInputBuffer() error
|
||||||
|
|
||||||
|
|||||||
9
serial_bsd.go
Normal file
9
serial_bsd.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
|
||||||
|
|
||||||
|
package serial
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
func (port *unixPort) Drain() error {
|
||||||
|
return unix.IoctlSetInt(port.handle, unix.TIOCDRAIN, 0)
|
||||||
|
}
|
||||||
@@ -85,3 +85,10 @@ func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) {
|
|||||||
settings.Ospeed = toTermiosSpeedType(baudrate)
|
settings.Ospeed = toTermiosSpeedType(baudrate)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (port *unixPort) Drain() error {
|
||||||
|
// It's not super well documented, but this is the same as calling tcdrain:
|
||||||
|
// - https://git.musl-libc.org/cgit/musl/tree/src/termios/tcdrain.c
|
||||||
|
// - https://elixir.bootlin.com/linux/v6.2.8/source/drivers/tty/tty_io.c#L2673
|
||||||
|
return unix.IoctlSetInt(port.handle, unix.TCSBRK, 1)
|
||||||
|
}
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ func (port *windowsPort) Write(p []byte) (int, error) {
|
|||||||
return int(writed), err
|
return int(writed), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (port *windowsPort) Drain() (err error) {
|
||||||
|
return syscall.FlushFileBuffers(port.handle)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
purgeRxAbort uint32 = 0x0002
|
purgeRxAbort uint32 = 0x0002
|
||||||
purgeRxClear = 0x0008
|
purgeRxClear = 0x0008
|
||||||
|
|||||||
Reference in New Issue
Block a user