rb232 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +5 -3
  2. data/src/port.c +24 -18
  3. metadata +1 -1
data/README CHANGED
@@ -30,8 +30,8 @@ license, so you can do anything you like with it.
30
30
  == STATUS
31
31
 
32
32
  Currently you can read from a serial port, but not write back. The code is only
33
- tested on Linux - other unixes *may* work, Mac OSX *might* be ok, but Windows
34
- is right out for now. Watch this space for further developments!
33
+ tested on Linux and Snow Leopard - other unixes *may* work, but Windows is right
34
+ out for now. Watch this space for further developments!
35
35
 
36
36
  == USAGE
37
37
 
@@ -49,6 +49,8 @@ You can provide alternative settings when you create a new port:
49
49
  :stop_bits => 2,
50
50
  :hardware_flow_control => true)
51
51
 
52
+ Note that OSX doesn't currently have hardware flow control support.
53
+
52
54
  See http://github.com/Floppy/rb232/tree/master/spec/port_spec.rb or RB232::Port
53
55
  documentation for more details.
54
56
 
@@ -56,4 +58,4 @@ If you are using a simple text protocol over RS232, you can use the
56
58
  RB232::TextProtocol class to help you out. It automatically monitors the port
57
59
  and splits messages up by detecting separator characters. See
58
60
  http://github.com/Floppy/rb232/tree/master/examples/listen.rb for an example of
59
- how to use this class.
61
+ how to use this class.
data/src/port.c CHANGED
@@ -77,63 +77,66 @@ VALUE rb232_port_initialize_with_options(VALUE self, VALUE port, VALUE options)
77
77
  rb_raise(rb_eArgError, "couldn't open the specified port");
78
78
  }
79
79
  /* Set port settings */
80
+ cfmakeraw(&(port_data->settings));
80
81
  port_data->settings.c_cflag = CRTSCTS | CLOCAL | CREAD;
81
82
  /* Baud rate */
83
+ speed_t speed = B0;
82
84
  switch (port_data->baud_rate) {
83
85
  case 0:
84
- port_data->settings.c_cflag |= B0;
86
+ speed = B0;
85
87
  break;
86
88
  case 50:
87
- port_data->settings.c_cflag |= B50;
89
+ speed = B50;
88
90
  break;
89
91
  case 75:
90
- port_data->settings.c_cflag |= B75;
92
+ speed = B75;
91
93
  break;
92
94
  case 110:
93
- port_data->settings.c_cflag |= B110;
95
+ speed = B110;
94
96
  break;
95
97
  case 134:
96
- port_data->settings.c_cflag |= B134;
98
+ speed = B134;
97
99
  break;
98
100
  case 150:
99
- port_data->settings.c_cflag |= B150;
101
+ speed = B150;
100
102
  break;
101
103
  case 200:
102
- port_data->settings.c_cflag |= B200;
104
+ speed = B200;
103
105
  break;
104
106
  case 300:
105
- port_data->settings.c_cflag |= B300;
107
+ speed = B300;
106
108
  break;
107
109
  case 600:
108
- port_data->settings.c_cflag |= B600;
110
+ speed = B600;
109
111
  break;
110
112
  case 1200:
111
- port_data->settings.c_cflag |= B1200;
113
+ speed = B1200;
112
114
  break;
113
115
  case 1800:
114
- port_data->settings.c_cflag |= B1800;
116
+ speed = B1800;
115
117
  break;
116
118
  case 2400:
117
- port_data->settings.c_cflag |= B2400;
119
+ speed = B2400;
118
120
  break;
119
121
  case 4800:
120
- port_data->settings.c_cflag |= B4800;
122
+ speed = B4800;
121
123
  break;
122
124
  case 9600:
123
- port_data->settings.c_cflag |= B9600;
125
+ speed = B9600;
124
126
  break;
125
127
  case 19200:
126
- port_data->settings.c_cflag |= B19200;
128
+ speed = B19200;
127
129
  break;
128
130
  case 38400:
129
- port_data->settings.c_cflag |= B38400;
131
+ speed = B38400;
130
132
  break;
131
133
  case 57600:
132
- port_data->settings.c_cflag |= B57600;
134
+ speed = B57600;
133
135
  break;
134
136
  default:
135
137
  rb_raise(rb_eArgError, "baud_rate must be a valid value");
136
138
  }
139
+ cfsetspeed(&(port_data->settings), speed);
137
140
  /* Data bits */
138
141
  switch (port_data->data_bits) {
139
142
  case 8:
@@ -150,7 +153,7 @@ VALUE rb232_port_initialize_with_options(VALUE self, VALUE port, VALUE options)
150
153
  break;
151
154
  default:
152
155
  rb_raise(rb_eArgError, "data_bits must be 5, 6, 7 or 8");
153
- }
156
+ }
154
157
  /* Parity */
155
158
  if (port_data->parity) port_data->settings.c_cflag |= PARENB;
156
159
  /* Stop bits */
@@ -163,8 +166,10 @@ VALUE rb232_port_initialize_with_options(VALUE self, VALUE port, VALUE options)
163
166
  default:
164
167
  rb_raise(rb_eArgError, "stop_bits must be 1 or 2");
165
168
  }
169
+ #ifdef CNEW_RTSCTS
166
170
  /* Flow control */
167
171
  if (port_data->hardware_flow_control) port_data->settings.c_cflag |= CNEW_RTSCTS;
172
+ #endif
168
173
  /* Other settings */
169
174
  port_data->settings.c_iflag = IGNPAR | ICRNL;
170
175
  port_data->settings.c_oflag = 0;
@@ -301,6 +306,7 @@ VALUE rb232_port_read_bytes(VALUE self, VALUE count) {
301
306
  */
302
307
  VALUE rb232_port_read_string(VALUE self, VALUE count) {
303
308
  char buffer[256];
309
+ memset(buffer, 0, 256);
304
310
  int bytes_read = rb232_port_read(self, buffer, count);
305
311
  if (bytes_read < 1) bytes_read = 0;
306
312
  buffer[bytes_read] = 0;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb232
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith