-
Notifications
You must be signed in to change notification settings - Fork 205
/
serial_darwin.go
46 lines (36 loc) · 1.16 KB
/
serial_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Copyright 2014-2024 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.
//
package serial
import (
"regexp"
"golang.org/x/sys/unix"
)
const devFolder = "/dev"
var osPortFilter = regexp.MustCompile("^(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]
if !ok {
return nil, true
}
settings.Ispeed = toTermiosSpeedType(baudrate)
settings.Ospeed = toTermiosSpeedType(baudrate)
return nil, false
}
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)
}