ffi-serial 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ffi-serial/posix.rb +37 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4df3ee55c469455ed931dcfd49c71841ff9e990a
|
4
|
+
data.tar.gz: 96dac10a98e36b7109978e98cc600caf9d2d5a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba5fa92d9da8438db7474d90c32e57ecd1df4b4b125f592169da0f97a2946eecedaf430e32e23b0329306b7fc7e20b0957e4f6d38a83f5bd1f06e928ea34f4e
|
7
|
+
data.tar.gz: f6406a1f629b0ecc288ba678de3085947f04846da621f06b32bba3997189b9b1b91fdec671bee471ef13bf06f143696b711428d61ff4159607a1b671b712b218
|
data/lib/ffi-serial/posix.rb
CHANGED
@@ -35,6 +35,7 @@ module Serial #:nodoc:
|
|
35
35
|
end
|
36
36
|
LIBC.cfsetispeed(termios, baud)
|
37
37
|
LIBC.cfsetospeed(termios, baud)
|
38
|
+
|
38
39
|
termios.data_bits = data_bits
|
39
40
|
termios.stop_bits = stop_bits
|
40
41
|
termios.parity = parity
|
@@ -48,12 +49,7 @@ module Serial #:nodoc:
|
|
48
49
|
termios[:c_iflag] = (termios[:c_iflag] | LIBC::CONSTANTS['IXON'] | LIBC::CONSTANTS['IXOFF'] | LIBC::CONSTANTS['IXANY'])
|
49
50
|
termios[:c_cflag] = (termios[:c_cflag] | LIBC::CONSTANTS['CLOCAL'] | LIBC::CONSTANTS['CREAD'] | LIBC::CONSTANTS['HUPCL'])
|
50
51
|
|
51
|
-
# non-blocking read
|
52
|
-
termios[:cc_c][LIBC::CONSTANTS['VMIN']] = 0
|
53
|
-
termios[:cc_c][LIBC::CONSTANTS['VTIME']] = 0
|
54
|
-
|
55
52
|
LIBC.tcsetattr(io, termios)
|
56
|
-
|
57
53
|
io.extend(self)
|
58
54
|
rescue Exception
|
59
55
|
begin; io.close; rescue Exception; end
|
@@ -62,6 +58,42 @@ module Serial #:nodoc:
|
|
62
58
|
io
|
63
59
|
end
|
64
60
|
|
61
|
+
# It seems like VMIN and VTIME is broken :(
|
62
|
+
# So this seems to be the only way to implement read the way it should be
|
63
|
+
def read(length = nil, buffer = nil) #:nodoc:
|
64
|
+
if length.nil?
|
65
|
+
IO.select([self]) # Block
|
66
|
+
|
67
|
+
if buffer.nil?
|
68
|
+
return super
|
69
|
+
else
|
70
|
+
return super(nil, buffer)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
read_count = 0
|
75
|
+
data_read = []
|
76
|
+
while(length > read_count)
|
77
|
+
IO.select([self]) # Block
|
78
|
+
data_read << (partial_read = super(length))
|
79
|
+
read_count += partial_read.length
|
80
|
+
end
|
81
|
+
|
82
|
+
data_read = data_read.join
|
83
|
+
return data_read if buffer.nil?
|
84
|
+
buffer.gsub!(buffer, data_read) # :sigh: not sure how to do this better
|
85
|
+
buffer
|
86
|
+
end
|
87
|
+
|
88
|
+
def readpartial(length, buffer = nil) #:nodoc:
|
89
|
+
IO.select([self]) # Block
|
90
|
+
if buffer.nil?
|
91
|
+
super(length)
|
92
|
+
else
|
93
|
+
super(length, buffer)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
65
97
|
def baud #:nodoc:
|
66
98
|
LIBC::CONSTANTS['BAUD_'].fetch(LIBC.cfgetispeed(LIBC.tcgetattr(self)))
|
67
99
|
end
|