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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ffi-serial/posix.rb +37 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3202efbedc0fb5ee6984b9f2f338b2594e216788
4
- data.tar.gz: 759504a859ecc078d47316b89eb19a5f25940d41
3
+ metadata.gz: 4df3ee55c469455ed931dcfd49c71841ff9e990a
4
+ data.tar.gz: 96dac10a98e36b7109978e98cc600caf9d2d5a22
5
5
  SHA512:
6
- metadata.gz: 06650bbfcf4d148d086a475b2d13779a184f7c126f44363fe475c4e272e45e0266834f02d68b4afb78371e5f2109ea282ff27b2ab37e6932afa582caa1a2e37c
7
- data.tar.gz: 0bebc5200e44b6fb342429a9f82f500d2fa5f5951edb1c653780544d05d30146eef3062474d6cbd388b38b254a7c8053220f2f09d7dee687fea35112b2a31a19
6
+ metadata.gz: 0ba5fa92d9da8438db7474d90c32e57ecd1df4b4b125f592169da0f97a2946eecedaf430e32e23b0329306b7fc7e20b0957e4f6d38a83f5bd1f06e928ea34f4e
7
+ data.tar.gz: f6406a1f629b0ecc288ba678de3085947f04846da621f06b32bba3997189b9b1b91fdec671bee471ef13bf06f143696b711428d61ff4159607a1b671b712b218
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan van der Vyver