rs232 0.1.2 → 0.1.3

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.
Files changed (3) hide show
  1. data/README +2 -2
  2. data/lib/rs232.rb +20 -9
  3. metadata +3 -3
data/README CHANGED
@@ -7,7 +7,7 @@
7
7
  # author hugo benichi
8
8
  # email hugo.benichi@m4x.org
9
9
  # copyright 2012 hugo benichi
10
- # version 0.1.0
10
+ # version 0.1.3
11
11
  #
12
12
  ##
13
13
 
@@ -37,4 +37,4 @@
37
37
  control flow hardware (RTS/CTS)
38
38
  delimiters "\r\n"
39
39
 
40
- you can directly use the RS232 instance with the 'write', 'read', and 'query' commands
40
+ you can directly use the RS232 instance with the 'write', 'read', and 'query' commands
@@ -1,4 +1,3 @@
1
-
2
1
  class RS232
3
2
 
4
3
  require 'ffi'
@@ -24,10 +23,11 @@ class RS232
24
23
  # :write_total_timeout_multiplier
25
24
  # :write_total_timeout_constant
26
25
  def initialize address, params = {}
27
- mode = param[:mode] || Win32::GENERIC_READ | Win32::GENERIC_WRITE
28
- type = param[:file] || Win32::OPEN_EXISTING
29
- attr = param[:attr] || Win32::FILE_ATTRIBUTE_NORMAL
30
- @serial = Win32::CreateFileA( address, mode, 0, nil, type, attr, nil)
26
+ mode = params[:mode] || Win32::GENERIC_READ | Win32::GENERIC_WRITE
27
+ share = params[:share] || 0 #Win32::FILE_SHARE_DELETE
28
+ type = params[:file] || Win32::OPEN_EXISTING
29
+ attr = params[:attr] || Win32::FILE_ATTRIBUTE_NORMAL
30
+ @serial = Win32::CreateFileA( address, mode, share, nil, type, attr, nil)
31
31
  @error = Win32.error_check
32
32
  puts "RS232 >> got file handle 0x%.8x for com port %s" % [@serial, address]
33
33
  DCB.new.tap do |p|
@@ -62,6 +62,7 @@ class RS232
62
62
  @buffer.write_string command
63
63
  Win32::WriteFile @serial, @buffer, command.length, @count, nil
64
64
  @error = Win32.error_check
65
+ @buffer.write_string "\0" #empty string buffer
65
66
  puts "write count %i" % @count.read_uint32 if @report
66
67
  end
67
68
 
@@ -116,10 +117,20 @@ class RS232
116
117
  def self.error_check
117
118
  self::GetLastError().tap{ |err| puts "error: %i | 0x%.8x" % [err,err] if err != 0 }
118
119
  end
119
- GENERIC_READ = 0x80000000 # consts from Windows seven sdk:
120
- GENERIC_WRITE = 0x40000000 # extract with
121
- OPEN_EXISTING = 3 # grep -i "generic_read" *.h
122
- FILE_ATTRIBUTE_NORMAL = 0x00000080 # from the /Include directory
120
+ # consts from Windows seven sdk. extract with
121
+ # grep -i "generic_read" *.h
122
+ # from the /Include directory
123
+ FILE_SHARE_DELETE = 0x00000004
124
+ FILE_SHARE_READ = 0x00000001
125
+ FILE_SHARE_WRITE = 0x00000002
126
+ FILE_SHARE_ALL = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE
127
+ GENERIC_READ = 0x80000000
128
+ GENERIC_WRITE = 0x40000000
129
+ CREATE_NEW = 1
130
+ CREATE_ALWAYS = 2
131
+ OPEN_EXISTING = 3
132
+ OPEN_ALWAYS = 4
133
+ FILE_ATTRIBUTE_NORMAL = 0x00000080
123
134
  end
124
135
 
125
136
  # this struct is used by windows to configure the COMM port
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs232
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &20596020 !ruby/object:Gem::Requirement
16
+ requirement: &16159800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20596020
24
+ version_requirements: *16159800
25
25
  description: Allows to script access to the serial port on Windows. Simple read and
26
26
  write commands
27
27
  email: hugo.benichi@m4x.org