shellixyz-serialport 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.travis.yml +12 -0
- data/CHANGELOG +59 -0
- data/CHECKLIST +12 -0
- data/Gemfile +3 -0
- data/LICENSE +339 -0
- data/MANIFEST +12 -0
- data/README.md +43 -0
- data/Rakefile +27 -0
- data/ext/native/extconf.rb +13 -0
- data/ext/native/posix_serialport_impl.c +789 -0
- data/ext/native/serialport.c +613 -0
- data/ext/native/serialport.h +100 -0
- data/ext/native/win_serialport_impl.c +657 -0
- data/lib/serialport/version.rb +3 -0
- data/lib/serialport.rb +60 -0
- data/serialport.gemspec +23 -0
- data/test/miniterm.rb +25 -0
- data/test/set_readtimeout.rb +7 -0
- metadata +113 -0
data/lib/serialport.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'serialport.so'
|
2
|
+
require 'serialport/version'
|
3
|
+
|
4
|
+
|
5
|
+
# This class is used for communication over a serial port.
|
6
|
+
# In addition to the methods here, you can use Ruby IO methods, e.g. read, write, getc, readlines, etc.
|
7
|
+
#
|
8
|
+
# @see http://rubydoc.info/stdlib/core/IO Ruby IO class
|
9
|
+
# @see http://www.cmrr.umn.edu/~strupp/serial.html "Serial Programming Guide for POSIX Operating Systems"
|
10
|
+
class SerialPort
|
11
|
+
private_class_method(:create)
|
12
|
+
|
13
|
+
# Creates a serial port object.
|
14
|
+
# Accepts the port identifier and a variable list for configuration as paramaters or hash.
|
15
|
+
# Please see SerialPort#set_modem_params
|
16
|
+
#
|
17
|
+
# @overload new(port, *params)
|
18
|
+
# @param port [Integer] the serial port number,
|
19
|
+
# where 0 is mapped to "COM1" on Windows, "/dev/ttyS0" on Linux, "/dev/cuaa0" on Mac OS X, etc.
|
20
|
+
# @overload new(port, *params)
|
21
|
+
# @param port [String] the serial port file e.g. "/dev/ttyS0"
|
22
|
+
# @return [SerialPort]
|
23
|
+
# @see SerialPort#set_modem_params
|
24
|
+
def SerialPort::new(port, *params)
|
25
|
+
sp = create(port)
|
26
|
+
begin
|
27
|
+
sp.set_modem_params(*params)
|
28
|
+
rescue
|
29
|
+
sp.close
|
30
|
+
raise
|
31
|
+
end
|
32
|
+
return sp
|
33
|
+
end
|
34
|
+
|
35
|
+
# This behaves like SerialPort#new, except that you can pass a block
|
36
|
+
# to which the new serial port object will be passed. In this case
|
37
|
+
# the connection is automaticaly closed when the block has finished.
|
38
|
+
#
|
39
|
+
# @yield [serial_port] the serial port number or filename
|
40
|
+
# @see SerialPort#new
|
41
|
+
# @see SerialPort#set_modem_params
|
42
|
+
def SerialPort::open(port, *params)
|
43
|
+
sp = create(port)
|
44
|
+
begin
|
45
|
+
sp.set_modem_params(*params)
|
46
|
+
rescue
|
47
|
+
sp.close
|
48
|
+
raise
|
49
|
+
end
|
50
|
+
if (block_given?)
|
51
|
+
begin
|
52
|
+
yield sp
|
53
|
+
ensure
|
54
|
+
sp.close
|
55
|
+
end
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
return sp
|
59
|
+
end
|
60
|
+
end
|
data/serialport.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/serialport/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "shellixyz-serialport"
|
6
|
+
s.license = "GPL-2"
|
7
|
+
s.version = SerialPort::VERSION
|
8
|
+
s.authors = ["Guillaume Pierronnet", "Alan Stern", "Daniel E. Shipton", "Tobin Richard", "Hector Parra", "Ryan C. Payne", "Michel Pastor"]
|
9
|
+
s.summary = "Library for using RS-232 serial ports."
|
10
|
+
s.description = "Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports. This version is a fork of the original serialport gem with some fixes"
|
11
|
+
s.email = "shellixyz@gmail.com"
|
12
|
+
s.homepage = "http://github.com/shellixyz/ruby-serialport/"
|
13
|
+
|
14
|
+
s.add_development_dependency "bundler"
|
15
|
+
s.add_development_dependency "rake"
|
16
|
+
s.add_development_dependency "rake-compiler", ">= 0.4.1"
|
17
|
+
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.files = `git ls-files`.split($\)
|
20
|
+
s.extensions = "ext/native/extconf.rb"
|
21
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
22
|
+
s.extra_rdoc_files = ["LICENSE", "README.md"]
|
23
|
+
end
|
data/test/miniterm.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "../serialport.so"
|
2
|
+
|
3
|
+
|
4
|
+
if ARGV.size < 4
|
5
|
+
STDERR.print <<EOF
|
6
|
+
Usage: ruby #{$0} num_port bps nbits stopb
|
7
|
+
EOF
|
8
|
+
exit(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
sp = SerialPort.new(ARGV[0].to_i, ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE)
|
12
|
+
|
13
|
+
open("/dev/tty", "r+") { |tty|
|
14
|
+
tty.sync = true
|
15
|
+
Thread.new {
|
16
|
+
while true do
|
17
|
+
tty.printf("%c", sp.getc)
|
18
|
+
end
|
19
|
+
}
|
20
|
+
while (l = tty.gets) do
|
21
|
+
sp.write(l.sub("\n", "\r"))
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
sp.close
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shellixyz-serialport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guillaume Pierronnet
|
8
|
+
- Alan Stern
|
9
|
+
- Daniel E. Shipton
|
10
|
+
- Tobin Richard
|
11
|
+
- Hector Parra
|
12
|
+
- Ryan C. Payne
|
13
|
+
- Michel Pastor
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: bundler
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
type: :development
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake-compiler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.4.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.4.1
|
61
|
+
description: Ruby/SerialPort is a Ruby library that provides a class for using RS-232
|
62
|
+
serial ports. This version is a fork of the original serialport gem with some fixes
|
63
|
+
email: shellixyz@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions:
|
66
|
+
- ext/native/extconf.rb
|
67
|
+
extra_rdoc_files:
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
files:
|
71
|
+
- ".gitignore"
|
72
|
+
- ".travis.yml"
|
73
|
+
- CHANGELOG
|
74
|
+
- CHECKLIST
|
75
|
+
- Gemfile
|
76
|
+
- LICENSE
|
77
|
+
- MANIFEST
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- ext/native/extconf.rb
|
81
|
+
- ext/native/posix_serialport_impl.c
|
82
|
+
- ext/native/serialport.c
|
83
|
+
- ext/native/serialport.h
|
84
|
+
- ext/native/win_serialport_impl.c
|
85
|
+
- lib/serialport.rb
|
86
|
+
- lib/serialport/version.rb
|
87
|
+
- serialport.gemspec
|
88
|
+
- test/miniterm.rb
|
89
|
+
- test/set_readtimeout.rb
|
90
|
+
homepage: http://github.com/shellixyz/ruby-serialport/
|
91
|
+
licenses:
|
92
|
+
- GPL-2
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.2.22
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Library for using RS-232 serial ports.
|
113
|
+
test_files: []
|