lxi_rb 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79bb0d516f205bcdeeb9dd3e12d685fde5237c481b66ec02d80b54e22bd393ce
4
- data.tar.gz: f713c4887fae97699c9c26a9a42e7b7b8308b7d615529889c53e41a843bc2a6a
3
+ metadata.gz: 46b92e004dc07e1fe7bd3badd3ad1163c4555abe9ec2992b619ff9f49ffc657c
4
+ data.tar.gz: b0c02b7b8ef14803b3179b5360c9b5c515049dfe69e6137736d3d989cac0027a
5
5
  SHA512:
6
- metadata.gz: def303af335abcb996b9f88709a8901da0b298e7687f46e72dbee56d451ea033972672c6f4a17e19ae9ce30a14cf34d92e5891472769e735d22c22718c019b07
7
- data.tar.gz: c92a6342c28c3ba4d60d0480cd394d2ba6fa804c9abe0bf18b1327909fe43fa6ddc2edfb0ff3fd22abc66ac91b6ffeeaa72beea247ca08606c9bbc944e11753a
6
+ metadata.gz: 6ba992bf1a91502ba42c5ff7e5f408d38d627a56eb20019491ee3fd596a059881cb516ade0132d0be9551767c30e52ce471cffbd6a7b581ac985770456be1012
7
+ data.tar.gz: d85a26e8551eeee60d5aa87594d81027b6bd42a997b2234aa49d530f9431939346bd802ff3175e63a40ddff3b9e802e4e1d94f998f42aee8c0d57c0d2cf30980
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lxi_rb (0.1.0)
4
+ lxi_rb (0.2.0)
5
5
  ffi (~> 1.15)
6
6
 
7
7
  GEM
data/lib/lxi/device.rb CHANGED
@@ -17,10 +17,10 @@ module Lxi
17
17
  end
18
18
 
19
19
  def connect
20
- raise Error, 'LXI Library Initialisation Error' unless Lxi.lxi_init == Lxi::OK
20
+ raise Error, 'LXI Library Initialisation Error' unless Lxi.lxi_init == LXI_OK
21
21
 
22
22
  @id = Lxi.lxi_connect(@address, @port, @name, @timeout, @protocol)
23
- raise Error, 'LXI Connection Error' if @id == Lxi::ERROR
23
+ raise Error, 'LXI Connection Error' if @id == LXI_ERROR
24
24
 
25
25
  true
26
26
  end
@@ -42,7 +42,9 @@ module Lxi
42
42
 
43
43
  def read(length)
44
44
  message = FFI::MemoryPointer.new(:char, length)
45
- raise Error, 'LXI communications error' unless Lxi.lxi_receive(@id, message, length, @timeout).positive?
45
+ bytes_received = Lxi.lxi_receive(@id, message, length, @timeout)
46
+ raise Error, 'LXI communications error' unless bytes_received.positive?
47
+
46
48
  message.read_string
47
49
  end
48
50
  alias gets read
data/lib/lxi/ffi.rb CHANGED
@@ -7,11 +7,24 @@ module Lxi
7
7
  ffi_lib '/opt/homebrew/lib/liblxi.dylib'
8
8
  ffi_lib_flags :now, :global
9
9
 
10
- # Define the enums
10
+ # Expose liblxi functions
11
+ attach_function :lxi_init, [], :int
12
+ attach_function :lxi_discover_internal, :lxi_discover, [LxiInfo.ptr, :int, :lxi_discover_type], :int
13
+ attach_function :lxi_discover_if, [LxiInfo.ptr, :string, :int, :lxi_discover_type], :int
14
+ attach_function :lxi_connect, %i[string int string int lxi_protocol_type], :int
15
+ attach_function :lxi_send, %i[int string int int], :int
16
+ attach_function :lxi_receive, %i[int pointer int int], :int
17
+ attach_function :lxi_disconnect, [:int], :int
18
+
19
+ # LXI Constants
20
+ LXI_OK = 0
21
+ LXI_ERROR = -1
22
+
23
+ # Define liblxi enums
11
24
  enum :lxi_protocol_type, %i[vxi11 raw hyslip]
12
25
  enum :lxi_discover_type, %i[vxi11 mdns]
13
26
 
14
- # Callbacks
27
+ # VXI11 Discovery Callbacks
15
28
  BroadcastCallback =
16
29
  FFI::Function.new(:void, %i[pointer pointer]) do |address, interface|
17
30
  puts "Broadcast: #{address.read_string}, #{interface.read_string}"
@@ -27,7 +40,7 @@ module Lxi
27
40
  puts "Service: #{address.read_string}, #{id.read_string}, #{service.read_string}, #{port}"
28
41
  end
29
42
 
30
- # Define the structs
43
+ # Define liblxi structs
31
44
  class LxiInfo < FFI::Struct
32
45
  layout :broadcast,
33
46
  callback(%i[pointer pointer], :void),
@@ -37,43 +50,7 @@ module Lxi
37
50
  callback(%i[pointer pointer pointer int], :void)
38
51
  end
39
52
 
40
- # Define the functions
41
- attach_function :lxi_init, [], :int
42
- attach_function :lxi_discover_internal, :lxi_discover, [LxiInfo.ptr, :int, :lxi_discover_type], :int
43
- attach_function :lxi_discover_if, [LxiInfo.ptr, :string, :int, :lxi_discover_type], :int
44
- attach_function :lxi_connect, %i[string int string int lxi_protocol_type], :int
45
- attach_function :lxi_send, %i[int string int int], :int
46
- attach_function :lxi_receive, %i[int pointer int int], :int
47
- attach_function :lxi_disconnect, [:int], :int
48
-
49
- # Define the constants
50
- OK = 0
51
- ERROR = -1
52
-
53
- # Send and recieve scpi commands
54
- def self.scpi(address, port = 0, name = nil, protocol, command)
55
- response = FFI::MemoryPointer.new(:char, 65_536)
56
- timeout = 1000
57
-
58
- # Initialize LXI library
59
- lxi_init
60
-
61
- # Connect LXI device
62
- device = lxi_connect(address, port, name, timeout, protocol)
63
-
64
- # Send SCPI command
65
- lxi_send(device, command, command.length, timeout)
66
-
67
- # Wait for response
68
- lxi_receive(device, response, response.size, timeout)
69
-
70
- puts response.read_string
71
-
72
- # Disconnect
73
- lxi_disconnect(device)
74
- end
75
-
76
- # Discover LXI devices on the LAN
53
+ # Discover LXI-11 devices on the LAN
77
54
  def self.search(timeout: 1000, type: :vxi11)
78
55
  lxi_init
79
56
 
data/lib/lxi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lxi
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lxi_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Carruthers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-06 00:00:00.000000000 Z
11
+ date: 2023-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -44,7 +44,6 @@ files:
44
44
  - lib/lxi/ffi.rb
45
45
  - lib/lxi/version.rb
46
46
  - lib/lxi_rb.rb
47
- - lxi_rb.gemspec
48
47
  - sig/lxi_rb.rbs
49
48
  homepage: https://github.com/robcarruthers/lxi_rb
50
49
  licenses:
data/lxi_rb.gemspec DELETED
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/lxi/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'lxi_rb'
7
- spec.version = Lxi::VERSION
8
- spec.authors = ['Rob Carruthers']
9
- spec.email = ['robcarruthers@mac.com']
10
-
11
- spec.summary = 'Ruby wrapper for the liblxi library.'
12
- spec.description = 'The gem includes methods required for discovering and communicating with LXI compliant devices'
13
- spec.homepage = 'https://github.com/robcarruthers/lxi_rb'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 3.1.0'
16
-
17
- spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = 'https://github.com/robcarruthers/lxi_rb'
19
- spec.metadata['changelog_uri'] = 'https://github.com/robcarruthers/lxi_rb/-/blob/master/CHANGELOG.md'
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files =
24
- Dir.chdir(__dir__) do
25
- `git ls-files -z`.split("\x0")
26
- .reject do |f|
27
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
28
- end
29
- end
30
- spec.bindir = 'exe'
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ['lib']
33
-
34
- # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
36
- spec.add_dependency 'ffi', '~> 1.15'
37
-
38
- # For more information and examples about making a new gem, check out our
39
- # guide at: https://bundler.io/guides/creating_gem.html
40
- end