generated from soypat/go-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pserial.go
63 lines (53 loc) · 1.12 KB
/
pserial.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package pserial
import (
"errors"
"sync"
"go.bug.st/serial"
)
var (
errInvalidCharacterSize = errors.New("pserial: invalid or unsupported character size")
errInvalidStopBits = errors.New("pserial: invalid or unsupported stop bits")
errInvalidParity = errors.New("pserial: invalid or unsupported parity")
errInvalidBaudRate = errors.New("pserial: invalid or unsupported baud rate")
)
type (
Parity uint8
StopBits uint8
)
const (
Stop1 = iota
Stop2
Stop1_5 // 1.5 stop bits. Only available on some platforms.
)
const (
ParityNone = iota
ParityOdd
ParityEven
ParityMark
)
type Serial struct {
fd int
mu sync.Mutex
}
type Mode struct {
// Baud is amount of data and non-data bits sent over the wire per second.
// Common bauds are 9600, 19200, 115200.
Baud int
//
ByteSize uint8
Parity Parity
StopBits StopBits
}
func Open(name string, config Mode) (*Serial, error) {
if config.Baud <= 0 {
return nil, errors.New("pserial: invalid baud rate")
}
serial.Open("", nil)
return nativeOpen(name, config)
}
func (s *Serial) lock() {
s.mu.Lock()
}
func (s *Serial) unlock() {
s.mu.Unlock()
}