{"id":21991541,"url":"https://github.com/terrabits/instrument-server-command-plugin-example","last_synced_at":"2026-04-29T10:06:06.909Z","repository":{"id":98389502,"uuid":"470336322","full_name":"Terrabits/instrument-server-command-plugin-example","owner":"Terrabits","description":"Instrument Server Command Plugin Example is an Instrument Server microservice which responds to one command:  is_rs_devices?","archived":false,"fork":false,"pushed_at":"2022-03-15T21:24:42.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-15T23:18:58.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Terrabits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-15T21:24:28.000Z","updated_at":"2022-03-15T21:24:45.000Z","dependencies_parsed_at":"2023-03-27T23:50:13.984Z","dependency_job_id":null,"html_url":"https://github.com/Terrabits/instrument-server-command-plugin-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Terrabits/instrument-server-command-plugin-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Terrabits%2Finstrument-server-command-plugin-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Terrabits%2Finstrument-server-command-plugin-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Terrabits%2Finstrument-server-command-plugin-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Terrabits%2Finstrument-server-command-plugin-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Terrabits","download_url":"https://codeload.github.com/Terrabits/instrument-server-command-plugin-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Terrabits%2Finstrument-server-command-plugin-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32420399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T20:09:40.150Z","updated_at":"2026-04-29T10:06:06.904Z","avatar_url":"https://github.com/Terrabits.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Instrument Server Command Plugin Example\n\nInstrument Server Command Plugin Example is an [Instrument Server](https://github.com/Terrabits/instrument-server) microservice which responds to one command:\n\n`is_rs_devices?`\n\n## Requirements\n\n-   Python ~= 3.7\n-   instrument-server ~= 1.3.7\n-   *At least one* R\u0026S Instrument\n\n## Install\n\nRun `scripts/install` to install a known-good package and version set.\n\nSee the lock file for details:\n\n[requirements.txt.lock](./requirements.txt.lock)\n\n## Instrument Server Command Plugins\n\nThe Instrument Server Command Plugin interface can be used to implement commands in python.\n\nCommand Plugins are implemented as classes with a specific interface. They are typically subclasses of the `instrument_server.command.Base` class.\n\nCommand Plugins must implement the following methods.\n\n```python\nCommand.is_match(self, received_command)\nCommand.execute(self, received_command)\n```\n\n### is_match\n\n```python\ndef is_match(self, received_command):\n  return True or False\n```\n\nThe `is_match` method should return `True` if this class can `execute` the `received_command`; it should return `False` otherwise.\n\nNote that `received_command` is of type `bytes`.\n\n### execute\n\n```python\ndef execute(self, received_command):\n  return optional_result\n```\n\nIf `is_match` returns `True`, the `execute` method will be called. `execute` should perform the work associated with the `received_command` (type: `bytes`), and can optionally return a result.\n\nThe input `received_command` is provided for argument parsing.\n\nThe command `Base` class provides the `self.devices` property (type: `dict`) for device communcation:\n\n```python\nself.devices['name']  # =\u003e object\n```\n\nNote that devices are referenced by their `name` from the project YAML config file.\n\n## `is_rs_devices?` Command\n\nThe `IsRsDevices` Command Plugin can be found in [plugins/commands/is_rs_devices.py](plugins/commands/is_rs_devices.py).\n\n### `is_match`\n\n`is_match` should only return true if the `received_command` is `is_rs_devices?`.\n\n```python\ndef is_match(self, received_command):\n      return received_command.strip() == b'is_rs_devices?'\n```\n\n### `execute`\n\nAs noted above, connected `devices` can be accessed via the `self.devices` property (type: `dict`).\n\n```python\ndef execute(self, received_command):\n      for device in self.devices.values():\n          id_string = device.query(b'*IDN?\\n').strip()\n          if b'ROHDE' not in id_string.upper():\n              # not R\u0026S device\n              return b'false'\n\n      # all devices R\u0026S\n      return b'true'\n```\n\nThis implementation loops through each device *object*, queries `*IDN?`, then performs a case-insensitive search for the substring `rohde`.\n\nIt returns `false` if any device `*IDN?` response does not contain `rohde` (case-insensitive). Otherwise it returns `true`.\n\n## Project Config File\n\nEvery `instrument-server` project is required to include a YAML config file. By convention, the config file must contain the following sections:\n\n```yaml\nplugins: {...}\ndevices: {...}\n# Translation Commands (Optional)\n...\n```\n\nThe config file for this project is [command_plugin_example.yaml](command_plugin_example.yaml). Each section of the file is explained below.\n\n### Plugins\n\n```yaml\nplugins:\n  plugins.commands.is_rs_devices: {}\n```\n\nThe `is_rs_devices?` command plugin is referenced for import. No plugin configuration settings are provided.\n\n### Devices\n\n```yaml\ninstrument:\n  type:        socket\n  address:     localhost\n  port:        5025\n  timeout:     5\n```\n\n`instrument` is the only device declared. It uses the (TCP) `socket` connection type.\n\nEdit the `address` field to match the address of the R\u0026S Instrument.\n\n### Translation Commands\n\nAn `instrument-server` project file may include `Translation` command definition(s).\n\nNo Translation commands are defined in this project.\n\n## Start\n\nRun `scripts/start` to serve `command_plugin_example.yaml` on all network interfaces on port `9000`.\n\n`scripts/start` calls the `instrument-server` Command Line Interface (CLI), which provides additional settings.\n\nFrom `instrument-server --help`:\n\n```comment\nusage: instrument-server [-h] [--address ADDRESS] [--port PORT]\n                         [--termination TERMINATION] [--debug-mode]\n                         config_filename\n\nCommand Line Interface for starting Instrument Server microservices\n\npositional arguments:\n  config_filename\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --address ADDRESS, -a ADDRESS\n                        Set listening address. Default: 0.0.0.0\n  --port PORT, -p PORT  Set listening port. Default: random\n  --termination TERMINATION, -t TERMINATION\n                        Set the termination character. Default: \"\\n\"\n  --debug-mode, -d      print debug info to stdout\n```\n\n## Client Script\n\nThe `client.py` script is provided for testing. It connects to the Instrument Server Command Plugin Example microservice, sends `init`, then checks for errors.\n\n`client.py` can be run from the command line as follows:\n\n```shell\nscripts/start-in-background\n# =\u003e Running on 0.0.0.0:9000...\n\n# run client\npython client.py\n# =\u003e is_rs_devices? true\n```\n\n## References\n\n-   [Introduction to YAML](https://dev.to/paulasantamaria/introduction-to-yaml-125f)\n-   [instrument-server](https://github.com/Terrabits/instrument-server)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrabits%2Finstrument-server-command-plugin-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterrabits%2Finstrument-server-command-plugin-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrabits%2Finstrument-server-command-plugin-example/lists"}