From 1bf551e0252c0dee88785679d45170060b19a602 Mon Sep 17 00:00:00 2001 From: Jack Doan Date: Fri, 30 Sep 2022 13:22:52 -0500 Subject: [PATCH] Fix ResetInputBuffer and ResetOutputBuffer on Darwin --- serial_darwin.go | 8 ++++++++ serial_resetbuf_linux_bsd.go | 19 +++++++++++++++++++ serial_unix.go | 8 -------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 serial_resetbuf_linux_bsd.go diff --git a/serial_darwin.go b/serial_darwin.go index ea1b99f..f30dc8d 100644 --- a/serial_darwin.go +++ b/serial_darwin.go @@ -29,3 +29,11 @@ func (port *unixPort) setSpecialBaudrate(speed uint32) error { const kIOSSIOSPEED = 0x80045402 return unix.IoctlSetPointerInt(port.handle, kIOSSIOSPEED, int(speed)) } + +func (port *unixPort) ResetInputBuffer() error { + return unix.IoctlSetPointerInt(port.handle, ioctlTcflsh, unix.TCIFLUSH) +} + +func (port *unixPort) ResetOutputBuffer() error { + return unix.IoctlSetPointerInt(port.handle, ioctlTcflsh, unix.TCOFLUSH) +} diff --git a/serial_resetbuf_linux_bsd.go b/serial_resetbuf_linux_bsd.go new file mode 100644 index 0000000..c6e1a4a --- /dev/null +++ b/serial_resetbuf_linux_bsd.go @@ -0,0 +1,19 @@ +// +// Copyright 2014-2021 Cristian Maglie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// + +// +build linux freebsd openbsd + +package serial + +import "golang.org/x/sys/unix" + +func (port *unixPort) ResetInputBuffer() error { + return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCIFLUSH) +} + +func (port *unixPort) ResetOutputBuffer() error { + return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCOFLUSH) +} diff --git a/serial_unix.go b/serial_unix.go index 4a8ef66..e171001 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -117,14 +117,6 @@ func (port *unixPort) Write(p []byte) (n int, err error) { return } -func (port *unixPort) ResetInputBuffer() error { - return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCIFLUSH) -} - -func (port *unixPort) ResetOutputBuffer() error { - return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCOFLUSH) -} - func (port *unixPort) SetMode(mode *Mode) error { settings, err := port.getTermSettings() if err != nil {