MSF fork of the RubyForge ruby-serialport library

git-svn-id: file:///home/svn/framework3/trunk@6117 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
druid 2009-01-11 05:35:23 +00:00
parent 348ffe7894
commit cad513b703
13 changed files with 2084 additions and 0 deletions

14
external/serialport/CHANGELOG vendored Normal file
View File

@ -0,0 +1,14 @@
0.6 => 12/02/2003: Windows support
Get/set modem parameters
Read and write timeouts
Open method
0.5 => 25/10/2002: Cygwin support
0.4 => 19/09/2002: Added more serial ports (total of 8 ports)
0.3 => 15/03/2002: Damn, another bug found
0.2 => 14/03/2002: A bug fixed (read() was not blocking)
0.1 => 14/03/2002: First release

10
external/serialport/MANIFEST vendored Normal file
View File

@ -0,0 +1,10 @@
test/miniterm.rb
README
CHANGELOG
debian/control
debian/rules
debian/changelog
debian/copyright
extconf.rb
serialport.c
.cvsignore

149
external/serialport/Makefile vendored Normal file
View File

@ -0,0 +1,149 @@
SHELL = /bin/sh
#### Start of system configuration section. ####
srcdir = .
topdir = /usr/lib/ruby/1.8/i486-linux
hdrdir = $(topdir)
VPATH = $(srcdir):$(topdir):$(hdrdir)
prefix = $(DESTDIR)/usr
exec_prefix = $(prefix)
sitedir = $(prefix)/lib/ruby/site_ruby
rubylibdir = $(libdir)/ruby/$(ruby_version)
docdir = $(datarootdir)/doc/$(PACKAGE)
dvidir = $(docdir)
datarootdir = $(prefix)/share
archdir = $(rubylibdir)/$(arch)
sbindir = $(exec_prefix)/sbin
psdir = $(docdir)
localedir = $(datarootdir)/locale
htmldir = $(docdir)
datadir = $(DESTDIR)/usr/share
includedir = $(prefix)/include
infodir = $(datarootdir)/info
sysconfdir = $(prefix)/etc
mandir = $(DESTDIR)/usr/man
libdir = $(exec_prefix)/lib
sharedstatedir = $(prefix)/com
oldincludedir = $(DESTDIR)/usr/include
pdfdir = $(docdir)
sitearchdir = $(sitelibdir)/$(sitearch)
bindir = $(exec_prefix)/bin
localstatedir = $(prefix)/var
sitelibdir = $(sitedir)/$(ruby_version)
libexecdir = $(exec_prefix)/libexec
CC = gcc
LIBRUBY = $(LIBRUBY_SO)
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -L. -l$(RUBY_SO_NAME)
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
RUBY_EXTCONF_H =
CFLAGS = -fPIC -O2 -march=i486 -mtune=i686 -fPIC -Dlinux
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
CPPFLAGS = -DHAVE_TERMIOS_H -DHAVE_UNISTD_H
CXXFLAGS = $(CFLAGS)
DLDFLAGS = -rdynamic -Wl,-export-dynamic
LDSHARED = $(CC) -shared
AR = ar
EXEEXT =
RUBY_INSTALL_NAME = ruby
RUBY_SO_NAME = ruby
arch = i486-linux
sitearch = i486-linux
ruby_version = 1.8
ruby = /usr/bin/ruby
RUBY = $(ruby)
RM = rm -f
MAKEDIRS = mkdir -p
INSTALL = /usr/bin/ginstall -c
INSTALL_PROG = $(INSTALL) -m 0755
INSTALL_DATA = $(INSTALL) -m 644
COPY = cp
#### End of system configuration section. ####
preload =
libpath = $(libdir)
LIBPATH = -L'$(libdir)' -Wl,-R'$(libdir)'
DEFFILE =
CLEANFILES =
DISTCLEANFILES =
extout =
extout_prefix =
target_prefix =
LOCAL_LIBS =
LIBS = $(LIBRUBYARG_SHARED) -ldl -lcrypt -lm -lc
SRCS = serialport.c
OBJS = serialport.o
TARGET = serialport
DLLIB = $(TARGET).so
EXTSTATIC =
STATIC_LIB =
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
TARGET_SO = $(DLLIB)
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
all: $(DLLIB)
static: $(STATIC_LIB)
clean:
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
distclean: clean
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
realclean: distclean
install: install-so install-rb
install-so: $(RUBYARCHDIR)
install-so: $(RUBYARCHDIR)/$(DLLIB)
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
install-rb: pre-install-rb install-rb-default
install-rb-default: pre-install-rb-default
pre-install-rb: Makefile
pre-install-rb-default: Makefile
$(RUBYARCHDIR):
$(MAKEDIRS) $@
site-install: site-install-so site-install-rb
site-install-so: install-so
site-install-rb: install-rb
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
.cc.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.cxx.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.cpp.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.C.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.c.o:
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
$(DLLIB): $(OBJS)
@-$(RM) $@
$(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
$(OBJS): ruby.h defines.h

61
external/serialport/README.msf vendored Normal file
View File

@ -0,0 +1,61 @@
Due to the ruby-serialport project provided by RubyForge.org apparently
being unmaintained, this is a MSF-specific fork of that project. This
version has been modified by both MSF developers as well as by applying
a patch found submitted to the RubyForge project but never included in
the distribution provided there. The versioning scheme has been updated
from the format X.y, to X.Y.z-msf. The text accompanying the applied
patch can be found below.
Please see the README.orig file for the original project's README, which
includes buid and install instructions as well as documentation of the
SerialPort Class API.
-- I)ruid
########################################################################
Applied Patches:
========================================================================
[#878] Six new methods (implemented for the posix flavor only) for the
SerialPort class
I had to use the SerialPort class to communicate chunks of binary data
through the serial port, and i needed to set some of the low-level
flags onto the serial fd using fcntl() and tcsetattr(), so I implemented
some nifty methods and added them to the class.
The six new methods are:
.nonblock= and .nonblock() -> Manipulate the O_NONBLOCK descriptor flag
.input_type= and .input_type() -> Manipulate the ICANON/RAW input flags
.output_type= and .output_type() -> Manipulate the OPOST/RAW output flags
Also two new constants were added:
SerialPort::PROCESSED -> Identifies the CANONICAL/PROCESSED I/O
SerialPort::RAW -> Identifies the RAW/RAW I/O
Example usage:
def open_port
ret = SerialPort.new @device
ret.baud = @port_baud
ret.data_bits = @port_data_bits
ret.stop_bits = @port_stop_bits
ret.parity = SerialPort::NONE
ret.flow_control = SerialPort::HARD
ret.input_type = SerialPort::RAW
ret.output_type = SerialPort::RAW
ret.read_timeout = -1
ret.nonblock = false
ret.dtr = 1
ret
end
This was the best setup for modem communications I could achieve, for
binary and string I/O, in a multithreaded application. Obviously YMMV.
-void
void@core-dumped.info

152
external/serialport/README.orig vendored Normal file
View File

@ -0,0 +1,152 @@
-----Ruby/SerialPort-----
-- Description --
Ruby/SerialPort is a Ruby library that provides a class for using
RS-232 serial ports. This class also contains low-level functions to
check and set the current state of the signals on the line.
The native Windows version of this library supports Microsoft's Visual C++
and Borland's C++ compilers.
-- Installation --
$ ruby extconf.rb
$ make
$ make install
-- Testing --
* test/miniterm.rb
Ruby's copy of miniterm.c !
-- API --
**** Class SerialPort, Parent IO ****
** Class constants **
VERSION -> aString (this release is "0.6")
NONE, HARD, SOFT, SPACE, MARK, EVEN, ODD -> anInteger
** Class methods **
* new(port_num [, modem_parameters]) -> aSerialPort
* open(port_num [, modem_parameters]) -> aSerialPort
* open(port_num [, modem_parameters]) {|aSerialPort| block} -> nil
port_num -> anInteger: port number, 0 for first port which is
"/dev/ttyS0" on GNU/Linux and "COM1" on Windows,
or aString: file name of the device (example: "/dev/ttyS2")
Optional modem_parameters:
baudrate -> anInteger: from 50 to 256000, depends on platform.
databits -> anInteger: from 5 to 8 (4 is allowed on Windows)
stopbits -> anInteger: 1 or 2 (1.5 is not supported)
parity -> anInteger: SerialPort::NONE, SerialPort::EVEN,
SerialPort::ODD, SerialPort::MARK, SerialPort::SPACE
(MARK and SPACE are not supported on Posix)
Raise an argError on bad argument.
SerialPort.new and SerialPort.open without a block return an
instance of SerialPort. SerialPort.open with a block passes
a SerialPort to the block and closes it when the block exits
(like File.open).
** Instance methods **
* modem_params() -> aHash
* modem_params=(aHash) -> self
* get_modem_params() -> aHash
* set_modem_params(aHash) -> self
* set_modem_params(baudrate [, databits [, stopbits [, parity]]])
Get and set the modem parameters. Hash keys are "baud", "data_bits",
"stop_bits", and "parity" (see above).
Parameters not present in the hash or set to nil remain unchanged.
Default parameter values for the set_modem_params method are:
databits = 8, stopbits = 1, parity = (databits == 8 ?
SerialPort::NONE : SerialPort::EVEN).
* baud() -> anInteger
* baud=(anInteger) -> self
* data_bits() -> 4, 5, 6, 7, or 8
* data_bits=(anInteger) -> self
* stop_bits() -> 1 or 2
* stop_bits=(anInteger) -> self
* parity() -> anInteger: SerialPort::NONE, SerialPort::EVEN,
SerialPort::ODD, SerialPort::MARK, or SerialPort::SPACE
* parity=(anInteger) -> self
Get and set the corresponding modem parameter.
* flow_control() -> anInteger
* flow_control=(anInteger) -> self
Get and set the flow control: SerialPort::NONE, SerialPort::HARD,
SerialPort::SOFT, or (SerialPort::HARD | SerialPort::SOFT).
Note: SerialPort::HARD mode is not supported on all platforms.
SerialPort::HARD uses RTS/CTS handshaking; DSR/DTR is not
supported.
* read_timeout() -> anInteger
* read_timeout=(anInteger) -> self
* write_timeout() -> anInteger
* write_timeout=(anInteger) -> self
Get and set timeout values (in milliseconds) for reading and writing.
A negative read timeout will return all the available data without
waiting, a zero read timeout will not return until at least one
byte is available, and a positive read timeout returns when the
requested number of bytes is available or the interval between the
arrival of two bytes exceeds the timeout value.
Note: Read timeouts don't mix well with multi-threading.
Note: Under Posix, write timeouts are not implemented.
* break(time) -> nil
Send a break for the given time.
time -> anInteger: tenths-of-a-second for the break.
Note: Under Posix, this value is very approximate.
* signals() -> anHash
Return a hash with the state of each line status bit. Keys are
"rts", "dtr", "cts", "dsr", "dcd", and "ri".
Note: Under Windows, the rts and dtr values are not included.
* rts()
* dtr()
* cts()
* dsr()
* dcd()
* ri() -> 0 or 1
* rts=(0 or 1)
* dtr=(0 or 1) -> self
Get and set the corresponding line status bit.
Note: Under Windows, rts() and dtr() are not implemented.
-- License --
GPL
Guillaume Pierronnet <moumar@netcourrier.com>
Alan Stern <stern@rowland.harvard.edu>

39
external/serialport/debian/changelog vendored Normal file
View File

@ -0,0 +1,39 @@
ruby-serialport (0.6.1) unstable; urgency=low
* Added nonblock= and nonblock()
* Added input_type= and input_type()
* Added output_type= and output_type()
* Re-indented code
-- Marcello Barnaba <l.barnaba@openssl.it> Wed, 8 Sep 2004 17:18:25 +0200
ruby-serialport (0.6) unstable; urgency=low
* Windows support
* Get/set modem parameters
* Read and write timeouts
* Open method
-- Guillaume Pierronnet <moumar@duron.maison.chello.fr> Thu, 13 Feb 2003 20:59:37 +0100
ruby-serialport (0.5-1) unstable; urgency=low
* Cygwin support
-- Guillaume Pierronnet <moumar@duron.maison.chello.fr> Fri, 25 Oct 2002 13:48:44 +0200
ruby-serialport (0.4-1) unstable; urgency=low
* Modified to support 8 serial ports
-- Guillaume Pierronnet <moumar@duron.maison.chello.fr> Fri, 20 Sep 2002 15:26:20 +0200
ruby-serialport (0.3-1) unstable; urgency=low
* Initial Release.
-- Guillaume Pierronnet <moumar@netcourrier.com> Mon, 21 Sep 2001 11:19:36 +0900
Local variables:
mode: debian-changelog
End:

13
external/serialport/debian/control vendored Normal file
View File

@ -0,0 +1,13 @@
Source: ruby-serialport
Section: interpreters
Priority: optional
Maintainer: Guillaume Pierronnet <moumar@netcourrier.com>
Standards-Version: 3.1.1
Build-Depends: debhelper (>= 2.1.2), ruby (>= 1.8-1), ruby1.8-dev (>= 1.8-1)
Package: ruby-serialport
Architecture: any
Depends: ${shlibs:Depends}, ruby (>= 1.8)
Description: serial port module for Ruby
serial port module for ruby

18
external/serialport/debian/copyright vendored Normal file
View File

@ -0,0 +1,18 @@
This package was debianized by Guillaume Pierronnet <moumar@netcourrier.com>
Mon, 25 Mar 2002 22:19:36 +0100.
It was downloaded from http://davedd.free.fr/ruby-serialport/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

83
external/serialport/debian/rules vendored Normal file
View File

@ -0,0 +1,83 @@
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
# This is the debhelper compatability version to use.
export DH_COMPAT=2
PACKAGE_NAME=ruby-serialport
#GNU_ARCH=$(shell ruby -e 'puts RUBY_PLATFORM')
#RBV=1.6
build: build-stamp
build-stamp:
dh_testdir
ruby extconf.rb
$(MAKE)
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp install-stamp
# Add here commands to clean up after the build process.
-$(MAKE) distclean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean
dh_installdirs
# Add here commands to install the package into debian/tmp.
$(MAKE) install DESTDIR=`pwd`/debian/$(PACKAGE_NAME)
# mkdir -p debian/tmp/$(RBV)/$(GNU_ARCH)
# cp serialport.so debian/$(PACKAGE_NAME)/usr/lib/ruby/$(RBV)/$(GNU_ARCH)/
touch install-stamp
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
# dh_testversion
dh_testdir
dh_testroot
# dh_installdebconf
dh_installdocs README*
dh_installexamples
# dh_installmenu
# dh_installemacsen
# dh_installpam
# dh_installinit
# dh_installcron
# dh_installmanpages
# dh_installinfo
# dh_undocumented
dh_installchangelogs
dh_link
dh_strip
dh_compress
dh_fixperms
# You may want to make some executables suid here.
# dh_suidregister
dh_makeshlibs
dh_installdeb
# dh_perl
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

13
external/serialport/extconf.rb vendored Normal file
View File

@ -0,0 +1,13 @@
require 'mkmf'
printf("checking for OS... ")
STDOUT.flush
os = /-([a-z]+)/.match(RUBY_PLATFORM)[1]
puts(os)
$CFLAGS += " -D#{os}"
if !(os == 'mswin' or os == 'bccwin')
exit(1) if not have_header("termios.h") or not have_header("unistd.h")
end
create_makefile("serialport")

20
external/serialport/mkmf.log vendored Normal file
View File

@ -0,0 +1,20 @@
have_header: checking for termios.h... -------------------- yes
"gcc -E -I. -I/usr/lib/ruby/1.8/i486-linux -I. -O2 -march=i486 -mtune=i686 -fPIC -Dlinux conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include <termios.h>
/* end */
--------------------
have_header: checking for unistd.h... -------------------- yes
"gcc -E -I. -I/usr/lib/ruby/1.8/i486-linux -I. -O2 -march=i486 -mtune=i686 -fPIC -Dlinux conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include <unistd.h>
/* end */
--------------------

1487
external/serialport/serialport.c vendored Normal file

File diff suppressed because it is too large Load Diff

25
external/serialport/test/miniterm.rb vendored Normal file
View File

@ -0,0 +1,25 @@
require "../serialport.so"
if ARGV.size < 4
STDERR.print <<EOF
Usage: ruby #{$0} num_port bps nbits stopb
EOF
exit(1)
end
sp = SerialPort.new(ARGV[0].to_i, ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE)
open("/dev/tty", "r+") { |tty|
tty.sync = true
Thread.new {
while true do
tty.printf("%c", sp.getc)
end
}
while (l = tty.gets) do
sp.write(l.sub("\n", "\r"))
end
}
sp.close