forked from albenik/go-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_termsettings_linux.go
45 lines (35 loc) · 1 KB
/
serial_termsettings_linux.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
//
// 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 linux && !android && !ppc64le
// +build linux,!android,!ppc64le
package serial
import (
"golang.org/x/sys/unix"
)
func (p *Port) retrieveTermSettings() (s *settings, err error) {
s = &settings{
termios: new(unix.Termios),
}
if s.termios, err = unix.IoctlGetTermios(p.internal.handle, unix.TCGETS); err != nil {
return nil, newPortOSError(err)
}
if s.termios.Cflag&unix.BOTHER == unix.BOTHER {
if s.termios, err = unix.IoctlGetTermios(p.internal.handle, unix.TCGETS2); err != nil {
return nil, newPortOSError(err)
}
}
return s, nil
}
func (p *Port) applyTermSettings(s *settings) error {
req := uint(unix.TCSETS)
if s.termios.Cflag&unix.BOTHER == unix.BOTHER {
req = unix.TCSETS2
}
if err := unix.IoctlSetTermios(p.internal.handle, req, s.termios); err != nil {
return newPortOSError(err)
}
return nil
}