ccutrer-serialport 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5883d7fba69f81de31f8f8d2a21f25e1734fb25adce3a3ec9f873a67c9e96b43
4
- data.tar.gz: 780c226269254d5d413445159cdd8a3603d5e835c315eb00cc9c50557d1b1fbf
3
+ metadata.gz: 105008488a20c325d7a6d178da216ba39a597dbc42d741079e3f84d49a84dc71
4
+ data.tar.gz: 03b74a72e0758729047cfb7553ece560ff7e209073e2ea5419f0bc215326b7a7
5
5
  SHA512:
6
- metadata.gz: 27f8bb29ca45fff55a30b0825dc1087f74259de5a81bb1a6671f90c95a52bf4e832f21ca40c79e84e1e486d5da362199d631a90134df34e09ce4b2162721acdc
7
- data.tar.gz: '08619960bba97f86e4752a14587b3b9d2a9b68723a76e681d7afe1e6f1f72a490c7cc23c9d43fc0155cc582db2e98e1323be9fcff23c45ce17a4d33dad711d1b'
6
+ metadata.gz: ca738d205a88eee990ae890ed3ebade20d59fbd7482a39b43938ab8ccbe5c4b39332ec740fe3b7b36c73f8cee5ac6bd4dd880cb5823c65f8cecd6a0de63c98b4
7
+ data.tar.gz: 5176af69f40896d1dddae480d88054955064eef462bbb5743e3a5a263dc363d2849f9f77ab683d5c25878e4e73dac2c368840631a934ecdd878f2e8afb842a42
@@ -1,84 +1,99 @@
1
- # Copyright (c) 2014-2016 The Hybrid Group, 2020 Cody Cutrer
1
+ # frozen_string_literal: true
2
2
 
3
- module CCutrer::SerialPort::Posix
4
- extend FFI::Library
5
- ffi_lib FFI::Library::LIBC
3
+ # Copyright (c) 2014-2016 The Hybrid Group, 2020-2021 Cody Cutrer
6
4
 
7
- VTIME = 5
8
- TCSANOW = 0
9
- TCSETS = 0x5402
10
- IGNPAR = 0000004
11
- PARENB = 0000400
12
- PARODD = 0001000
13
- CSTOPB = 0000100
14
- CREAD = 0000200
15
- CLOCAL = 0004000
16
- VMIN = 6
17
- NCCS = 32
5
+ module CCutrer
6
+ class SerialPort < File
7
+ module Termios
8
+ NCCS = 32
18
9
 
19
- DATA_BITS = {
20
- 5 => 0000000,
21
- 6 => 0000020,
22
- 7 => 0000040,
23
- 8 => 0000060
24
- }
10
+ class Termios < FFI::Struct
11
+ layout :c_iflag,
12
+ :uint,
13
+ :c_oflag,
14
+ :uint,
15
+ :c_cflag,
16
+ :uint,
17
+ :c_lflag,
18
+ :uint,
19
+ :c_line,
20
+ :uchar,
21
+ :c_cc,
22
+ [:uchar, NCCS],
23
+ :c_ispeed,
24
+ :uint,
25
+ :c_ospeed,
26
+ :uint
27
+ end
25
28
 
26
- BAUD_RATES = {
27
- 0 => 0000000,
28
- 50 => 0000001,
29
- 75 => 0000002,
30
- 110 => 0000003,
31
- 134 => 0000004,
32
- 150 => 0000005,
33
- 200 => 0000006,
34
- 300 => 0000007,
35
- 600 => 0000010,
36
- 1200 => 0000011,
37
- 1800 => 0000012,
38
- 2400 => 0000013,
39
- 4800 => 0000014,
40
- 9600 => 0000015,
41
- 19200 => 0000016,
42
- 38400 => 0000017,
43
- 57600 => 0010001,
44
- 115200 => 0010002,
45
- 230400 => 0010003,
46
- 460800 => 0010004,
47
- 500000 => 0010005,
48
- 576000 => 0010006,
49
- 921600 => 0010007,
50
- 1000000 => 0010010,
51
- 1152000 => 0010011,
52
- 1500000 => 0010012,
53
- 2000000 => 0010013,
54
- 2500000 => 0010014,
55
- 3000000 => 0010015,
56
- 3500000 => 0010016,
57
- 4000000 => 0010017
58
- }
29
+ # c_cc characters
30
+ VTIME = 5
31
+ VMIN = 6
59
32
 
60
- PARITY = {
61
- :none => 0000000,
62
- :even => PARENB,
63
- :odd => PARENB | PARODD,
64
- }
33
+ # c_iflag bits
34
+ IGNPAR = 0o000004
65
35
 
66
- STOPBITS = {
67
- 1 => 0x00000000,
68
- 2 => CSTOPB
69
- }
36
+ # c_cflag bits
37
+ CSIZE = 0o000060
38
+ CSTOPB = 0o000100
39
+ CREAD = 0o000200
40
+ PARENB = 0o000400
41
+ PARODD = 0o001000
42
+ CLOCAL = 0o004000
70
43
 
71
- class Termios < FFI::Struct
72
- layout :c_iflag, :uint,
73
- :c_oflag, :uint,
74
- :c_cflag, :uint,
75
- :c_lflag, :uint,
76
- :c_line, :uchar,
77
- :cc_c, [ :uchar, NCCS ],
78
- :c_ispeed, :uint,
79
- :c_ospeed, :uint
80
- end
44
+ DATA_BITS = {
45
+ 5 => 0o000000,
46
+ 6 => 0o000020,
47
+ 7 => 0o000040,
48
+ 8 => 0o000060
49
+ }.freeze
50
+
51
+ BAUD_RATES = {
52
+ 0 => 0o000000,
53
+ 50 => 0o000001,
54
+ 75 => 0o000002,
55
+ 110 => 0o000003,
56
+ 134 => 0o000004,
57
+ 150 => 0o000005,
58
+ 200 => 0o000006,
59
+ 300 => 0o000007,
60
+ 600 => 0o000010,
61
+ 1200 => 0o000011,
62
+ 1800 => 0o000012,
63
+ 2400 => 0o000013,
64
+ 4800 => 0o000014,
65
+ 9600 => 0o000015,
66
+ 19_200 => 0o000016,
67
+ 38_400 => 0o000017,
68
+ 57_600 => 0o010001,
69
+ 115_200 => 0o010002,
70
+ 230_400 => 0o010003,
71
+ 460_800 => 0o010004,
72
+ 500_000 => 0o010005,
73
+ 576_000 => 0o010006,
74
+ 921_600 => 0o010007,
75
+ 1_000_000 => 0o010010,
76
+ 1_152_000 => 0o010011,
77
+ 1_500_000 => 0o010012,
78
+ 2_000_000 => 0o010013,
79
+ 2_500_000 => 0o010014,
80
+ 3_000_000 => 0o010015,
81
+ 3_500_000 => 0o010016,
82
+ 4_000_000 => 0o010017
83
+ }.freeze
84
+
85
+ PARITY = {
86
+ none: 0o000000,
87
+ even: PARENB,
88
+ odd: PARENB | PARODD
89
+ }.freeze
81
90
 
82
- attach_function :tcsetattr, [ :int, :int, Termios ], :int, blocking: true
83
- attach_function :tcgetattr, [ :int, Termios ], :int, blocking: true
91
+ STOP_BITS = {
92
+ 1 => 0o000000,
93
+ 2 => CSTOPB
94
+ }.freeze
95
+
96
+ TCSANOW = 0
97
+ end
98
+ end
84
99
  end
@@ -1,76 +1,91 @@
1
- # Copyright (c) 2014-2016 The Hybrid Group, 2020 Cody Cutrer
1
+ # frozen_string_literal: true
2
2
 
3
- module CCutrer::SerialPort::Posix
4
- extend FFI::Library
5
- ffi_lib FFI::Library::LIBC
3
+ # Copyright (c) 2014-2016 The Hybrid Group, 2020-2021 Cody Cutrer
6
4
 
7
- IGNPAR = 0x00000004
8
- PARENB = 0x00001000
9
- PARODD = 0x00002000
10
- VMIN = 16
11
- VTIME = 17
12
- CLOCAL = 0x00008000
13
- CSTOPB = 0x00000400
14
- CREAD = 0x00000800
15
- CCTS_OFLOW = 0x00010000 # Clearing this disables RTS AND CTS.
16
- TCSANOW = 0
17
- NCCS = 20
5
+ module CCutrer
6
+ class SerialPort < File
7
+ module Termios
8
+ NCCS = 20
18
9
 
19
- DATA_BITS = {
20
- 5 => 0x00000000,
21
- 6 => 0x00000100,
22
- 7 => 0x00000200,
23
- 8 => 0x00000300
24
- }
10
+ class Termios < FFI::Struct
11
+ layout :c_iflag,
12
+ :ulong,
13
+ :c_oflag,
14
+ :ulong,
15
+ :c_cflag,
16
+ :ulong,
17
+ :c_lflag,
18
+ :ulong,
19
+ :c_line,
20
+ :uchar,
21
+ :c_cc,
22
+ [:uchar, NCCS],
23
+ :c_ispeed,
24
+ :ulong,
25
+ :c_ospeed,
26
+ :ulong
27
+ end
25
28
 
26
- BAUD_RATES = {
27
- 0 => 0,
28
- 50 => 50,
29
- 75 => 75,
30
- 110 => 110,
31
- 134 => 134,
32
- 150 => 150,
33
- 200 => 200,
34
- 300 => 300,
35
- 600 => 600,
36
- 1200 => 1200,
37
- 1800 => 1800,
38
- 2400 => 2400,
39
- 4800 => 4800,
40
- 9600 => 9600,
41
- 19200 => 19200,
42
- 38400 => 38400,
43
- 7200 => 7200,
44
- 14400 => 14400,
45
- 28800 => 28800,
46
- 57600 => 57600,
47
- 76800 => 76800,
48
- 115200 => 115200,
49
- 230400 => 230400
50
- }
29
+ # c_cc characters
30
+ VMIN = 16
31
+ VTIME = 17
51
32
 
52
- PARITY = {
53
- :none => 0x00000000,
54
- :even => PARENB,
55
- :odd => PARENB | PARODD,
56
- }
33
+ # c_iflag bits
34
+ IGNPAR = 0x00000004
57
35
 
58
- STOPBITS = {
59
- 1 => 0x00000000,
60
- 2 => CSTOPB
61
- }
36
+ # c_cflag bits
37
+ CSIZE = 0x00000300
38
+ CSTOPB = 0x00000400
39
+ CREAD = 0x00000800
40
+ PARENB = 0x00001000
41
+ PARODD = 0x00002000
42
+ CLOCAL = 0x00008000
62
43
 
63
- class Termios < FFI::Struct
64
- layout :c_iflag, :ulong,
65
- :c_oflag, :ulong,
66
- :c_cflag, :ulong,
67
- :c_lflag, :ulong,
68
- :c_line, :uchar,
69
- :cc_c, [ :uchar, NCCS ],
70
- :c_ispeed, :ulong,
71
- :c_ospeed, :ulong
72
- end
44
+ DATA_BITS = {
45
+ 5 => 0x00000000,
46
+ 6 => 0x00000100,
47
+ 7 => 0x00000200,
48
+ 8 => 0x00000300
49
+ }.freeze
50
+
51
+ BAUD_RATES = {
52
+ 0 => 0,
53
+ 50 => 50,
54
+ 75 => 75,
55
+ 110 => 110,
56
+ 134 => 134,
57
+ 150 => 150,
58
+ 200 => 200,
59
+ 300 => 300,
60
+ 600 => 600,
61
+ 1200 => 1200,
62
+ 1800 => 1800,
63
+ 2400 => 2400,
64
+ 4800 => 4800,
65
+ 7200 => 7200,
66
+ 9600 => 9600,
67
+ 19_200 => 19_200,
68
+ 38_400 => 38_400,
69
+ 14_400 => 14_400,
70
+ 28_800 => 28_800,
71
+ 57_600 => 57_600,
72
+ 76_800 => 76_800,
73
+ 115_200 => 115_200,
74
+ 230_400 => 230_400
75
+ }.freeze
76
+
77
+ PARITY = {
78
+ none: 0x00000000,
79
+ even: PARENB,
80
+ odd: PARENB | PARODD
81
+ }.freeze
73
82
 
74
- attach_function :tcsetattr, [ :int, :int, Termios ], :int, blocking: true
75
- attach_function :tcgetattr, [ :int, Termios ], :int, blocking: true
83
+ STOP_BITS = {
84
+ 1 => 0x00000000,
85
+ 2 => CSTOPB
86
+ }.freeze
87
+
88
+ TCSANOW = 0
89
+ end
90
+ end
76
91
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2014-2016 The Hybrid Group, 2020-2021 Cody Cutrer
4
+
5
+ module CCutrer
6
+ class SerialPort < File
7
+ module Termios
8
+ attach_function :cfgetispeed, [Termios], :uint
9
+ attach_function :cfgetospeed, [Termios], :uint
10
+ attach_function :cfsetispeed, [Termios, :uint], :int
11
+ attach_function :cfsetospeed, [Termios, :uint], :int
12
+ attach_function :tcsetattr, [:int, :int, Termios], :int
13
+ attach_function :tcgetattr, [:int, Termios], :int
14
+
15
+ begin
16
+ attach_function :cfsetibaud, [Termios, :uint], :int
17
+ attach_function :cfsetobaud, [Termios, :uint], :int
18
+ attach_function :cfgetibaud, [Termios], :uint
19
+ attach_function :cfgetobaud, [Termios], :uint
20
+ rescue FFI::NotFoundError
21
+ # ignore; will fall back to hardcoded constants
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2014-2016 The Hybrid Group, 2020-2021 Cody Cutrer
4
+
5
+ module CCutrer
6
+ class SerialPort < File
7
+ module Termios
8
+ extend FFI::Library
9
+
10
+ ffi_lib FFI::Library::LIBC
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (c) 2014-2018 The Hybrid Group and Friends
2
4
 
3
5
  module CCutrer
4
6
  class SerialPort < File
5
- VERSION = "1.0.0"
7
+ VERSION = "1.2.0"
6
8
  end
7
9
  end
@@ -1,45 +1,166 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (c) 2014-2016 The Hybrid Group, 2020 Cody Cutrer
2
4
 
3
- require 'fcntl'
5
+ module CCutrer
6
+ class SerialPort < File
7
+ def initialize(address, baud: nil, data_bits: nil, parity: nil, stop_bits: nil)
8
+ super(address, IO::RDWR | IO::NOCTTY | IO::NONBLOCK)
4
9
 
5
- class CCutrer::SerialPort < File
6
- def initialize(address, baud: 9600, data_bits: 8, parity: :none, stop_bits: 1)
7
- super(address, IO::RDWR | IO::NOCTTY | IO::NONBLOCK)
10
+ raise IOError, "Not a serial port" unless tty?
8
11
 
9
- raise IOError, "Not a serial port" unless tty?
12
+ @termios = Termios::Termios.new
13
+ refresh
10
14
 
11
- fl = fcntl(Fcntl::F_GETFL, 0)
12
- fcntl(Fcntl::F_SETFL, ~Fcntl::O_NONBLOCK & fl)
15
+ # base config
16
+ @termios[:c_iflag] = Termios::IGNPAR
17
+ @termios[:c_oflag] = 0
18
+ @termios[:c_cflag] =
19
+ Termios::CREAD |
20
+ Termios::CLOCAL
21
+ @termios[:c_lflag] = 0
13
22
 
14
- @config = build_config(baud, data_bits, parity, stop_bits)
23
+ @termios[:c_cc][Termios::VTIME] = 0
24
+ @termios[:c_cc][Termios::VMIN] = 0
15
25
 
16
- err = Posix.tcsetattr(fileno, Posix::TCSANOW, @config)
17
- if err == -1
18
- raise SystemCallError, FFI.errno
26
+ configure do
27
+ self.baud = baud if baud
28
+ self.data_bits = data_bits if data_bits
29
+ self.parity = parity if parity
30
+ self.stop_bits = stop_bits if stop_bits
31
+ end
32
+ raise Errno::EINVAL if baud && baud != self.baud
33
+ raise Errno::EINVAL if data_bits && data_bits != self.data_bits
34
+ raise Errno::EINVAL if parity && parity != self.parity
35
+ raise Errno::EINVAL if stop_bits && stop_bits != self.stop_bits
36
+ end
37
+
38
+ # Read up to +length+ bytes that are currently available without waiting.
39
+ def read(length, outbuf = nil)
40
+ result = read_nonblock(length, outbuf, exception: false)
41
+ return result unless result == :wait_readable
42
+
43
+ nil
44
+ end
45
+
46
+ def getbyte
47
+ read(1)&.getbyte(0)
48
+ end
49
+
50
+ def configure
51
+ @configuring = true
52
+ yield
53
+ @configuring = false
54
+ apply
55
+ refresh
56
+ ensure
57
+ @configuring = false
58
+ end
59
+
60
+ if Termios.respond_to?(:cfgetibaud)
61
+ def baud
62
+ Termios.cfgetibaud(@termios)
63
+ end
64
+
65
+ def baud=(baud)
66
+ raise ArgumentError, "Invalid baud" unless Termios::BAUD_RATES.key?(baud)
67
+
68
+ err = Termios.cfsetibaud(@termios, baud)
69
+ raise SystemCallError, FFI.errno if err == -1
70
+
71
+ err = Termios.cfsetobaud(@termios, baud)
72
+ raise SystemCallError, FFI.errno if err == -1
73
+
74
+ apply
75
+ refresh
76
+ end
77
+ else
78
+ def baud
79
+ Termios::BAUD_RATES.invert[Termios.cfgetispeed(@termios)]
80
+ end
81
+
82
+ def baud=(baud)
83
+ raise ArgumentError, "Invalid baud" unless Termios::BAUD_RATES.key?(baud)
84
+
85
+ err = Termios.cfsetispeed(@termios, Termios::BAUD_RATES[baud])
86
+ raise SystemCallError, FFI.errno if err == -1
87
+
88
+ err = Termios.cfsetospeed(@termios, Termios::BAUD_RATES[baud])
89
+ raise SystemCallError, FFI.errno if err == -1
90
+
91
+ apply
92
+ refresh
93
+ end
19
94
  end
20
- end
21
95
 
22
- private
96
+ def data_bits
97
+ Termios::DATA_BITS.invert[@termios[:c_cflag] & Termios::CSIZE]
98
+ end
99
+
100
+ def data_bits=(data_bits)
101
+ raise ArgumentError, "Invalid data bits" unless Termios::DATA_BITS.key?(data_bits)
102
+
103
+ @termios[:c_cflag] &= ~Termios::CSIZE
104
+ @termios[:c_cflag] |= Termios::DATA_BITS[data_bits]
105
+ apply
106
+ refresh
107
+ end
108
+
109
+ def parity
110
+ Termios::PARITY.invert[@termios[:c_cflag] & Termios::PARITY[:odd]]
111
+ end
23
112
 
24
- def build_config(baud_rate, data_bits, parity, stop_bits)
25
- config = Posix::Termios.new
113
+ def parity=(parity)
114
+ raise ArgumentError, "Invalid parity" unless Termios::PARITY.key?(parity)
26
115
 
27
- config[:c_iflag] = Posix::IGNPAR
28
- config[:c_ispeed] = Posix::BAUD_RATES[baud_rate]
29
- config[:c_ospeed] = Posix::BAUD_RATES[baud_rate]
30
- config[:c_cflag] = Posix::DATA_BITS[data_bits] |
31
- Posix::CREAD |
32
- Posix::CLOCAL |
33
- Posix::PARITY[parity] |
34
- Posix::STOPBITS[stop_bits]
116
+ @termios[:c_cflag] &= ~Termios::PARITY[:odd]
117
+ @termios[:c_cflag] |= Termios::PARITY[parity]
118
+ apply
119
+ refresh
120
+ end
35
121
 
36
- # Masking in baud rate on OS X would corrupt the settings.
37
- if ON_LINUX
38
- config[:c_cflag] = config[:c_cflag] | Posix::BAUD_RATES[baud_rate]
122
+ def stop_bits
123
+ @termios[:c_cflag].nobits?(Termios::CSTOPB) ? 1 : 2
39
124
  end
40
125
 
41
- config[:cc_c][Posix::VMIN] = 0
126
+ def stop_bits=(stop_bits)
127
+ raise ArgumentError, "Invalid stop bits" unless Termios::STOP_BITS.key?(stop_bits)
42
128
 
43
- config
129
+ @termios[:c_cflag] &= ~Termios::CSTOPB
130
+ @termios[:c_cflag] |= Termios::STOP_BITS[stop_bits]
131
+ apply
132
+ refresh
133
+ end
134
+
135
+ def inspect
136
+ "#<#{self.class.name}:#{path} #{baud} #{data_bits}#{parity.to_s[0].upcase}#{stop_bits}>"
137
+ end
138
+
139
+ private
140
+
141
+ def apply
142
+ return if @configuring
143
+
144
+ err = Termios.tcsetattr(fileno, Termios::TCSANOW, @termios)
145
+ raise SystemCallError, FFI.errno if err == -1
146
+
147
+ self
148
+ rescue SystemCallError
149
+ begin
150
+ refresh
151
+ rescue SystemCallError
152
+ # ignore errors during refresh after a failed apply
153
+ end
154
+ raise
155
+ end
156
+
157
+ def refresh
158
+ return if @configuring
159
+
160
+ err = Termios.tcgetattr(fileno, @termios)
161
+ raise SystemCallError, FFI.errno if err == -1
162
+
163
+ self
164
+ end
44
165
  end
45
166
  end
@@ -1,22 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (c) 2014-2016 The Hybrid Group, 2020 Cody Cutrer
2
4
 
3
- require 'rbconfig'
4
- require 'ffi'
5
+ require "rbconfig"
6
+ require "ffi"
5
7
 
6
8
  module CCutrer
7
9
  class SerialPort < File
8
- ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
9
- ON_LINUX = RbConfig::CONFIG['host_os'] =~ /linux/i
10
+ ON_WINDOWS = RbConfig::CONFIG["host_os"] =~ /mswin|windows|mingw/i
11
+ ON_LINUX = RbConfig::CONFIG["host_os"] =~ /linux/i
12
+
13
+ raise "rubyserial is not currently supported on windows" if ON_WINDOWS
10
14
 
11
- if ON_WINDOWS
12
- raise "rubyserial is not currently supported on windows"
13
- elsif ON_LINUX
14
- require 'ccutrer/serial_port/linux'
15
+ # order is important here
16
+ require "ccutrer/serial_port/termios"
17
+ if ON_LINUX
18
+ require "ccutrer/serial_port/linux"
15
19
  else
16
- require 'ccutrer/serial_port/osx'
20
+ require "ccutrer/serial_port/osx"
17
21
  end
22
+ require "ccutrer/serial_port/posix"
18
23
  end
19
24
  end
20
25
 
21
- require 'ccutrer/serial_port'
22
- require 'ccutrer/serial_port/version'
26
+ require "ccutrer/serial_port"
27
+ require "ccutrer/serial_port/version"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccutrer-serialport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
10
+ date: 2026-07-28 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ffi
@@ -30,62 +29,24 @@ dependencies:
30
29
  - - ">="
31
30
  - !ruby/object:Gem::Version
32
31
  version: 1.9.3
33
- - !ruby/object:Gem::Dependency
34
- name: rake
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '13.0'
40
- type: :development
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '13.0'
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: 3.0.0
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: 3.0.0
61
32
  description: Ruby only library that relies on FFI instead of an extension, and inherits
62
33
  from IO
63
- email:
64
34
  executables: []
65
35
  extensions: []
66
36
  extra_rdoc_files: []
67
37
  files:
68
- - ".gitignore"
69
- - ".rspec"
70
- - ".travis.yml"
71
- - Gemfile
72
- - Gemfile.lock
73
- - LICENSE
74
- - README.md
75
- - Rakefile
76
- - ccutrer-serialport.gemspec
77
38
  - lib/ccutrer-serialport.rb
78
39
  - lib/ccutrer/serial_port.rb
79
40
  - lib/ccutrer/serial_port/linux.rb
80
41
  - lib/ccutrer/serial_port/osx.rb
42
+ - lib/ccutrer/serial_port/posix.rb
43
+ - lib/ccutrer/serial_port/termios.rb
81
44
  - lib/ccutrer/serial_port/version.rb
82
- - spec/serialport_spec.rb
83
- - spec/spec_helper.rb
84
45
  homepage: https://github.com/ccutrer/ccutrer-serialport
85
46
  licenses:
86
47
  - MIT
87
- metadata: {}
88
- post_install_message:
48
+ metadata:
49
+ rubygems_mfa_required: 'true'
89
50
  rdoc_options: []
90
51
  require_paths:
91
52
  - lib
@@ -93,15 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
54
  requirements:
94
55
  - - ">="
95
56
  - !ruby/object:Gem::Version
96
- version: '2.0'
57
+ version: '3.1'
97
58
  required_rubygems_version: !ruby/object:Gem::Requirement
98
59
  requirements:
99
60
  - - ">="
100
61
  - !ruby/object:Gem::Version
101
62
  version: '0'
102
63
  requirements: []
103
- rubygems_version: 3.1.2
104
- signing_key:
64
+ rubygems_version: 3.6.2
105
65
  specification_version: 4
106
66
  summary: Linux/OS X RS-232 serial port communication
107
67
  test_files: []
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- /pkg
2
- /socat.log
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --warnings
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- addons:
4
- apt:
5
- packages:
6
- - socat
7
- rvm:
8
- - 2.7
9
- - 2.6
10
- script:
11
- - bundle exec rake spec
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ccutrer-serialport (1.0.0)
5
- ffi (~> 1.9, >= 1.9.3)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- diff-lcs (1.4.4)
11
- ffi (1.13.1)
12
- rake (13.0.1)
13
- rspec (3.0.0)
14
- rspec-core (~> 3.0.0)
15
- rspec-expectations (~> 3.0.0)
16
- rspec-mocks (~> 3.0.0)
17
- rspec-core (3.0.4)
18
- rspec-support (~> 3.0.0)
19
- rspec-expectations (3.0.4)
20
- diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.0.0)
22
- rspec-mocks (3.0.4)
23
- rspec-support (~> 3.0.0)
24
- rspec-support (3.0.4)
25
-
26
- PLATFORMS
27
- ruby
28
-
29
- DEPENDENCIES
30
- ccutrer-serialport!
31
- rake (~> 13.0)
32
- rspec (~> 3.0.0)
33
-
34
- BUNDLED WITH
35
- 2.1.4
data/LICENSE DELETED
@@ -1,7 +0,0 @@
1
- Copyright 2020 Cody Cutrer
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,38 +0,0 @@
1
- # ccutrer-serialport
2
-
3
- SerialPort is a simple Ruby gem for interacting with serial ports.
4
-
5
- It does not require an extension thanks to using [FFI](https://github.com/ffi/ffi).
6
-
7
- SerialPort objects inherit from `File` (and thus `IO`), so are compatible with all
8
- IO methods, in particular `read_partial`, and asynchronous IO.
9
-
10
- It was inspired by the [rubyserial](https://github.com/hybridgroup/rubyserial) gem.
11
-
12
- ## Usage
13
-
14
- ```ruby
15
- require 'ccutrer-rubyserial'
16
- serialport = CCutrer::SerialPort.new '/dev/ttyACM0' # Defaults to 9600 baud, 8 data bits, and no parity
17
- serialport = CCutrer::SerialPort.new '/dev/ttyACM0', baud: 57600
18
- serialport = CCutrer::SerialPort.new '/dev/ttyACM0', baud: 19200, data_bits: 8, parity: :even
19
-
20
- serialport.read(4096)
21
- serialport.gets
22
-
23
- require 'io/wait'
24
- serialport.ready?
25
- serialport.wait_readable(1)
26
- ```
27
-
28
- ## Running the tests
29
-
30
- The test suite is written using rspec, just use the `rspec` command.
31
-
32
- ### Test dependencies
33
-
34
- To run the tests, you must also have `socat` installed.
35
-
36
- ## License
37
-
38
- MIT. See `LICENSE` for more details.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
@@ -1,24 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require "ccutrer/serial_port/version"
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "ccutrer-serialport"
6
- s.version = CCutrer::SerialPort::VERSION
7
- s.summary = "Linux/OS X RS-232 serial port communication"
8
- s.description = "Ruby only library that relies on FFI instead of an extension, and inherits from IO"
9
- s.homepage = "https://github.com/ccutrer/ccutrer-serialport"
10
- s.authors = ["Cody Cutrer"]
11
- s.platform = Gem::Platform::RUBY
12
- s.license = 'MIT'
13
-
14
- s.required_ruby_version = '>= 2.0'
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
19
-
20
- s.add_runtime_dependency 'ffi', '~> 1.9', '>= 1.9.3'
21
-
22
- s.add_development_dependency 'rake', '~> 13.0'
23
- s.add_development_dependency 'rspec', '~> 3.0.0'
24
- end
@@ -1,177 +0,0 @@
1
- require 'ccutrer-serialport'
2
-
3
- describe CCutrer::SerialPort do
4
- before do
5
- @ports = []
6
- File.delete('socat.log') if File.file?('socat.log')
7
-
8
- raise 'socat not found' unless (`socat -h` && $? == 0)
9
-
10
- Thread.new do
11
- system('socat -lf socat.log -d -d pty,raw,echo=0 pty,raw,echo=0')
12
- end
13
-
14
- @ptys = nil
15
-
16
- loop do
17
- if File.file? 'socat.log'
18
- @file = File.open('socat.log', "r")
19
- @fileread = @file.read
20
-
21
- unless @fileread.count("\n") < 3
22
- @ptys = @fileread.scan(/PTY is (.*)/)
23
- break
24
- end
25
- end
26
- end
27
-
28
- @ports = [@ptys[1][0], @ptys[0][0]]
29
-
30
- @sp2 = CCutrer::SerialPort.new(@ports[0])
31
- @sp = CCutrer::SerialPort.new(@ports[1])
32
- end
33
-
34
- after do
35
- @sp2.close
36
- @sp.close
37
- end
38
-
39
- it "should read and write" do
40
- @sp2.write('hello')
41
- # small delay so it can write to the other port.
42
- sleep 0.1
43
- check = @sp.read(5)
44
- expect(check).to eql('hello')
45
- end
46
-
47
- it "should convert ints to strings" do
48
- expect(@sp2.write(123)).to eql(3)
49
- sleep 0.1
50
- expect(@sp.read(3)).to eql('123')
51
- end
52
-
53
- it "write should return bytes written" do
54
- expect(@sp2.write('hello')).to eql(5)
55
- end
56
-
57
- it "reading nothing should be blank" do
58
- expect(@sp.read(5)).to be_nil
59
- end
60
-
61
- it "should give me nil on getbyte" do
62
- expect(@sp.getbyte).to be_nil
63
- end
64
-
65
- it 'should give me a zero byte from getbyte' do
66
- @sp2.write("\x00")
67
- sleep 0.1
68
- expect(@sp.getbyte).to eql(0)
69
- end
70
-
71
- it "should give me bytes" do
72
- @sp2.write('hello')
73
- # small delay so it can write to the other port.
74
- sleep 0.1
75
- check = @sp.getbyte
76
- expect([check].pack('C')).to eql('h')
77
- end
78
-
79
- describe "giving me lines" do
80
- it "should give me a line" do
81
- @sp.write("no yes \n hello")
82
- sleep 0.1
83
- expect(@sp2.gets).to eql("no yes \n")
84
- end
85
-
86
- it "should give me a line with block" do
87
- @sp.write("no yes \n hello")
88
- sleep 0.1
89
- result = ""
90
- @sp2.each_line do |line|
91
- result = line
92
- break if !result.empty?
93
- end
94
- expect(result).to eql("no yes \n")
95
- end
96
-
97
- it "should accept a sep param" do
98
- @sp.write('no yes END bleh')
99
- sleep 0.1
100
- expect(@sp2.gets('END')).to eql("no yes END")
101
- end
102
-
103
- it "should accept a limit param" do
104
- @sp.write("no yes \n hello")
105
- sleep 0.1
106
- expect(@sp2.gets(4)).to eql("no y")
107
- end
108
-
109
- it "should accept limit and sep params" do
110
- @sp.write("no yes END hello")
111
- sleep 0.1
112
- expect(@sp2.gets('END', 20)).to eql("no yes END")
113
- @sp2.read(1000)
114
- @sp.write("no yes END hello")
115
- sleep 0.1
116
- expect(@sp2.gets('END', 4)).to eql('no y')
117
- end
118
-
119
- it "should read a paragraph at a time" do
120
- @sp.write("Something \n Something else \n\n and other stuff")
121
- sleep 0.1
122
- expect(@sp2.gets('')).to eql("Something \n Something else \n\n")
123
- end
124
- end
125
-
126
- describe 'config' do
127
- it 'should accept EVEN parity' do
128
- @sp2.close
129
- @sp.close
130
- @sp2 = CCutrer::SerialPort.new(@ports[0], baud: 19200, data_bits: 8, parity: :even)
131
- @sp = CCutrer::SerialPort.new(@ports[1], baud: 19200, data_bits: 8, parity: :even)
132
- @sp.write("Hello!\n")
133
- sleep 0.1
134
- expect(@sp2.gets).to eql("Hello!\n")
135
- end
136
-
137
- it 'should accept ODD parity' do
138
- @sp2.close
139
- @sp.close
140
- @sp2 = CCutrer::SerialPort.new(@ports[0], baud: 19200, data_bits: 8, parity: :odd)
141
- @sp = CCutrer::SerialPort.new(@ports[1], baud: 19200, data_bits: 8, parity: :odd)
142
- @sp.write("Hello!\n")
143
- sleep 0.1
144
- expect(@sp2.gets).to eql("Hello!\n")
145
- end
146
-
147
- it 'should accept 1 stop bit' do
148
- @sp2.close
149
- @sp.close
150
- @sp2 = CCutrer::SerialPort.new(@ports[0], baud: 19200, data_bits: 8, parity: :none, stop_bits: 1)
151
- @sp = CCutrer::SerialPort.new(@ports[1], baud: 19200, data_bits: 8, parity: :none, stop_bits: 1)
152
- @sp.write("Hello!\n")
153
- sleep 0.1
154
- expect(@sp2.gets).to eql("Hello!\n")
155
- end
156
-
157
- it 'should accept 2 stop bits' do
158
- @sp2.close
159
- @sp.close
160
- @sp2 = CCutrer::SerialPort.new(@ports[0], baud: 19200, data_bits: 8, parity: :none, stop_bits: 2)
161
- @sp = CCutrer::SerialPort.new(@ports[1], baud: 19200, data_bits: 8, parity: :none, stop_bits: 2)
162
- @sp.write("Hello!\n")
163
- sleep 0.1
164
- expect(@sp2.gets).to eql("Hello!\n")
165
- end
166
-
167
- it 'should set baud rate, check #46 fixed' do
168
- @sp.close
169
- rate = 600
170
- @sp = CCutrer::SerialPort.new(@ports[1], baud: rate)
171
- fd = @sp.fileno
172
- termios = CCutrer::SerialPort::Posix::Termios.new
173
- CCutrer::SerialPort::Posix.tcgetattr(fd, termios)
174
- expect(termios[:c_ispeed]).to eql(CCutrer::SerialPort::Posix::BAUD_RATES[rate])
175
- end
176
- end
177
- end
data/spec/spec_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- RSpec.configure do |config|
2
- end