rs_232 2.3.2.pre → 3.0.0.pre2
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 +4 -4
- data/LICENSE.txt +2 -2
- data/Rakefile +29 -7
- data/ext/rs_232/Constants.c +50 -0
- data/ext/rs_232/Constants.h +97 -0
- data/ext/rs_232/{initializer.c → Rs232.cpp} +111 -144
- data/ext/rs_232/{initializer.h → Rs232.h} +45 -36
- data/ext/rs_232/Structs.h +63 -0
- data/ext/rs_232/extconf.rb +10 -6
- data/ext/rs_232/posix/{port.c → Port.c} +94 -150
- data/ext/rs_232/posix/{port.h → Port.h} +39 -30
- data/ext/rs_232/windows/{port.c → Port.c} +99 -102
- data/ext/rs_232/windows/{port.h → Port.h} +39 -30
- data/lib/rs_232/version.rb +1 -1
- data/lib/rs_232.rb +94 -2
- data/rs_232.gemspec +12 -3
- metadata +52 -38
- data/ext/rs_232/constants.c +0 -49
- data/ext/rs_232/constants.h +0 -95
- data/ext/rs_232/structs.h +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bcb80fd72cfb4f47935134fbe73abc7594b289c
|
4
|
+
data.tar.gz: 949a14cb21434e5a3af56701e265f44c06a50966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01e9454ede82eb0905af93a07e30783917e003f552e99f5bf5cedb1d253ab8e85c17bc5c684e46c5221bd25c91bd983ef13162d538ca4e3a94428b94f09ae07c
|
7
|
+
data.tar.gz: ae532ffee6ab6490641e6cbb32568ce0a357b30135980f6ddebe962a9751f19f4563ddccb4049a7c188bb1a6a6b6195d5516302e993bee28facda3203830ef49
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2013,
|
1
|
+
Copyright (c) 2013, Roman Lishtaba.
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -16,7 +16,7 @@ included in all copies or substantial portions of the Software.
|
|
16
16
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
17
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
18
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
|
19
|
+
NONINFINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,13 +1,35 @@
|
|
1
1
|
lib = File.expand_path '../lib', __FILE__
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include? lib
|
3
|
+
|
3
4
|
require 'bundler/setup'
|
4
5
|
require 'bundler/gem_tasks'
|
5
|
-
require 'rake'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
require 'rake/extensiontask'
|
8
|
+
Rake::ExtensionTask.new('rs_232') do |ext|
|
9
|
+
ext.name = 'rs_232_native'
|
10
|
+
ext.source_pattern = '*.{c,cpp}'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rake/clean'
|
14
|
+
CLEAN.include %w(**/*.{log} doc coverage tmp pkg **/*.{o,so,bundle} Makefile)
|
15
|
+
|
16
|
+
require 'simplecov'
|
17
|
+
task :cov do
|
18
|
+
ENV['SIMPLECOV'] = 'features'
|
19
|
+
Rake::Task['default'].invoke
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'cucumber/rake/task'
|
23
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
24
|
+
t.fork = true
|
25
|
+
t.profile = :default
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new do |t|
|
30
|
+
t.fail_on_error = false
|
31
|
+
t.verbose = true
|
32
|
+
t.rspec_opts = '--format RspecJunitFormatter --out rspec.xml --tag ~wip'
|
33
|
+
end
|
12
34
|
|
13
|
-
task default: [:clobber, :compile, :spec
|
35
|
+
task default: [:clobber, :compile, :spec]
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2013, Roman Lishtaba.
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
|
5
|
+
* provided that the above copyright notice and this permission notice appear in all copies.
|
6
|
+
*
|
7
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
8
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
9
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
10
|
+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
11
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
12
|
+
*
|
13
|
+
**/
|
14
|
+
|
15
|
+
/*
|
16
|
+
* @author Roman Lishtaba
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "Constants.h"
|
20
|
+
|
21
|
+
void Constants_Init(VALUE namespace)
|
22
|
+
{
|
23
|
+
rb_define_const(namespace, "BAUD_110", INT2FIX(BAUD110));
|
24
|
+
rb_define_const(namespace, "BAUD_300", INT2FIX(BAUD300));
|
25
|
+
rb_define_const(namespace, "BAUD_600", INT2FIX(BAUD600));
|
26
|
+
rb_define_const(namespace, "BAUD_1200", INT2FIX(BAUD1200));
|
27
|
+
rb_define_const(namespace, "BAUD_2400", INT2FIX(BAUD2400));
|
28
|
+
rb_define_const(namespace, "BAUD_4800", INT2FIX(BAUD4800));
|
29
|
+
rb_define_const(namespace, "BAUD_9600", INT2FIX(BAUD9600));
|
30
|
+
rb_define_const(namespace, "BAUD_19200", INT2FIX(BAUD19200));
|
31
|
+
rb_define_const(namespace, "BAUD_38400", INT2FIX(BAUD38400));
|
32
|
+
rb_define_const(namespace, "BAUD_57600", INT2FIX(BAUD57600));
|
33
|
+
rb_define_const(namespace, "BAUD_115200", INT2FIX(BAUD115200));
|
34
|
+
|
35
|
+
rb_define_const(namespace, "DATA_BITS_5", INT2FIX(DATA_5));
|
36
|
+
rb_define_const(namespace, "DATA_BITS_6", INT2FIX(DATA_6));
|
37
|
+
rb_define_const(namespace, "DATA_BITS_7", INT2FIX(DATA_7));
|
38
|
+
rb_define_const(namespace, "DATA_BITS_8", INT2FIX(DATA_8));
|
39
|
+
|
40
|
+
rb_define_const(namespace, "PAR_NONE", INT2FIX(PAR_NONE));
|
41
|
+
rb_define_const(namespace, "PAR_ODD", INT2FIX(PAR_ODD));
|
42
|
+
rb_define_const(namespace, "PAR_EVEN", INT2FIX(PAR_EVEN));
|
43
|
+
|
44
|
+
rb_define_const(namespace, "STOP_BITS_1", INT2FIX(STOP_1));
|
45
|
+
rb_define_const(namespace, "STOP_BITS_3", INT2FIX(STOP_2));
|
46
|
+
|
47
|
+
rb_define_const(namespace, "FLOW_OFF", INT2FIX(FLOW_OFF));
|
48
|
+
rb_define_const(namespace, "FLOW_HARDWARE", INT2FIX(FLOW_HARDWARE));
|
49
|
+
rb_define_const(namespace, "FLOW_XONXOFF", INT2FIX(FLOW_XONXOFF));
|
50
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2013, Roman Lishtaba.
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
|
5
|
+
* provided that the above copyright notice and this permission notice appear in all copies.
|
6
|
+
*
|
7
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
8
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
9
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
10
|
+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
11
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
12
|
+
*
|
13
|
+
**/
|
14
|
+
|
15
|
+
/*
|
16
|
+
* @author Roman Lishtaba
|
17
|
+
*/
|
18
|
+
|
19
|
+
#pragma once
|
20
|
+
|
21
|
+
#ifdef __cplusplus
|
22
|
+
extern "C" {
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#include <ruby.h>
|
26
|
+
|
27
|
+
#define LS_CTS 0x01
|
28
|
+
#define LS_DSR 0x02
|
29
|
+
#define LS_DCD 0x04
|
30
|
+
#define LS_RI 0x08
|
31
|
+
#define LS_RTS 0x10
|
32
|
+
#define LS_DTR 0x20
|
33
|
+
#define LS_ST 0x40
|
34
|
+
#define LS_SR 0x80
|
35
|
+
|
36
|
+
enum { PORT_OPEN, PORT_CLOSED };
|
37
|
+
|
38
|
+
enum BaudRateType
|
39
|
+
{
|
40
|
+
BAUD110 = 110,
|
41
|
+
BAUD300 = 300,
|
42
|
+
BAUD600 = 600,
|
43
|
+
BAUD1200 = 1200,
|
44
|
+
BAUD2400 = 2400,
|
45
|
+
BAUD4800 = 4800,
|
46
|
+
BAUD9600 = 9600,
|
47
|
+
BAUD19200 = 19200,
|
48
|
+
BAUD38400 = 38400,
|
49
|
+
BAUD57600 = 57600,
|
50
|
+
BAUD115200 = 115200
|
51
|
+
};
|
52
|
+
|
53
|
+
enum DataBitsType
|
54
|
+
{
|
55
|
+
DATA_5 = 5,
|
56
|
+
DATA_6,
|
57
|
+
DATA_7,
|
58
|
+
DATA_8
|
59
|
+
};
|
60
|
+
|
61
|
+
enum ParityType
|
62
|
+
{
|
63
|
+
PAR_NONE,
|
64
|
+
PAR_ODD,
|
65
|
+
PAR_EVEN,
|
66
|
+
};
|
67
|
+
|
68
|
+
enum StopBitsType
|
69
|
+
{
|
70
|
+
STOP_1 = 1,
|
71
|
+
STOP_2
|
72
|
+
};
|
73
|
+
|
74
|
+
enum FlowType
|
75
|
+
{
|
76
|
+
FLOW_OFF,
|
77
|
+
FLOW_HARDWARE,
|
78
|
+
FLOW_XONXOFF
|
79
|
+
};
|
80
|
+
|
81
|
+
enum SettingsFlags
|
82
|
+
{
|
83
|
+
T_BaudRate = 0x0001,
|
84
|
+
T_Parity = 0x0002,
|
85
|
+
T_StopBits = 0x0004,
|
86
|
+
T_DataBits = 0x0008,
|
87
|
+
T_Flow = 0x0010,
|
88
|
+
T_TimeOut = 0x0100,
|
89
|
+
T_ALL = 0x0fff,
|
90
|
+
T_SettingsDone = 0x00ff,
|
91
|
+
};
|
92
|
+
|
93
|
+
void Constants_Init(VALUE);
|
94
|
+
|
95
|
+
#ifdef __cplusplus
|
96
|
+
}
|
97
|
+
#endif
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2013,
|
2
|
+
* Copyright (c) 2013, Roman Lishtaba.
|
3
3
|
*
|
4
4
|
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
|
5
5
|
* provided that the above copyright notice and this permission notice appear in all copies.
|
@@ -10,45 +10,44 @@
|
|
10
10
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
11
11
|
* PERFORMANCE OF THIS SOFTWARE.
|
12
12
|
*
|
13
|
-
|
13
|
+
*/
|
14
14
|
|
15
|
-
|
15
|
+
/*
|
16
|
+
* @author Roman Lishtaba
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "Rs232.h"
|
16
20
|
|
17
21
|
static void destructor(PortDescriptor *port)
|
18
22
|
{
|
19
23
|
xfree(port);
|
20
24
|
}
|
21
25
|
|
22
|
-
|
23
26
|
static void markDescriptor(PortDescriptor *port)
|
24
27
|
{
|
28
|
+
//noop
|
25
29
|
}
|
26
30
|
|
27
31
|
|
28
32
|
static VALUE allocateStruct(VALUE self)
|
29
33
|
{
|
30
|
-
PortDescriptor *port;
|
31
|
-
|
34
|
+
PortDescriptor *port = NULL;
|
32
35
|
rb_iv_set(self, "@port", Qnil);
|
33
|
-
|
36
|
+
|
34
37
|
return Data_Make_Struct(self, PortDescriptor, markDescriptor, destructor, port);
|
35
38
|
}
|
36
39
|
|
37
40
|
|
38
41
|
void setBaudRate(VALUE self, VALUE int_baudRate)
|
39
42
|
{
|
43
|
+
Check_Type(int_baudRate, T_FIXNUM);
|
44
|
+
|
40
45
|
PortDescriptor *port;
|
41
|
-
|
42
|
-
{
|
43
|
-
Check_Type(int_baudRate, T_FIXNUM);
|
44
|
-
}
|
45
|
-
|
46
46
|
int baudRate = FIX2INT(int_baudRate);
|
47
|
-
|
48
|
-
Data_Get_Struct(self, PortDescriptor, port);
|
49
|
-
|
50
47
|
int baud = 110;
|
51
|
-
|
48
|
+
|
49
|
+
Data_Get_Struct(self, PortDescriptor, port);
|
50
|
+
|
52
51
|
switch (baudRate)
|
53
52
|
{
|
54
53
|
case BAUD110:
|
@@ -85,10 +84,10 @@ void setBaudRate(VALUE self, VALUE int_baudRate)
|
|
85
84
|
rb_raise(rb_eException, "BaudRate value does not match specification, current: %d", baudRate);
|
86
85
|
break;
|
87
86
|
}
|
88
|
-
|
87
|
+
|
89
88
|
port->settings.BaudRate = (enum BaudRateType) baud;
|
90
89
|
port->toBeUpdated |= T_BaudRate;
|
91
|
-
|
90
|
+
|
92
91
|
updateSettings(port);
|
93
92
|
}
|
94
93
|
|
@@ -96,28 +95,21 @@ void setBaudRate(VALUE self, VALUE int_baudRate)
|
|
96
95
|
VALUE getBaudRate(VALUE self)
|
97
96
|
{
|
98
97
|
PortDescriptor *port;
|
99
|
-
|
100
98
|
Data_Get_Struct(self, PortDescriptor, port);
|
101
|
-
|
99
|
+
|
102
100
|
return INT2FIX(port->settings.BaudRate);
|
103
101
|
}
|
104
102
|
|
105
103
|
|
106
104
|
void setParity(VALUE self, VALUE int_parity)
|
107
105
|
{
|
108
|
-
|
109
|
-
|
110
|
-
Check_Type(int_parity, T_FIXNUM);
|
111
|
-
}
|
112
|
-
|
113
|
-
int parity = FIX2INT(int_parity);
|
114
|
-
|
106
|
+
Check_Type(int_parity, T_FIXNUM);
|
107
|
+
|
115
108
|
PortDescriptor *port;
|
116
|
-
|
117
109
|
Data_Get_Struct(self, PortDescriptor, port);
|
118
|
-
|
110
|
+
int parity = FIX2INT(int_parity);
|
119
111
|
enum ParityType parity_type = PAR_NONE;
|
120
|
-
|
112
|
+
|
121
113
|
switch (parity)
|
122
114
|
{
|
123
115
|
case PAR_NONE:
|
@@ -133,40 +125,31 @@ void setParity(VALUE self, VALUE int_parity)
|
|
133
125
|
rb_raise(rb_eException, "Parity value does not match specification, current: %d", parity);
|
134
126
|
break;
|
135
127
|
}
|
136
|
-
|
128
|
+
|
137
129
|
port->settings.Parity = parity_type;
|
138
130
|
port->toBeUpdated |= T_Parity;
|
139
|
-
|
131
|
+
|
140
132
|
updateSettings(port);
|
141
133
|
}
|
142
134
|
|
143
135
|
|
144
136
|
VALUE getParity(VALUE self)
|
145
137
|
{
|
146
|
-
|
147
138
|
PortDescriptor *port;
|
148
|
-
|
149
139
|
Data_Get_Struct(self, PortDescriptor, port);
|
150
|
-
|
140
|
+
|
151
141
|
return INT2FIX(port->settings.Parity);
|
152
142
|
}
|
153
143
|
|
154
144
|
|
155
145
|
void setDataBits(VALUE self, VALUE intDataBits)
|
156
146
|
{
|
157
|
-
|
158
|
-
{
|
159
|
-
Check_Type(intDataBits, T_FIXNUM);
|
160
|
-
}
|
161
|
-
|
162
|
-
int dataBits = FIX2INT(intDataBits);
|
163
|
-
|
147
|
+
Check_Type(intDataBits, T_FIXNUM);
|
164
148
|
PortDescriptor *port;
|
165
|
-
|
166
149
|
Data_Get_Struct(self, PortDescriptor, port);
|
167
|
-
|
150
|
+
int dataBits = FIX2INT(intDataBits);
|
168
151
|
enum DataBitsType dataBitsType = DATA_8;
|
169
|
-
|
152
|
+
|
170
153
|
switch (dataBits)
|
171
154
|
{
|
172
155
|
case DATA_5:
|
@@ -185,40 +168,32 @@ void setDataBits(VALUE self, VALUE intDataBits)
|
|
185
168
|
rb_raise(rb_eException, "DataBits value does not match specification, current: %d", dataBits);
|
186
169
|
break;
|
187
170
|
}
|
188
|
-
|
171
|
+
|
189
172
|
port->settings.DataBits = dataBitsType;
|
190
173
|
port->toBeUpdated |= T_DataBits;
|
191
|
-
|
174
|
+
|
192
175
|
updateSettings(port);
|
193
176
|
}
|
194
177
|
|
195
178
|
|
196
179
|
VALUE getDataBits(VALUE self)
|
197
180
|
{
|
198
|
-
|
199
181
|
PortDescriptor *port;
|
200
|
-
|
201
182
|
Data_Get_Struct(self, PortDescriptor, port);
|
202
|
-
|
183
|
+
|
203
184
|
return INT2FIX(port->settings.DataBits);
|
204
185
|
}
|
205
186
|
|
206
187
|
|
207
188
|
void setStopBits(VALUE self, VALUE intStopBits)
|
208
189
|
{
|
209
|
-
|
210
|
-
|
211
|
-
Check_Type(intStopBits, T_FIXNUM);
|
212
|
-
}
|
213
|
-
|
214
|
-
int stopBits = FIX2INT(intStopBits);
|
215
|
-
|
190
|
+
Check_Type(intStopBits, T_FIXNUM);
|
191
|
+
|
216
192
|
PortDescriptor *port;
|
217
|
-
|
218
193
|
Data_Get_Struct(self, PortDescriptor, port);
|
219
|
-
|
194
|
+
int stopBits = FIX2INT(intStopBits);
|
220
195
|
enum StopBitsType stopBitsType = STOP_1;
|
221
|
-
|
196
|
+
|
222
197
|
switch (stopBits)
|
223
198
|
{
|
224
199
|
case STOP_1:
|
@@ -231,40 +206,31 @@ void setStopBits(VALUE self, VALUE intStopBits)
|
|
231
206
|
rb_raise(rb_eException, "StopBits value does not match specification, current: %d", stopBits);
|
232
207
|
break;
|
233
208
|
}
|
234
|
-
|
209
|
+
|
235
210
|
port->settings.StopBits = stopBitsType;
|
236
211
|
port->toBeUpdated |= T_StopBits;
|
237
|
-
|
212
|
+
|
238
213
|
updateSettings(port);
|
239
214
|
}
|
240
215
|
|
241
216
|
|
242
217
|
VALUE getStopBits(VALUE self)
|
243
218
|
{
|
244
|
-
|
245
219
|
PortDescriptor *port;
|
246
|
-
|
247
220
|
Data_Get_Struct(self, PortDescriptor, port);
|
248
|
-
|
221
|
+
|
249
222
|
return INT2FIX(port->settings.StopBits);
|
250
223
|
}
|
251
224
|
|
252
225
|
|
253
226
|
void setFlowControl(VALUE self, VALUE intFlow)
|
254
227
|
{
|
255
|
-
|
256
|
-
{
|
257
|
-
Check_Type(intFlow, T_FIXNUM);
|
258
|
-
}
|
259
|
-
|
260
|
-
int flow = FIX2INT(intFlow);
|
261
|
-
|
228
|
+
Check_Type(intFlow, T_FIXNUM);
|
262
229
|
PortDescriptor *port;
|
263
|
-
|
264
230
|
Data_Get_Struct(self, PortDescriptor, port);
|
265
|
-
|
231
|
+
int flow = FIX2INT(intFlow);
|
266
232
|
enum FlowType flowType = FLOW_OFF;
|
267
|
-
|
233
|
+
|
268
234
|
switch (flow)
|
269
235
|
{
|
270
236
|
case FLOW_OFF:
|
@@ -280,119 +246,120 @@ void setFlowControl(VALUE self, VALUE intFlow)
|
|
280
246
|
rb_raise(rb_eException, "FlowControl value does not match specification, current: %d", flow);
|
281
247
|
break;
|
282
248
|
}
|
283
|
-
|
249
|
+
|
284
250
|
port->settings.FlowControl = flowType;
|
285
251
|
port->toBeUpdated |= T_StopBits;
|
286
|
-
|
252
|
+
|
287
253
|
updateSettings(port);
|
288
254
|
}
|
289
255
|
|
290
256
|
|
291
257
|
VALUE getFlowControl(VALUE self)
|
292
258
|
{
|
293
|
-
|
294
259
|
PortDescriptor *port;
|
295
|
-
|
296
260
|
Data_Get_Struct(self, PortDescriptor, port);
|
297
|
-
|
261
|
+
|
298
262
|
return INT2FIX(port->settings.FlowControl);
|
299
263
|
}
|
300
264
|
|
301
265
|
|
302
266
|
void setTimeout(VALUE self, VALUE rb_timeout)
|
303
267
|
{
|
304
|
-
|
305
|
-
{
|
306
|
-
Check_Type(rb_timeout, T_FIXNUM);
|
307
|
-
}
|
308
|
-
|
268
|
+
Check_Type(rb_timeout, T_FIXNUM);
|
309
269
|
PortDescriptor *port;
|
310
|
-
|
311
270
|
Data_Get_Struct(self, PortDescriptor, port);
|
312
|
-
|
313
271
|
long timeout = FIX2LONG(rb_timeout);
|
314
|
-
|
272
|
+
|
315
273
|
port->settings.Timeout_Millisec = timeout;
|
316
274
|
port->toBeUpdated |= T_TimeOut;
|
317
|
-
|
275
|
+
|
318
276
|
updateSettings(port);
|
319
277
|
}
|
320
278
|
|
321
|
-
|
279
|
+
/*
|
280
|
+
* Get connection timeout
|
281
|
+
*
|
282
|
+
* @return [Fixnum] the timeout value
|
283
|
+
* @see Impl#timeout
|
284
|
+
*/
|
322
285
|
VALUE getTimeout(VALUE self)
|
323
286
|
{
|
324
|
-
|
325
287
|
PortDescriptor *port;
|
326
|
-
|
327
288
|
Data_Get_Struct(self, PortDescriptor, port);
|
328
|
-
|
289
|
+
|
329
290
|
return INT2FIX(port->settings.Timeout_Millisec);
|
330
291
|
}
|
331
292
|
|
332
|
-
|
333
293
|
void setSettings(VALUE self)
|
334
294
|
{
|
335
|
-
|
336
295
|
PortDescriptor *port;
|
337
|
-
|
338
296
|
Data_Get_Struct(self, PortDescriptor, port);
|
339
|
-
|
297
|
+
|
340
298
|
setBaudRate(self, INT2FIX(port->settings.BaudRate));
|
341
299
|
setParity(self, INT2FIX(port->settings.Parity));
|
342
300
|
setDataBits(self, INT2FIX(port->settings.DataBits));
|
343
301
|
setStopBits(self, INT2FIX(port->settings.StopBits));
|
344
302
|
setFlowControl(self, INT2FIX(port->settings.FlowControl));
|
345
303
|
setTimeout(self, LONG2FIX(port->settings.Timeout_Millisec));
|
346
|
-
|
347
304
|
port->toBeUpdated = T_ALL;
|
348
|
-
|
305
|
+
|
349
306
|
updateSettings(port);
|
350
307
|
}
|
351
308
|
|
352
|
-
|
353
|
-
void Init_rs_232(void)
|
309
|
+
extern "C" void Init_rs_232_native(void)
|
354
310
|
{
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
rb_define_method(
|
380
|
-
|
381
|
-
|
382
|
-
rb_define_method(
|
383
|
-
|
384
|
-
|
385
|
-
rb_define_method(
|
386
|
-
rb_define_method(
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
rb_define_method(
|
392
|
-
rb_define_method(
|
393
|
-
|
394
|
-
rb_define_method(
|
395
|
-
rb_define_method(
|
396
|
-
|
397
|
-
|
311
|
+
const char rootModName[] = "Rs232";
|
312
|
+
const char implClassName[] = "Native";
|
313
|
+
const char constantsModName[] = "Constants";
|
314
|
+
const char VERSION[] = "2.0.0";
|
315
|
+
|
316
|
+
// define root Rs232 module
|
317
|
+
const VALUE root = rb_define_module(rootModName);
|
318
|
+
|
319
|
+
// define impl ruby class
|
320
|
+
const VALUE impl = rb_define_class_under(root, implClassName, rb_cObject);
|
321
|
+
|
322
|
+
// define module Constants under Native
|
323
|
+
const VALUE constants = rb_define_module_under(root, constantsModName);
|
324
|
+
|
325
|
+
// initialize constants in to module Native::Constants
|
326
|
+
Constants_Init(constants);
|
327
|
+
|
328
|
+
// define native version constant
|
329
|
+
rb_define_const(impl, "NATIVE_VERSION", rb_str_new2(VERSION));
|
330
|
+
|
331
|
+
rb_define_alloc_func(impl, allocateStruct);
|
332
|
+
|
333
|
+
rb_define_method(impl, "initialize", RUBY_METHOD_FUNC(initializeStruct), 1);
|
334
|
+
|
335
|
+
rb_define_method(impl, "baud_rate=", RUBY_METHOD_FUNC(setBaudRate), 1);
|
336
|
+
rb_define_method(impl, "baud_rate", RUBY_METHOD_FUNC(getBaudRate), 0);
|
337
|
+
|
338
|
+
rb_define_method(impl, "parity=", RUBY_METHOD_FUNC(setParity), 1);
|
339
|
+
rb_define_method(impl, "parity", RUBY_METHOD_FUNC(getParity), 0);
|
340
|
+
|
341
|
+
rb_define_method(impl, "data_bits=", RUBY_METHOD_FUNC(setDataBits), 1);
|
342
|
+
rb_define_method(impl, "data_bits", RUBY_METHOD_FUNC(getDataBits), 0);
|
343
|
+
|
344
|
+
rb_define_method(impl, "stop_bits=", RUBY_METHOD_FUNC(setStopBits), 1);
|
345
|
+
rb_define_method(impl, "stop_bits", RUBY_METHOD_FUNC(getStopBits), 0);
|
346
|
+
|
347
|
+
rb_define_method(impl, "flow_control=", RUBY_METHOD_FUNC(setFlowControl), 1);
|
348
|
+
rb_define_method(impl, "flow_control", RUBY_METHOD_FUNC(getFlowControl), 0);
|
349
|
+
|
350
|
+
rb_define_method(impl, "timeout=", RUBY_METHOD_FUNC(setTimeout), 1);
|
351
|
+
rb_define_method(impl, "timeout", RUBY_METHOD_FUNC(getTimeout), 0);
|
352
|
+
|
353
|
+
rb_define_method(impl, "open", RUBY_METHOD_FUNC(openIO), 0);
|
354
|
+
rb_define_method(impl, "close", RUBY_METHOD_FUNC(closeIO), 0);
|
355
|
+
rb_define_method(impl, "flush", RUBY_METHOD_FUNC(flushIO), 0);
|
356
|
+
rb_define_method(impl, "open?", RUBY_METHOD_FUNC(isOpenIO), 0);
|
357
|
+
|
358
|
+
rb_define_method(impl, "write", RUBY_METHOD_FUNC(writeIO), 1);
|
359
|
+
rb_define_method(impl, "read", RUBY_METHOD_FUNC(readIO), 1);
|
360
|
+
rb_define_method(impl, "available?", RUBY_METHOD_FUNC(bytesAvailableIO), 0);
|
361
|
+
|
362
|
+
rb_define_method(impl, "line_status", RUBY_METHOD_FUNC(lineStatusIO), 0);
|
363
|
+
rb_define_method(impl, "set_rts", RUBY_METHOD_FUNC(setRtsIO), 1);
|
364
|
+
rb_define_method(impl, "set_dtr", RUBY_METHOD_FUNC(setDtrIO), 1);
|
398
365
|
}
|