Added support for sending breaks
This commit is contained in:
@@ -48,6 +48,9 @@ type Port interface {
|
||||
|
||||
// Close the serial port
|
||||
Close() error
|
||||
|
||||
// Break sends a break for a determined time
|
||||
Break(time.Duration) error
|
||||
}
|
||||
|
||||
// NoTimeout should be used as a parameter to SetReadTimeout to disable timeout.
|
||||
|
||||
@@ -14,6 +14,8 @@ const regexFilter = "^(cu|tty)\\..*"
|
||||
const ioctlTcgetattr = unix.TIOCGETA
|
||||
const ioctlTcsetattr = unix.TIOCSETA
|
||||
const ioctlTcflsh = unix.TIOCFLUSH
|
||||
const ioctlTioccbrk = unix.TIOCCBRK
|
||||
const ioctlTiocsbrk = unix.TIOCSBRK
|
||||
|
||||
func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) {
|
||||
baudrate, ok := baudrateMap[speed]
|
||||
|
||||
@@ -56,6 +56,8 @@ const tcCRTSCTS uint32 = tcCCTS_OFLOW
|
||||
const ioctlTcgetattr = unix.TIOCGETA
|
||||
const ioctlTcsetattr = unix.TIOCSETA
|
||||
const ioctlTcflsh = unix.TIOCFLUSH
|
||||
const ioctlTioccbrk = unix.TIOCCBRK
|
||||
const ioctlTiocsbrk = unix.TIOCSBRK
|
||||
|
||||
func toTermiosSpeedType(speed uint32) uint32 {
|
||||
return speed
|
||||
|
||||
@@ -63,6 +63,8 @@ const tcCRTSCTS uint32 = unix.CRTSCTS
|
||||
const ioctlTcgetattr = unix.TCGETS
|
||||
const ioctlTcsetattr = unix.TCSETS
|
||||
const ioctlTcflsh = unix.TCFLSH
|
||||
const ioctlTioccbrk = unix.TIOCCBRK
|
||||
const ioctlTiocsbrk = unix.TIOCSBRK
|
||||
|
||||
func toTermiosSpeedType(speed uint32) uint32 {
|
||||
return speed
|
||||
|
||||
@@ -56,6 +56,8 @@ const tcCRTSCTS uint32 = tcCCTS_OFLOW
|
||||
const ioctlTcgetattr = unix.TIOCGETA
|
||||
const ioctlTcsetattr = unix.TIOCSETA
|
||||
const ioctlTcflsh = unix.TIOCFLUSH
|
||||
const ioctlTioccbrk = unix.TIOCCBRK
|
||||
const ioctlTiocsbrk = unix.TIOCSBRK
|
||||
|
||||
func toTermiosSpeedType(speed uint32) int32 {
|
||||
return int32(speed)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
//
|
||||
|
||||
//go:build linux || darwin || freebsd || openbsd
|
||||
// +build linux darwin freebsd openbsd
|
||||
|
||||
package serial
|
||||
@@ -117,6 +118,20 @@ func (port *unixPort) Write(p []byte) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (port *unixPort) Break(t time.Duration) error {
|
||||
if err := unix.IoctlSetInt(port.handle, ioctlTiocsbrk, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
time.Sleep(t)
|
||||
|
||||
if err := unix.IoctlSetInt(port.handle, ioctlTioccbrk, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (port *unixPort) SetMode(mode *Mode) error {
|
||||
settings, err := port.getTermSettings()
|
||||
if err != nil {
|
||||
|
||||
@@ -381,6 +381,10 @@ func (port *windowsPort) SetReadTimeout(timeout time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (port *windowsPort) Break(d time.Duration) error {
|
||||
return &PortError{code: FunctionNotImplemented}
|
||||
}
|
||||
|
||||
func createOverlappedEvent() (*syscall.Overlapped, error) {
|
||||
h, err := createEvent(nil, true, false, nil)
|
||||
return &syscall.Overlapped{HEvent: h}, err
|
||||
|
||||
Reference in New Issue
Block a user