{"id":15294081,"url":"https://github.com/twinleaf/tio-python","last_synced_at":"2025-04-13T13:31:03.212Z","repository":{"id":27625990,"uuid":"114689999","full_name":"twinleaf/tio-python","owner":"twinleaf","description":"Twinleaf I/O Python module","archived":false,"fork":false,"pushed_at":"2024-11-20T18:11:02.000Z","size":2478,"stargazers_count":13,"open_issues_count":3,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-11T19:16:05.474Z","etag":null,"topics":["linux","macos"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twinleaf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2017-12-18T21:34:18.000Z","updated_at":"2024-11-20T18:11:06.000Z","dependencies_parsed_at":"2024-10-14T22:40:55.255Z","dependency_job_id":null,"html_url":"https://github.com/twinleaf/tio-python","commit_stats":{"total_commits":169,"total_committers":5,"mean_commits":33.8,"dds":"0.035502958579881616","last_synced_commit":"35dbb7a2506413d48c8ffc533b54b4f590dacf84"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twinleaf%2Ftio-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twinleaf%2Ftio-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twinleaf%2Ftio-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twinleaf%2Ftio-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twinleaf","download_url":"https://codeload.github.com/twinleaf/tio-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248720990,"owners_count":21151022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["linux","macos"],"created_at":"2024-09-30T16:57:23.668Z","updated_at":"2025-04-13T13:31:01.821Z","avatar_url":"https://github.com/twinleaf.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Twinleaf I/O\n\nThis package implements a communications protocol in python to work with [Twinleaf sensors](http://www.twinleaf.com) using [Twinleaf I/O (TIO)](https://github.com/twinleaf/libtio/blob/master/doc/TIO%20Protocol%20Overview.md) as the communications layer. Data from the sensors is received via PUB messages and sensor parameters may be changed using REQ/REP messages. \n\n![itio](doc/tio_monitor.gif)\n\n## Use\n\nTwo example scripts are installed with this package:\n\n  - itio: A interactive session for configuring devices\n  - tio_monitor: A live graph of streamed data (does not work on windows)\n\nThese examples can be called with \"url\" that is either a serial port (`/dev/cu.usbserialXXXXXX`, `/dev/ttyUSBx`, `COMx`) or a net url such as `tcp://localhost`. \n\n![itio](doc/itio.gif)\n\n## Prerequisites\n\n[Python](https://www.python.org/downloads/) \u003e= 3.6 is required.\n\n  - Windows may install via the [Microsoft Store](https://www.microsoft.com/store/productId/9PJPW5LDXLZ5) \n  - macOS may consider installing with [Homebrew](https://brew.sh): `brew install python3`\n  - linux may use your native package manager; on debian/ubuntu use: `sudo apt-get install python3`.\n\nThe interactive prompt is a lot better if ipython is available (`pip3 install ipython`).\n\n## Installation\n\n`tio-python` is uploaded to [PyPI](https://pypi.org) and can be installed/upgraded using `pip`:\n\n  - `pip3 install tio --upgrade`\n\nWindows users who can't run python might need to [add python to their path](https://www.pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/).\n\nWindows users who run into an error installing packages may need to [enable long paths](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation).\n\nWindows console scripts are installed in an odd folder which may be added to your path:\n\n  C:\\Users\\username\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\Scripts\n\nWhen installed without sudo on macOS, add the following to your `~/.zshrc`:\n\n  export PATH=/Users/user/Library/Python/3.9/bin:$PATH\n\n\n### Optional installation\n\niPython greatly enhances the interactive itio.py program. It is possible to explore the properties of a device by using tab completion to see available properties and methods. Get it\n\n  - macOS/linux: `pip3 install ipython`\n  - Windows: `py -m pip install ipython`\n\n\n## Performance\n\nSadly, python is not the best choice for fast data processing. If the background thread ingesting the data does not keep up with the data rate, it exits with an error.\n\nAt the moment, the native serial interface is significantly slower than the TCP version. As a result, we recommend that users use the TCP proxy program found in [tio-tools](https://github.com/twinleaf/tio-tools) to manage the serial port in C and convert the data into a TCP stream. The proxy has the added advantage that multiple clients can simultaneously connect to the sensor and use the data. \n\nTerminal #1: serial proxy\n\n    $ bin/proxy /dev/ttyUSB0\n\nTerminal #2: your python program\n\n    $ itio.py\n    ...\n\nwhere the proxy serves to port 7855 and itio by default connects to that port on localhost. This also permits more interesting networking topologies and distributed signal anslysis possible.\n\n## Programming\n\nThe `tldevice` module performs metaprogramming to construct an object that has methods that match the RPC calls available on the device. It uses the `tio` module, a lower-level library for connecting and managing a communication session. To interact with a Twinleaf CSB current supply, a script would look like:\n\n```python\nimport tldevice\ncsb = tldevice.Device('COM1')\ncsb.coil.x.current(0.25) # mA\n```\n\nTo receive data streams from a sensor such as the [Twinleaf VMR vector magnetometer](http://www.twinleaf.com/vector/VMR), it is possible to use the named streams such as vmr.gmr(duration=1) to get one second of data. To get the data from all the streams synchronously, use the iterator at vmr.data.stream_iter(). A simple logging program for the VMR vector magnetometer would look like this:\n\n```python\nimport tldevice\nvmr = tldevice.Device()\nfile = open('log.tsv','w') \nfor row in vmr.data.iter():\n  rowstring = \"\\t\".join(map(str,row))+\"\\n\"\n  file.write(rowstring)\n```\n\n## TODO\n\n  - [x] Threaded session management\n  - [ ] Attempt automatic reconnection on loss of port\n  - [ ] stream_iter smarter should terminate if the setup changes","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwinleaf%2Ftio-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwinleaf%2Ftio-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwinleaf%2Ftio-python/lists"}