serialport 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ /pkg
3
+ /doc
4
+ /ext/native/*.bundle
5
+ /ext/native/*.log
6
+ /ext/native/*.o
7
+ /ext/native/*.so
8
+ /ext/native/Makefile
9
+ .*.swp
10
+ tags
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
- 0.7.4 => 10/12/2009: Conditional 1.8.6 & 1.9 support (POSIX only). MinGW support.
1
+ 1.0.0 => 01/12/2010: Fixed x86_64 segmentation fault issues. Windows 1.9 support.
2
+
3
+ 0.7.4 => 10/12/2009: Conditional 1.8.6 & 1.9 support (POSIX only). MinGW support.
2
4
 
3
5
  0.7.3 => 10/09/2009: http://makrotopia.org/browser/makrosys/makrobe/ruby-serialport/patches/10-fix-for-ruby-1.9
4
6
  applied for 1.9 support (POSIX only)
data/LICENSE ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/MANIFEST CHANGED
@@ -1,11 +1,13 @@
1
1
  CHANGELOG
2
- README
3
2
  MANIFEST
3
+ README
4
+ Rakefile
4
5
  serialport.gemspec
5
- extconf.rb
6
+ VERSION
7
+ ext/native/extconf.rb
8
+ ext/native/posix_serialport_impl.c
9
+ ext/native/serialport.c
10
+ ext/native/serialport.h
11
+ ext/native/win_serialport_impl.c
6
12
  lib/serialport.rb
7
- src/posix_serialport_impl.c
8
- src/serialport.c
9
- src/serialport.h
10
- src/win_serialport_impl.c
11
- test/miniterm.rb
13
+ test/miniterm.rb
data/README CHANGED
@@ -154,3 +154,4 @@ Guillaume Pierronnet <moumar@netcourrier.com>
154
154
  Alan Stern <stern@rowland.harvard.edu>
155
155
  Tobin Richard <tobin.richard@gmail.com>
156
156
  Hector Parra <hector@hectorparra.com>
157
+ Ryan C. Payne <rpayne-oss@bullittsystems.com>
data/Rakefile CHANGED
@@ -9,11 +9,16 @@ begin
9
9
  gemspec.description = "Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports."
10
10
  gemspec.email = "hector@hectorparra.com"
11
11
  gemspec.homepage = 'http://github.com/hparra/ruby-serialport/'
12
- gemspec.authors = ['Guillaume Pierronnet', 'Alan Stern', 'Daniel E. Shipton', 'Tobin Richard']
13
- gemspec.has_rdoc = false
14
- gemspec.extensions << 'extconf.rb'
12
+ gemspec.authors = ['Guillaume Pierronnet', 'Alan Stern', 'Daniel E. Shipton', 'Tobin Richard', 'Hector Parra', 'Ryan C. Payne']
13
+ gemspec.has_rdoc = true
14
+ gemspec.extensions << 'ext/native/extconf.rb'
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
17
17
  rescue LoadError
18
18
  puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
19
+ end
20
+
21
+ task :clean do
22
+ rm_rf(Dir['doc'], :verbose => true)
23
+ rm_rf(Dir['pkg'], :verbose => true)
19
24
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 1.0.0
@@ -5,10 +5,10 @@ STDOUT.flush
5
5
  os = /-([a-z]+)/.match(RUBY_PLATFORM)[1]
6
6
  puts(os)
7
7
  $CFLAGS += " -DOS_#{os.upcase}"
8
- $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /^1\.9/
8
+ $CFLAGS += " -DRUBY_1_9" if RUBY_VERSION =~ /^1\.9/
9
9
 
10
10
  if !(os == 'mswin' or os == 'bccwin' or os == 'mingw')
11
11
  exit(1) if not have_header("termios.h") or not have_header("unistd.h")
12
12
  end
13
13
 
14
- create_makefile('serialport','src')
14
+ create_makefile('serialport')
@@ -1,7 +1,8 @@
1
- /* Ruby/SerialPort $Id$
1
+ /* Ruby/SerialPort
2
2
  * Guillaume Pierronnet <moumar@netcourrier.com>
3
3
  * Alan Stern <stern@rowland.harvard.edu>
4
4
  * Daniel E. Shipton <dshipton@redshiptechnologies.com>
5
+ * Ryan C. Payne <rpayne-oss@bullittsystems.com>
5
6
  *
6
7
  * This code is hereby licensed for public consumption under either the
7
8
  * GNU GPL v2 or greater.
@@ -43,26 +44,26 @@ static char sIoctl[] = "ioctl";
43
44
  int get_fd_helper(obj)
44
45
  VALUE obj;
45
46
  {
46
- #ifdef RUBY_19
47
- rb_io_t *fptr;
47
+ #ifdef RUBY_1_9
48
+ rb_io_t *fptr;
48
49
  #else
49
- OpenFile *fptr;
50
+ OpenFile *fptr;
50
51
  #endif
51
52
  GetOpenFile(obj, fptr);
52
- #ifdef RUBY_19
53
- return (fptr->fd);
53
+ #ifdef RUBY_1_9
54
+ return (fptr->fd);
54
55
  #else
55
- return (fileno(fptr->f));
56
+ return (fileno(fptr->f));
56
57
  #endif
57
58
  }
58
59
 
59
60
  VALUE sp_create_impl(class, _port)
60
61
  VALUE class, _port;
61
62
  {
62
- #ifdef RUBY_19
63
- rb_io_t *fp;
63
+ #ifdef RUBY_1_9
64
+ rb_io_t *fp;
64
65
  #else
65
- OpenFile *fp;
66
+ OpenFile *fp;
66
67
  #endif
67
68
 
68
69
  int fd;
@@ -72,8 +73,8 @@ VALUE sp_create_impl(class, _port)
72
73
  #if defined(OS_LINUX) || defined(OS_CYGWIN)
73
74
  "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3",
74
75
  "/dev/ttyS4", "/dev/ttyS5", "/dev/ttyS6", "/dev/ttyS7"
75
- #elif defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_OPENBSD)
76
- "/dev/cuaa0", "/dev/cuaa1", "/dev/cuaa2", "/dev/cuaa3",
76
+ #elif defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DARWIN)
77
+ "/dev/cuaa0", "/dev/cuaa1", "/dev/cuaa2", "/dev/cuaa3",
77
78
  "/dev/cuaa4", "/dev/cuaa5", "/dev/cuaa6", "/dev/cuaa7"
78
79
  #elif defined(OS_SOLARIS)
79
80
  "/dev/ttya", "/dev/ttyb", "/dev/ttyc", "/dev/ttyd",
@@ -106,10 +107,10 @@ VALUE sp_create_impl(class, _port)
106
107
 
107
108
  case T_STRING:
108
109
  Check_SafeStr(_port);
109
- #ifdef RUBY_19
110
- port = RSTRING_PTR(_port);
110
+ #ifdef RUBY_1_9
111
+ port = RSTRING_PTR(_port);
111
112
  #else
112
- port = RSTRING(_port)->ptr;
113
+ port = RSTRING(_port)->ptr;
113
114
  #endif
114
115
  break;
115
116
 
@@ -151,10 +152,10 @@ VALUE sp_create_impl(class, _port)
151
152
  rb_sys_fail(sTcsetattr);
152
153
  }
153
154
 
154
- #ifdef RUBY_19
155
- fp->fd = fd;
155
+ #ifdef RUBY_1_9
156
+ fp->fd = fd;
156
157
  #else
157
- fp->f = rb_fdopen(fd, "r+");
158
+ fp->f = rb_fdopen(fd, "r+");
158
159
  #endif
159
160
  fp->mode = FMODE_READWRITE | FMODE_SYNC;
160
161
 
@@ -1,7 +1,9 @@
1
- /* Ruby/SerialPort $Id$
1
+ /* Ruby/SerialPort
2
2
  * Guillaume Pierronnet <moumar@netcourrier.com>
3
3
  * Alan Stern <stern@rowland.harvard.edu>
4
4
  * Daniel E. Shipton <dshipton@redshiptechnologies.com>
5
+ * Jonas Bähr <jonas.baehr@fs.ei.tum.de>
6
+ * Ryan C. Payne <rpayne-oss@bullittsystems.com>
5
7
  *
6
8
  * This code is hereby licensed for public consumption under either the
7
9
  * GNU GPL v2 or greater.
@@ -24,6 +26,7 @@ VALUE sBaud, sDataBits, sStopBits, sParity; /* strings */
24
26
  VALUE sRts, sDtr, sCts, sDsr, sDcd, sRi;
25
27
 
26
28
  /*
29
+ * :nodoc: This method is private and will be called by SerialPort#new or SerialPort#open.
27
30
  */
28
31
  static VALUE sp_create(class, _port)
29
32
  VALUE class, _port;
@@ -32,6 +35,21 @@ static VALUE sp_create(class, _port)
32
35
  }
33
36
 
34
37
  /*
38
+ * Configure the serial port. You can pass a hash or multiple values
39
+ * as separate arguments. Invalid or unsupported values will raise
40
+ * an ArgumentError.
41
+ *
42
+ * When using a hash the following keys are recognized:
43
+ * ["baud"] Integer from 50 to 256000, depends on platform
44
+ * ["data_bits"] Integer from 5 to 8 (4 is allowed on Windows too)
45
+ * ["stop_bits"] An integer, only allowed values are 1 or 2 (1.5 is not supported)
46
+ * ["parity"] One of the constants NONE, EVEN or ODD (Windows allows also MARK and SPACE)
47
+ *
48
+ * When using separate arguments, they are interpreted as:
49
+ * (baud, data_bits = 8, stop_bits = 1, parity = (previous_databits==8 ? NONE : EVEN))
50
+ *
51
+ * Nota: A baudrate of nil will keep the old value. The default parity depends on the
52
+ * number of databits configured before this function call.
35
53
  */
36
54
  static VALUE sp_set_modem_params(argc, argv, self)
37
55
  int argc;
@@ -41,6 +59,11 @@ static VALUE sp_set_modem_params(argc, argv, self)
41
59
  }
42
60
 
43
61
  /*
62
+ * Send a break for the given time.
63
+ *
64
+ * <tt>time</tt> is an integer of tenths-of-a-second for the break.
65
+ *
66
+ * Note: Under Posix, this value is very approximate.
44
67
  */
45
68
  static VALUE sp_break(self, time)
46
69
  VALUE self, time;
@@ -49,6 +72,7 @@ static VALUE sp_break(self, time)
49
72
  }
50
73
 
51
74
  /*
75
+ * Get the state (0 or 1) of the DTR line (not available on Windows)
52
76
  */
53
77
  static VALUE sp_get_dtr(self)
54
78
  VALUE self;
@@ -57,6 +81,7 @@ static VALUE sp_get_dtr(self)
57
81
  }
58
82
 
59
83
  /*
84
+ * Get the flow control. The result is either NONE, HARD, SOFT or (HARD | SOFT)
60
85
  */
61
86
  static VALUE sp_get_flow_control(self)
62
87
  VALUE self;
@@ -65,6 +90,8 @@ static VALUE sp_get_flow_control(self)
65
90
  }
66
91
 
67
92
  /*
93
+ * Get the timeout value (in milliseconds) for reading.
94
+ * See SerialPort#set_read_timeout for details.
68
95
  */
69
96
  static VALUE sp_get_read_timeout(self)
70
97
  VALUE self;
@@ -73,6 +100,7 @@ static VALUE sp_get_read_timeout(self)
73
100
  }
74
101
 
75
102
  /*
103
+ * Get the state (0 or 1) of the RTS line (not available on Windows)
76
104
  */
77
105
  static VALUE sp_get_rts(self)
78
106
  VALUE self;
@@ -81,6 +109,9 @@ static VALUE sp_get_rts(self)
81
109
  }
82
110
 
83
111
  /*
112
+ * Get the write timeout (in milliseconds)
113
+ *
114
+ * Note: Under Posix, write timeouts are not implemented.
84
115
  */
85
116
  static VALUE sp_get_write_timeout(self)
86
117
  VALUE self;
@@ -89,36 +120,59 @@ static VALUE sp_get_write_timeout(self)
89
120
  }
90
121
 
91
122
  /*
123
+ * Set the state (0 or 1) of the DTR line
92
124
  */
93
125
  static VALUE sp_set_dtr(self, val)
126
+ VALUE self, val;
94
127
  {
95
128
  return sp_set_dtr_impl(self, val);
96
129
  }
97
130
 
98
131
  /*
132
+ * Set the flow control to either NONE, HARD, SOFT or (HARD | SOFT)
133
+ *
134
+ * Note: SerialPort::HARD mode is not supported on all platforms.
135
+ * SerialPort::HARD uses RTS/CTS handshaking; DSR/DTR is not
136
+ * supported.
99
137
  */
100
138
  static VALUE sp_set_flow_control(self, val)
139
+ VALUE self, val;
101
140
  {
102
141
  return sp_set_flow_control_impl(self, val);
103
142
  }
104
143
 
105
144
  /*
145
+ * Set the timeout value (in milliseconds) for reading.
146
+ * A negative read timeout will return all the available data without
147
+ * waiting, a zero read timeout will not return until at least one
148
+ * byte is available, and a positive read timeout returns when the
149
+ * requested number of bytes is available or the interval between the
150
+ * arrival of two bytes exceeds the timeout value.
151
+ *
152
+ * Note: Read timeouts don't mix well with multi-threading.
106
153
  */
107
154
  static VALUE sp_set_read_timeout(self, val)
155
+ VALUE self, val;
108
156
  {
109
157
  return sp_set_read_timeout_impl(self, val);
110
158
  }
111
159
 
112
160
  /*
161
+ * Set the state (0 or 1) of the RTS line
113
162
  */
114
163
  static VALUE sp_set_rts(self, val)
164
+ VALUE self, val;
115
165
  {
116
166
  return sp_set_rts_impl(self, val);
117
167
  }
118
168
 
119
169
  /*
170
+ * Set a write timeout (in milliseconds)
171
+ *
172
+ * Note: Under Posix, write timeouts are not implemented.
120
173
  */
121
174
  static VALUE sp_set_write_timeout(self, val)
175
+ VALUE self, val;
122
176
  {
123
177
  return sp_set_write_timeout_impl(self, val);
124
178
  }
@@ -133,6 +187,7 @@ static void get_modem_params(self, mp)
133
187
  }
134
188
 
135
189
  /*
190
+ * Set the baud rate, see SerialPort#set_modem_params for details.
136
191
  */
137
192
  static VALUE sp_set_data_rate(self, data_rate)
138
193
  VALUE self, data_rate;
@@ -147,6 +202,7 @@ static VALUE sp_set_data_rate(self, data_rate)
147
202
  }
148
203
 
149
204
  /*
205
+ * Set the data bits, see SerialPort#set_modem_params for details.
150
206
  */
151
207
  static VALUE sp_set_data_bits(self, data_bits)
152
208
  VALUE self, data_bits;
@@ -161,6 +217,7 @@ static VALUE sp_set_data_bits(self, data_bits)
161
217
  }
162
218
 
163
219
  /*
220
+ * Set the stop bits, see SerialPort#set_modem_params for details.
164
221
  */
165
222
  static VALUE sp_set_stop_bits(self, stop_bits)
166
223
  VALUE self, stop_bits;
@@ -175,6 +232,7 @@ static VALUE sp_set_stop_bits(self, stop_bits)
175
232
  }
176
233
 
177
234
  /*
235
+ * Set the parity, see SerialPort#set_modem_params for details.
178
236
  */
179
237
  static VALUE sp_set_parity(self, parity)
180
238
  VALUE self, parity;
@@ -189,6 +247,7 @@ static VALUE sp_set_parity(self, parity)
189
247
  }
190
248
 
191
249
  /*
250
+ * Get the current baud rate, see SerialPort#get_modem_params for details.
192
251
  */
193
252
  static VALUE sp_get_data_rate(self)
194
253
  VALUE self;
@@ -201,6 +260,7 @@ static VALUE sp_get_data_rate(self)
201
260
  }
202
261
 
203
262
  /*
263
+ * Get the current data bits, see SerialPort#get_modem_params for details.
204
264
  */
205
265
  static VALUE sp_get_data_bits(self)
206
266
  VALUE self;
@@ -213,6 +273,7 @@ static VALUE sp_get_data_bits(self)
213
273
  }
214
274
 
215
275
  /*
276
+ * Get the current stop bits, see SerialPort#get_modem_params for details.
216
277
  */
217
278
  static VALUE sp_get_stop_bits(self)
218
279
  VALUE self;
@@ -225,6 +286,7 @@ static VALUE sp_get_stop_bits(self)
225
286
  }
226
287
 
227
288
  /*
289
+ * Get the current parity, see SerialPort#get_modem_params for details.
228
290
  */
229
291
  static VALUE sp_get_parity(self)
230
292
  VALUE self;
@@ -237,6 +299,13 @@ static VALUE sp_get_parity(self)
237
299
  }
238
300
 
239
301
  /*
302
+ * Get the configure of the serial port.
303
+ *
304
+ * Returned is a hash with the following keys:
305
+ * ["baud"] Integer with the baud rate
306
+ * ["data_bits"] Integer from 5 to 8 (4 is possible on Windows too)
307
+ * ["stop_bits"] Integer, 1 or 2 (1.5 is not supported)
308
+ * ["parity"] One of the constants NONE, EVEN or ODD (on Windows may also MARK or SPACE)
240
309
  */
241
310
  static VALUE sp_get_modem_params(self)
242
311
  VALUE self;
@@ -264,6 +333,7 @@ void get_line_signals_helper(obj, ls)
264
333
  }
265
334
 
266
335
  /*
336
+ * Get the state (0 or 1) of the CTS line
267
337
  */
268
338
  static VALUE sp_get_cts(self)
269
339
  VALUE self;
@@ -276,6 +346,7 @@ static VALUE sp_get_cts(self)
276
346
  }
277
347
 
278
348
  /*
349
+ * Get the state (0 or 1) of the DSR line
279
350
  */
280
351
  static VALUE sp_get_dsr(self)
281
352
  VALUE self;
@@ -288,6 +359,7 @@ static VALUE sp_get_dsr(self)
288
359
  }
289
360
 
290
361
  /*
362
+ * Get the state (0 or 1) of the DCD line
291
363
  */
292
364
  static VALUE sp_get_dcd(self)
293
365
  VALUE self;
@@ -300,6 +372,7 @@ static VALUE sp_get_dcd(self)
300
372
  }
301
373
 
302
374
  /*
375
+ * Get the state (0 or 1) of the RI line
303
376
  */
304
377
  static VALUE sp_get_ri(self)
305
378
  VALUE self;
@@ -312,6 +385,10 @@ static VALUE sp_get_ri(self)
312
385
  }
313
386
 
314
387
  /*
388
+ * Return a hash with the state of each line status bit. Keys are
389
+ * "rts", "dtr", "cts", "dsr", "dcd", and "ri".
390
+ *
391
+ * Note: Under Windows, the rts and dtr values are not included.
315
392
  */
316
393
  static VALUE sp_signals(self)
317
394
  VALUE self;
@@ -335,6 +412,11 @@ static VALUE sp_signals(self)
335
412
  return hash;
336
413
  }
337
414
 
415
+ /*
416
+ * This class is used for communication over a serial port.
417
+ * In addition to the methods here, you can use everything
418
+ * Ruby's IO-class provides (read, write, getc, readlines, ...)
419
+ */
338
420
  void Init_serialport()
339
421
  {
340
422
  sBaud = rb_str_new2("baud");
@@ -405,5 +487,6 @@ void Init_serialport()
405
487
  rb_define_const(cSerialPort, "EVEN", INT2FIX(EVEN));
406
488
  rb_define_const(cSerialPort, "ODD", INT2FIX(ODD));
407
489
 
490
+ /* the package's version as a string "X.Y.Z", beeing major, minor and patch level */
408
491
  rb_define_const(cSerialPort, "VERSION", rb_str_new2(RUBY_SERIAL_PORT_VERSION));
409
492
  }
@@ -1,8 +1,9 @@
1
- /* Ruby/SerialPort $Id$
1
+ /* Ruby/SerialPort
2
2
  * Guillaume Pierronnet <moumar@netcourrier.com>
3
3
  * Alan Stern <stern@rowland.harvard.edu>
4
4
  * Daniel E. Shipton <dshipton@redshiptechnologies.com>
5
5
  * Tobin Richard <tobin.richard@gmail.com>
6
+ * Ryan C. Payne <rpayne-oss@bullittsystems.com>
6
7
  *
7
8
  * This code is hereby licensed for public consumption under either the
8
9
  * GNU GPL v2 or greater.
@@ -20,14 +21,13 @@
20
21
  #ifndef _RUBY_SERIAL_PORT_H_
21
22
  #define _RUBY_SERIAL_PORT_H_
22
23
 
23
- #define RUBY_SERIAL_PORT_VERSION "0.7.3"
24
+ #define RUBY_SERIAL_PORT_VERSION "1.0.0"
24
25
 
25
26
  #include <ruby.h> /* ruby inclusion */
26
-
27
- #ifdef RUBY_19
28
- #include <ruby/io.h>
27
+ #ifdef RUBY_1_9 /* ruby io inclusion */
28
+ #include <ruby/io.h>
29
29
  #else
30
- #include <rubyio.h>
30
+ #include <rubyio.h>
31
31
  #endif
32
32
 
33
33
  struct modem_params
@@ -57,10 +57,13 @@ struct line_signals
57
57
  #define MARK MARKPARITY
58
58
  #define EVEN EVENPARITY
59
59
  #define ODD ODDPARITY
60
-
60
+
61
+ /* Not entirely sure why this was commented out, but it has been tested */
62
+ /*
61
63
  #ifndef RB_SERIAL_EXPORT
62
- #define RB_SERIAL_EXPORT __declspec(dllexport)
64
+ #define RB_SERIAL_EXPORT __declspec(dllexport)
63
65
  #endif
66
+ */
64
67
  #else
65
68
  #define SPACE 0
66
69
  #define MARK 0
@@ -1,4 +1,4 @@
1
- /* Ruby/SerialPort $Id$
1
+ /* Ruby/SerialPort
2
2
  * Guillaume Pierronnet <moumar@netcourrier.com>
3
3
  * Alan Stern <stern@rowland.harvard.edu>
4
4
  * Daniel E. Shipton <dshipton@redshiptechnologies.com>
@@ -35,16 +35,28 @@ static char sSetCommTimeouts[] = "SetCommTimeouts";
35
35
  static HANDLE get_handle_helper(obj)
36
36
  VALUE obj;
37
37
  {
38
+ #ifdef RUBY_1_9
39
+ rb_io_t *fptr;
40
+ #else
38
41
  OpenFile *fptr;
42
+ #endif
39
43
 
40
44
  GetOpenFile(obj, fptr);
45
+ #ifdef RUBY_1_9
46
+ return (HANDLE) _get_osfhandle(fptr->fd);
47
+ #else
41
48
  return (HANDLE) _get_osfhandle(fileno(fptr->f));
49
+ #endif
42
50
  }
43
51
 
44
52
  VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port)
45
53
  VALUE class, _port;
46
54
  {
55
+ #ifdef RUBY_1_9
56
+ rb_io_t *fp;
57
+ #else
47
58
  OpenFile *fp;
59
+ #endif
48
60
  int fd;
49
61
  HANDLE fh;
50
62
  int num_port;
@@ -75,7 +87,11 @@ VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port)
75
87
 
76
88
  case T_STRING:
77
89
  Check_SafeStr(_port);
90
+ #ifdef RUBY_1_9
91
+ port = RSTRING_PTR(_port);
92
+ #else
78
93
  port = RSTRING(_port)->ptr;
94
+ #endif
79
95
  break;
80
96
 
81
97
  default:
@@ -121,7 +137,11 @@ VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port)
121
137
 
122
138
  errno = 0;
123
139
  fp->mode = FMODE_READWRITE | FMODE_BINMODE | FMODE_SYNC;
140
+ #ifdef RUBY_1_9
141
+ fp->fd = fd;
142
+ #else
124
143
  fp->f = fdopen(fd, "rb+");
144
+ #endif
125
145
  return (VALUE) sp;
126
146
  }
127
147
 
@@ -1,8 +1,17 @@
1
- require "serialport.so"
1
+ require 'serialport.so'
2
2
 
3
3
  class SerialPort
4
4
  private_class_method(:create)
5
5
 
6
+ # Creates a serial port object.
7
+ #
8
+ # <tt>port</tt> may be a port number
9
+ # or the file name of a defice.
10
+ # The number is portable; so 0 is mapped to "COM1" on Windows,
11
+ # "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
12
+ #
13
+ # <tt>params</tt> can be used to configure the serial port.
14
+ # See SerialPort#set_modem_params for details
6
15
  def SerialPort::new(port, *params)
7
16
  sp = create(port)
8
17
  begin
@@ -14,6 +23,9 @@ class SerialPort
14
23
  return sp
15
24
  end
16
25
 
26
+ # This behaves like SerialPort#new, except that you can pass a block
27
+ # to which the new serial port object will be passed. In this case
28
+ # the connection is automaticaly closed when the block has finished.
17
29
  def SerialPort::open(port, *params)
18
30
  sp = create(port)
19
31
  begin
@@ -5,31 +5,35 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{serialport}
8
- s.version = "0.8.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Guillaume Pierronnet", "Alan Stern", "Daniel E. Shipton", "Tobin Richard"]
12
- s.date = %q{2009-10-14}
11
+ s.authors = ["Guillaume Pierronnet", "Alan Stern", "Daniel E. Shipton", "Tobin Richard", "Hector Parra", "Ryan C. Payne"]
12
+ s.date = %q{2010-01-19}
13
13
  s.description = %q{Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports.}
14
14
  s.email = %q{hector@hectorparra.com}
15
- s.extensions = ["extconf.rb"]
15
+ s.extensions = ["ext/native/extconf.rb"]
16
16
  s.extra_rdoc_files = [
17
- "README"
17
+ "LICENSE",
18
+ "README"
18
19
  ]
19
20
  s.files = [
20
- "CHANGELOG",
21
+ ".gitignore",
22
+ "CHANGELOG",
23
+ "LICENSE",
21
24
  "MANIFEST",
22
25
  "README",
23
26
  "Rakefile",
24
27
  "VERSION",
25
- "extconf.rb",
28
+ "ext/native/extconf.rb",
29
+ "ext/native/posix_serialport_impl.c",
30
+ "ext/native/serialport.c",
31
+ "ext/native/serialport.h",
32
+ "ext/native/win_serialport_impl.c",
26
33
  "lib/serialport.rb",
27
34
  "serialport.gemspec",
28
- "src/posix_serialport_impl.c",
29
- "src/serialport.c",
30
- "src/serialport.h",
31
- "src/win_serialport_impl.c",
32
- "test/miniterm.rb"
35
+ "test/miniterm.rb",
36
+ "test/set_readtimeout.rb"
33
37
  ]
34
38
  s.homepage = %q{http://github.com/hparra/ruby-serialport/}
35
39
  s.rdoc_options = ["--charset=UTF-8"]
@@ -37,7 +41,8 @@ Gem::Specification.new do |s|
37
41
  s.rubygems_version = %q{1.3.5}
38
42
  s.summary = %q{Library for using RS-232 serial ports.}
39
43
  s.test_files = [
40
- "test/miniterm.rb"
44
+ "test/miniterm.rb",
45
+ "test/set_readtimeout.rb"
41
46
  ]
42
47
 
43
48
  if s.respond_to? :specification_version then
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ require "rubygems"
3
+ require "serialport"
4
+
5
+ sp = SerialPort.new("/dev/tty.usbserial", "9600".to_i)
6
+ sp.read_timeout = 100
7
+ sp.close
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serialport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Pierronnet
8
8
  - Alan Stern
9
9
  - Daniel E. Shipton
10
10
  - Tobin Richard
11
+ - Hector Parra
12
+ - Ryan C. Payne
11
13
  autorequire:
12
14
  bindir: bin
13
15
  cert_chain: []
14
16
 
15
- date: 2009-10-14 00:00:00 -07:00
17
+ date: 2010-01-19 00:00:00 -08:00
16
18
  default_executable:
17
19
  dependencies: []
18
20
 
@@ -21,23 +23,27 @@ email: hector@hectorparra.com
21
23
  executables: []
22
24
 
23
25
  extensions:
24
- - extconf.rb
26
+ - ext/native/extconf.rb
25
27
  extra_rdoc_files:
28
+ - LICENSE
26
29
  - README
27
30
  files:
31
+ - .gitignore
28
32
  - CHANGELOG
33
+ - LICENSE
29
34
  - MANIFEST
30
35
  - README
31
36
  - Rakefile
32
37
  - VERSION
33
- - extconf.rb
38
+ - ext/native/extconf.rb
39
+ - ext/native/posix_serialport_impl.c
40
+ - ext/native/serialport.c
41
+ - ext/native/serialport.h
42
+ - ext/native/win_serialport_impl.c
34
43
  - lib/serialport.rb
35
44
  - serialport.gemspec
36
- - src/posix_serialport_impl.c
37
- - src/serialport.c
38
- - src/serialport.h
39
- - src/win_serialport_impl.c
40
45
  - test/miniterm.rb
46
+ - test/set_readtimeout.rb
41
47
  has_rdoc: true
42
48
  homepage: http://github.com/hparra/ruby-serialport/
43
49
  licenses: []
@@ -68,3 +74,4 @@ specification_version: 3
68
74
  summary: Library for using RS-232 serial ports.
69
75
  test_files:
70
76
  - test/miniterm.rb
77
+ - test/set_readtimeout.rb