ORiN3を使ってデバイスにアクセスしてみる - ruby編
はじめに
今回は、rubyでORiN3にアクセスしてみようと思います。
1. 前準備
プロキシ設定
もしネットワークがプロキシ経由になっている場合、APTコマンドもプロキシ設定が必要です。
以下の設定ファイルを確認してください。
$ sudo nano /etc/apt/apt.conf.d/95proxies
設定例:
Acquire::http::Proxy "http://<プロキシのIP>:<ポート>";
Acquire::https::Proxy "http://<プロキシのIP>:<ポート>";
プロキシを使用していない場合、この手順はスキップできます。
Ubuntuのバージョンなど
以下の環境で試してみた結果を記事に書いています。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble
2. RubyGemの設定
$ mkdir orin3ruby
$ cd orin3ruby/
$ gem install --user-install grpc-orin3-provider
3. プロバイダの設定
以下の記事を参考にしていただきORiN3プロバイダーをインストールしてみてください。
今回はMockプロバイダー(version.1.1.0)を使用します。
4. サンプルプログラムを使ったデータアクセス
これで準備は完了です。
以下のコードを実行すればTrue/Falseの値が10回出力されるはずです。
require 'uri'
require 'grpc/orin3/provider'
module ORiN3
include Grpc::Client::ORiN3
include Grpc::Client::ORiN3::Provider
end
def main
channel = GRPC::Core::Channel.new("localhost:51234", nil, :this_channel_is_insecure)
remote_engine = ORiN3::RemoteEngine.new(channel)
id = "643D12C8-DCFC-476C-AA15-E8CA004F48E8"
version = "[1.0.0,2.0.0)"
result = remote_engine.wakeup_provider(id, version, "0.0.0.0", 0)
puts "* wakeup mock provider done. [uri=#{result.provider_information.endpoints[0].uri}]"
uri = URI.parse(result.provider_information.endpoints[0].uri)
provider_channerl = GRPC::Core::Channel.new("localhost:#{uri.port}", nil, :this_channel_is_insecure)
root = ORiN3::ORiN3RootObject.attach(provider_channerl)
puts "Root.name: #{root.name}"
puts "Root.type_name: #{root.type_name}"
puts "Root.option: #{root.option}"
puts "Root.created_datetime: #{root.created_datetime.getlocal}"
puts "Root.orin3_object_type: #{root.orin3_object_type}"
puts "Root.id: #{root.id}"
controller = root.create_controller("GeneralPurposeController",
"ORiN3.Provider.ORiNConsortium.Mock.O3Object.Controller.GeneralPurposeController, ORiN3.Provider.ORiNConsortium.Mock",
'{"@Version":"1.1.0"}')
controller.connect
variable = controller.create_variable("PulseWaveBoolVariable",
"ORiN3.Provider.ORiNConsortium.Mock.O3Object.Variable.PulseWaveBoolVariable, ORiN3.Provider.ORiNConsortium.Mock",
'{"@Version":"1.1.0"}', :ORIN3_BOOL)
10.times do |i|
puts variable.get_value
sleep 0.5
end
root.shutdown
end
main
実行結果:
$ ruby accessToOrin3.rb
* wakeup mock provider done. [uri=http://0.0.0.0:35875/]
Root.name: Root
Root.type_name: ORiN3.Provider.ORiNConsortium.Mock.O3Object.Root.MockRootObject, ORiN3.Provider.ORiNConsortium.Mock
Root.option: {}
Root.created_datetime: 2025-05-14 13:14:40 +0900
Root.orin3_object_type: PROVIDER_ROOT
Root.id: ff83baff-0756-1042-906d-f6f8ae00a7f7
false
false
true
true
false
false
true
true
false
false
関連情報(公式)
関連情報