lxi_rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79bb0d516f205bcdeeb9dd3e12d685fde5237c481b66ec02d80b54e22bd393ce
4
+ data.tar.gz: f713c4887fae97699c9c26a9a42e7b7b8308b7d615529889c53e41a843bc2a6a
5
+ SHA512:
6
+ metadata.gz: def303af335abcb996b9f88709a8901da0b298e7687f46e72dbee56d451ea033972672c6f4a17e19ae9ce30a14cf34d92e5891472769e735d22c22718c019b07
7
+ data.tar.gz: c92a6342c28c3ba4d60d0480cd394d2ba6fa804c9abe0bf18b1327909fe43fa6ddc2edfb0ff3fd22abc66ac91b6ffeeaa72beea247ca08606c9bbc944e11753a
data/.streerc ADDED
@@ -0,0 +1 @@
1
+ /Users/rob/.streerc
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-05-02
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in lxi_rb.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lxi_rb (0.1.0)
5
+ ffi (~> 1.15)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ ffi (1.15.5)
12
+ json (2.6.3)
13
+ minitest (5.18.0)
14
+ parallel (1.22.1)
15
+ parser (3.2.1.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.1.1)
18
+ rake (13.0.6)
19
+ regexp_parser (2.6.2)
20
+ rexml (3.2.5)
21
+ rubocop (1.46.0)
22
+ json (~> 2.3)
23
+ parallel (~> 1.10)
24
+ parser (>= 3.2.0.0)
25
+ rainbow (>= 2.2.2, < 4.0)
26
+ regexp_parser (>= 1.8, < 3.0)
27
+ rexml (>= 3.2.5, < 4.0)
28
+ rubocop-ast (>= 1.26.0, < 2.0)
29
+ ruby-progressbar (~> 1.7)
30
+ unicode-display_width (>= 2.4.0, < 3.0)
31
+ rubocop-ast (1.26.0)
32
+ parser (>= 3.2.1.0)
33
+ ruby-progressbar (1.11.0)
34
+ unicode-display_width (2.4.2)
35
+
36
+ PLATFORMS
37
+ arm64-darwin-22
38
+
39
+ DEPENDENCIES
40
+ lxi_rb!
41
+ minitest (~> 5.0)
42
+ rake (~> 13.0)
43
+ rubocop (~> 1.21)
44
+
45
+ BUNDLED WITH
46
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Rob Carruthers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # lxi_rb
2
+
3
+ ![Gem](https://img.shields.io/gem/v/lxi_rb?color=green&label=version) ![Ruby](https://img.shields.io/static/v1?message=Ruby&color=red&logo=Ruby&logoColor=FFFFFF&label=v3.2.1) ![Ruby](https://img.shields.io/gitlab/license/robcarruthers/rfbeam?color=orange)
4
+
5
+ Ruby wrapper for the [liblxi](https://github.com/lxi-tools/liblxi) library.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add lxi_rb
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install lxi_rb
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ ❯ irb
21
+ irb(main):001:0> require 'lxi_rb'
22
+ => true
23
+
24
+ irb(main):002:0> Lxi.search
25
+ Searching for LXI devices - please wait...
26
+
27
+ Broadcast: 127.0.0.1, lo0
28
+ Broadcast: 192.168.10.255, en0
29
+ Device: 192.168.10.21, Siglent Technologies,SDS1104X-E,SDSMMGKC6R0011,8.2.6.1.37R8
30
+ Device: 192.168.10.107, Siglent Technologies,SDM3055-SC,SDM35GBQ6R1882,1.01.01.25
31
+ => nil
32
+
33
+ irb(main):003:0> Lxi.scpi '192.168.10.21', 0, nil, :vxi11, '*IDN?'
34
+ Siglent Technologies,SDS1104X-E,SDSMMGKC6R0011,8.2.6.1.37R8
35
+ => 0
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lxi_rb.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/lib/lxi/device.rb ADDED
@@ -0,0 +1,50 @@
1
+ module Lxi
2
+ class Device
3
+ include FFI
4
+ attr_accessor :id, :address, :port, :name, :timeout, :protocol
5
+
6
+ def initialize(address, protocol)
7
+ @address = address
8
+ @port = 0
9
+ @name = nil
10
+ @timeout = 1000
11
+ @protocol = protocol
12
+ @id = -1
13
+
14
+ connect
15
+
16
+ yield self if block_given?
17
+ end
18
+
19
+ def connect
20
+ raise Error, 'LXI Library Initialisation Error' unless Lxi.lxi_init == Lxi::OK
21
+
22
+ @id = Lxi.lxi_connect(@address, @port, @name, @timeout, @protocol)
23
+ raise Error, 'LXI Connection Error' if @id == Lxi::ERROR
24
+
25
+ true
26
+ end
27
+ alias open connect
28
+
29
+ def disconnect
30
+ Lxi.lxi_disconnect(@id)
31
+ end
32
+ alias close disconnect
33
+
34
+ def send(message)
35
+ bytes_sent = Lxi.lxi_send(@id, message, message.length, @timeout)
36
+ raise Error, 'LXI communications error' unless bytes_sent.positive?
37
+
38
+ bytes_sent
39
+ end
40
+ alias scpi send
41
+ alias write send
42
+
43
+ def read(length)
44
+ message = FFI::MemoryPointer.new(:char, length)
45
+ raise Error, 'LXI communications error' unless Lxi.lxi_receive(@id, message, length, @timeout).positive?
46
+ message.read_string
47
+ end
48
+ alias gets read
49
+ end
50
+ end
data/lib/lxi/ffi.rb ADDED
@@ -0,0 +1,90 @@
1
+ require 'ffi'
2
+
3
+ module Lxi
4
+ extend FFI::Library
5
+
6
+ # Set the path to the library
7
+ ffi_lib '/opt/homebrew/lib/liblxi.dylib'
8
+ ffi_lib_flags :now, :global
9
+
10
+ # Define the enums
11
+ enum :lxi_protocol_type, %i[vxi11 raw hyslip]
12
+ enum :lxi_discover_type, %i[vxi11 mdns]
13
+
14
+ # Callbacks
15
+ BroadcastCallback =
16
+ FFI::Function.new(:void, %i[pointer pointer]) do |address, interface|
17
+ puts "Broadcast: #{address.read_string}, #{interface.read_string}"
18
+ end
19
+
20
+ DeviceCallback =
21
+ FFI::Function.new(:void, %i[pointer pointer]) do |address, id|
22
+ puts "Device: #{address.read_string}, #{id.read_string}"
23
+ end
24
+
25
+ ServiceCallback =
26
+ FFI::Function.new(:void, %i[pointer pointer pointer int]) do |address, id, service, port|
27
+ puts "Service: #{address.read_string}, #{id.read_string}, #{service.read_string}, #{port}"
28
+ end
29
+
30
+ # Define the structs
31
+ class LxiInfo < FFI::Struct
32
+ layout :broadcast,
33
+ callback(%i[pointer pointer], :void),
34
+ :device,
35
+ callback(%i[pointer pointer], :void),
36
+ :service,
37
+ callback(%i[pointer pointer pointer int], :void)
38
+ end
39
+
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
77
+ def self.search(timeout: 1000, type: :vxi11)
78
+ lxi_init
79
+
80
+ info = LxiInfo.new
81
+ info[:broadcast] = BroadcastCallback
82
+ info[:device] = DeviceCallback
83
+
84
+ puts "Searching for LXI devices - please wait...\n\n"
85
+
86
+ result = lxi_discover_internal(info, timeout, type)
87
+
88
+ puts "Error during discovery: #{result}" if result < 0
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lxi
4
+ VERSION = '0.1.0'
5
+ end
data/lib/lxi_rb.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lxi/version'
4
+ require_relative 'lxi/ffi'
5
+ require_relative 'lxi/device'
6
+
7
+ module Lxi
8
+ class Error < StandardError
9
+ end
10
+ # Your code goes here...
11
+ end
data/lxi_rb.gemspec ADDED
@@ -0,0 +1,40 @@
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
data/sig/lxi_rb.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module LxiRb
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lxi_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Carruthers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ description: The gem includes methods required for discovering and communicating with
28
+ LXI compliant devices
29
+ email:
30
+ - robcarruthers@mac.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".streerc"
36
+ - ".tool-versions"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/lxi/device.rb
44
+ - lib/lxi/ffi.rb
45
+ - lib/lxi/version.rb
46
+ - lib/lxi_rb.rb
47
+ - lxi_rb.gemspec
48
+ - sig/lxi_rb.rbs
49
+ homepage: https://github.com/robcarruthers/lxi_rb
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/robcarruthers/lxi_rb
54
+ source_code_uri: https://github.com/robcarruthers/lxi_rb
55
+ changelog_uri: https://github.com/robcarruthers/lxi_rb/-/blob/master/CHANGELOG.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.3.26
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Ruby wrapper for the liblxi library.
75
+ test_files: []