-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathserial_termsettings_darwin.go
46 lines (34 loc) · 1.04 KB
/
serial_termsettings_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-2017 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.
//
//go:build darwin
package serial
// #include <sys/ioctl.h>
// #include <IOKit/serial/ioss.h>
import "C"
import (
"unsafe"
"golang.org/x/sys/unix"
)
func (p *Port) retrieveTermSettings() (*settings, error) {
s := &settings{termios: new(unix.Termios), specificBaudrate: 0}
var err error
if s.termios, err = unix.IoctlGetTermios(p.internal.handle, unix.TIOCGETA); err != nil {
return nil, newPortOSError(err)
}
speed := C.cfgetispeed((*C.struct_termios)(unsafe.Pointer(s.termios)))
s.specificBaudrate = int(speed)
return s, nil
}
func (p *Port) applyTermSettings(s *settings) error {
if err := unix.IoctlSetTermios(p.internal.handle, unix.TIOCSETA, s.termios); err != nil {
return newPortOSError(err)
}
speed := s.specificBaudrate
if err := unix.IoctlSetPointerInt(p.internal.handle, C.IOSSIOSPEED, speed); err != nil {
return newPortOSError(err)
}
return nil
}