pcanusb 0.0.1 → 1.0.0
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.
- data/lib/{PCAN_USB.rb → pcanusb.rb} +23 -6
- data/rakefile +8 -5
- metadata +5 -5
@@ -6,7 +6,7 @@ require "dl"
|
|
6
6
|
require "dl/import"
|
7
7
|
require "dl/struct"
|
8
8
|
|
9
|
-
class
|
9
|
+
class PCANUSB
|
10
10
|
|
11
11
|
# BAUD rates used by "init"
|
12
12
|
BAUD_1M = 0x0014
|
@@ -49,6 +49,10 @@ class PCAN_USB
|
|
49
49
|
CAN_ILLPARAMTYPE = 0x4000 # Parameter is not permitted/applicable here.
|
50
50
|
CAN_ILLPARAMVAL = 0x8000 # Parameter value is invalid.
|
51
51
|
|
52
|
+
# Initialize the PCAN device with a BAUD rate and message type.
|
53
|
+
# Valid message types are
|
54
|
+
# * CAN_INIT_TYPE_ST:: Standard format IDs
|
55
|
+
# * CAN_INIT_TYPE_EX:: Extended IDs
|
52
56
|
def self.init(baud_value, message_type = CAN_INIT_TYPE_EX)
|
53
57
|
err = Core::cAN_Init(baud_value, message_type)
|
54
58
|
|
@@ -58,14 +62,18 @@ class PCAN_USB
|
|
58
62
|
return err
|
59
63
|
end
|
60
64
|
|
65
|
+
# Close the PCAN device connection.
|
61
66
|
def self.close
|
62
67
|
return Core::cAN_Close
|
63
68
|
end
|
64
|
-
|
69
|
+
|
70
|
+
# Retrieve the current PCAN status.
|
65
71
|
def self.status
|
66
72
|
return Core::cAN_Status
|
67
73
|
end
|
68
|
-
|
74
|
+
|
75
|
+
# Initiates a transmission of a CAN message with a given ID.
|
76
|
+
# the data parameter is expected to be less than 8 bytes.
|
69
77
|
def self.write(id, data, message_type = MSGTYPE_EXTENDED)
|
70
78
|
message = Core::TPCANMsg.malloc
|
71
79
|
message.id = id
|
@@ -84,6 +92,8 @@ class PCAN_USB
|
|
84
92
|
return Core::cAN_MsgFilter(fromID, toID, message_type)
|
85
93
|
end
|
86
94
|
|
95
|
+
# Read one CAN message from the PCAN FIFO.
|
96
|
+
# Returns the error code, message type, ID and data array.
|
87
97
|
def self.read
|
88
98
|
message = Core::TPCANMsg.malloc
|
89
99
|
|
@@ -92,6 +102,8 @@ class PCAN_USB
|
|
92
102
|
return err, message.message_type, message.id, message.data[0..message.length - 1]
|
93
103
|
end
|
94
104
|
|
105
|
+
# Read a message with a given ID.
|
106
|
+
# Returns the received data array if the required ID is received within the timeout or false if not.
|
95
107
|
def self.read_id(id, timeout=1)
|
96
108
|
read_timeout = Time.now + timeout
|
97
109
|
|
@@ -106,10 +118,12 @@ class PCAN_USB
|
|
106
118
|
return false
|
107
119
|
end
|
108
120
|
|
121
|
+
# Reset the PCAN device.
|
109
122
|
def self.reset_client
|
110
123
|
return Core::cAN_ResetClient
|
111
124
|
end
|
112
125
|
|
126
|
+
# Provide information about the PCAN.
|
113
127
|
def self.version_info
|
114
128
|
info = Core::Version_Info.malloc
|
115
129
|
|
@@ -118,7 +132,8 @@ class PCAN_USB
|
|
118
132
|
# info.value is an array of characters, convert it to string
|
119
133
|
return info.value.pack("c128")
|
120
134
|
end
|
121
|
-
|
135
|
+
|
136
|
+
# Return the device number associated with the connected PCAN.
|
122
137
|
def self.get_usb_device_number
|
123
138
|
number = Core::Device_Number.malloc
|
124
139
|
|
@@ -126,8 +141,10 @@ class PCAN_USB
|
|
126
141
|
|
127
142
|
return err, number.value
|
128
143
|
end
|
129
|
-
|
130
|
-
|
144
|
+
|
145
|
+
#-----
|
146
|
+
|
147
|
+
module Core #:nodoc:all
|
131
148
|
extend DL::Importable
|
132
149
|
|
133
150
|
dlload File.dirname(__FILE__) + "/Pcan_usb.dll"
|
data/rakefile
CHANGED
@@ -4,10 +4,11 @@ require 'rubygems'
|
|
4
4
|
require 'rake'
|
5
5
|
require 'rake/packagetask'
|
6
6
|
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
7
8
|
require 'rake/contrib/rubyforgepublisher'
|
8
9
|
|
9
10
|
PKG_NAME = 'pcanusb'
|
10
|
-
PKG_VERSION = '0.0
|
11
|
+
PKG_VERSION = '1.0.0'
|
11
12
|
|
12
13
|
# Create compressed packages
|
13
14
|
dist_dirs = [ 'lib' ]
|
@@ -23,11 +24,9 @@ It ships with a DLL and documented API.
|
|
23
24
|
This is a Ruby wrapper for that API allowing CAN messages to be sent and received from Ruby.
|
24
25
|
EOF
|
25
26
|
|
26
|
-
|
27
|
+
s.has_rdoc = true
|
27
28
|
s.requirements << 'none'
|
28
29
|
|
29
|
-
# s.add_dependency('activesupport', '= 1.4.2' + PKG_BUILD)
|
30
|
-
|
31
30
|
s.require_path = 'lib'
|
32
31
|
s.autorequire = 'rake'
|
33
32
|
|
@@ -40,7 +39,6 @@ end
|
|
40
39
|
Rake::GemPackageTask.new(spec) do |pkg|
|
41
40
|
pkg.gem_spec = spec
|
42
41
|
pkg.need_zip = true
|
43
|
-
# pkg.need_tar = true
|
44
42
|
end
|
45
43
|
|
46
44
|
desc "Publish the release files to RubyForge."
|
@@ -53,3 +51,8 @@ task :release => [ :package ] do
|
|
53
51
|
rubyforge.login
|
54
52
|
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
|
55
53
|
end
|
54
|
+
|
55
|
+
Rake::RDocTask.new do |rd|
|
56
|
+
rd.main = "lib/pcanusb.rb"
|
57
|
+
rd.rdoc_files.include("lib/**/*.rb")
|
58
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: pcanusb
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2008-
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-08-13 00:00:00 -04:00
|
8
8
|
summary: PCAN DLL wrapper
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -15,7 +15,7 @@ description: PCAN is a Controller Area Network (CAN) device that connects to a P
|
|
15
15
|
autorequire: rake
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
|
-
has_rdoc:
|
18
|
+
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">"
|
@@ -30,8 +30,8 @@ authors: []
|
|
30
30
|
|
31
31
|
files:
|
32
32
|
- rakefile
|
33
|
+
- lib/pcanusb.rb
|
33
34
|
- lib/Pcan_usb.dll
|
34
|
-
- lib/PCAN_USB.rb
|
35
35
|
test_files: []
|
36
36
|
|
37
37
|
rdoc_options: []
|