Name | arizon-usb-apiserver JSON |
Version |
0.4.7
JSON |
| download |
home_page | |
Summary | Driver for Arizona USB Pressure Sensor |
upload_time | 2023-06-01 06:42:18 |
maintainer | |
docs_url | None |
author | davidliyutong |
requires_python | >=3.7 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ARIZON USB APIServer
![Upload Python Package](https://github.com/mvig-robotflow/arizon_usb_apiserver/workflows/Upload%20Python%20Package/badge.svg)
[![Pypi](https://img.shields.io/pypi/v/arizon_usb_apiserver.svg)](https://pypi.org/project/arizon_usb_apiserver/)
An APIServer for ARIZON USB force sensors.
## Installation
Clone & `cd` into this repository then:
```shell
python setup.py install
```
Or download from PyPI:
```shell
python -m pip install arizon-usb-apiserver
```
## Get Started
The apiserver operates in two modes: RESTful and gRPC. They share the same configuration schema.
### Basics
To read the sensor locally, use this snippet:
```python
from serial import Serial
from arizon_usb_apiserver import Sensor
if __name__ == '__main__':
conn = Serial("COM16", 115200)
sensor = Sensor(conn)
sensor.reset()
while True:
print(sensor.read_once())
```
To generate configuration from command line interaction run:
```shell
python -m arizon_usb_apiserver configure
```
### RESTful
To launch the apiserver in RESTful mode, set the `API_SERVER_RESTFUL` to `1` before run apiserver command:
```shell
export API_SERVER_RESTFUL=1
```
Or run with variable
```shell
API_SERVER_RESTFUL=1 python -m arizon_usb_apiserver apiserver
```
> Powershell: `Set-Item -Path Env:API_SERVER_RESTFUL -Value 1`
Or you can directely run `apiserver.restful`
```shell
python -m arizon_usb_apiserver apiserver.restful
```
Here are some examples to test the apiserver using curl
- Init sensor
```shell
curl -X 'PUT' \
'http://127.0.0.1:8080/v1/arizon/force?flag=true' \
-H 'accept: application/json'
```
- Read sensor
```shell
curl -X 'GET' \
'http://127.0.0.1:8080/v1/arizon/force' \
-H 'accept: application/json'
```
- Shutdown sensor
```shell
curl -X 'PUT' \
'http://127.0.0.1:8080/v1/arizon/force?flag=false' \
-H 'accept: application/json'
```
## gRPC
Run this command
```shell
python -m arizon_usb_apiserver apiserver
```
Or you can directely run `apiserver.grpc`
```shell
python -m arizon_usb_apiserver apiserver.grpc
```
## Testing with cli tools
To test RESTful API, run:
```shell
python -m arizon_usb_apiserver test.restful
```
You will be asked to input API endpoint.
To test gRPC API, run:
```shell
python -m arizon_usb_apiserver test.grpc
```
You will be asked to input API endpoint.
## Generate Client
### Restful
First launch the apiserver, then run `openapi-python-client`:
```shell
openapi-python-client generate --url http://127.0.0.1:8080/openapi.json
rm -rf ./arizon_usb_driver/client/restful
mv fast-api-client/fast_api_client ./arizon_usb_driver/client/restful
rm -rf ./fast-api-client
```
### GRPC
First `cd arizon_usb_apiserver/grpc`, then run:
```shell
python -m grpc_tools.protoc -I../../manifests/protos --python_out=. --pyi_out=. --grpc_python_out=. ../../manifests/protos/force_packet.proto
```
You might need to replace `import force_packet_pb2 as force__packet__pb2` with `import arizon_usb_apiserver.grpc.force_packet_pb2 as force__packet__pb2`
## Serial Protocol
| Field | Content |
| ------------ | ------- |
| Head | 0xFE |
| Status | 1 Byte |
| Data | 3 Byte |
| XOR checksum | 1 Byte |
- Status: 4 bits of address + 4 bits represents number of digits
- Data: 3 bytes of signed integers, no digit, big-endian.
- Checksum: xor() of first 5 bytes
## Configuration
Here is an template of configuration
```yaml
arizon_usb_apiserver: # Key
api: # Control API settings
interface: 0.0.0.0 # Listen interface
port: 8080 # Listen port
debug: false # Enable debug
serials: # Serial connections, can be a list
- baudrate: 115200 # Baudrate, default is 115200, no need to change
port: COM8 # Port name
addr: "dev1" # Friendly name
data_path: ./arizon_data # Path to save data
```
Raw data
{
"_id": null,
"home_page": "",
"name": "arizon-usb-apiserver",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "davidliyutong",
"author_email": "davidliyutong@sjtu.edu.cn",
"download_url": "https://files.pythonhosted.org/packages/3a/37/5f09dc73e65bd7af51387fc922cf6114cbb10451d96128d24672f5d58b2d/arizon-usb-apiserver-0.4.7.tar.gz",
"platform": null,
"description": "# ARIZON USB APIServer\n\n![Upload Python Package](https://github.com/mvig-robotflow/arizon_usb_apiserver/workflows/Upload%20Python%20Package/badge.svg)\n[![Pypi](https://img.shields.io/pypi/v/arizon_usb_apiserver.svg)](https://pypi.org/project/arizon_usb_apiserver/)\n\nAn APIServer for ARIZON USB force sensors.\n\n## Installation\n\nClone & `cd` into this repository then:\n\n```shell\npython setup.py install\n```\n\nOr download from PyPI:\n\n```shell\npython -m pip install arizon-usb-apiserver\n```\n\n## Get Started\n\nThe apiserver operates in two modes: RESTful and gRPC. They share the same configuration schema.\n\n### Basics\n\nTo read the sensor locally, use this snippet:\n\n```python\nfrom serial import Serial\nfrom arizon_usb_apiserver import Sensor\n\nif __name__ == '__main__':\n conn = Serial(\"COM16\", 115200)\n sensor = Sensor(conn)\n sensor.reset()\n while True:\n print(sensor.read_once())\n```\n\nTo generate configuration from command line interaction run:\n\n```shell\npython -m arizon_usb_apiserver configure\n```\n\n### RESTful\n\nTo launch the apiserver in RESTful mode, set the `API_SERVER_RESTFUL` to `1` before run apiserver command:\n\n```shell\nexport API_SERVER_RESTFUL=1\n```\n\nOr run with variable\n\n```shell\nAPI_SERVER_RESTFUL=1 python -m arizon_usb_apiserver apiserver\n```\n\n> Powershell: `Set-Item -Path Env:API_SERVER_RESTFUL -Value 1`\n\nOr you can directely run `apiserver.restful`\n\n```shell\npython -m arizon_usb_apiserver apiserver.restful\n```\n\nHere are some examples to test the apiserver using curl\n\n- Init sensor\n\n ```shell\n curl -X 'PUT' \\\n 'http://127.0.0.1:8080/v1/arizon/force?flag=true' \\\n -H 'accept: application/json'\n ```\n\n- Read sensor\n\n ```shell\n curl -X 'GET' \\\n 'http://127.0.0.1:8080/v1/arizon/force' \\\n -H 'accept: application/json'\n ```\n\n- Shutdown sensor\n\n ```shell\n curl -X 'PUT' \\\n 'http://127.0.0.1:8080/v1/arizon/force?flag=false' \\\n -H 'accept: application/json'\n ```\n\n## gRPC\n\nRun this command\n\n```shell\npython -m arizon_usb_apiserver apiserver\n```\n\nOr you can directely run `apiserver.grpc`\n\n```shell\npython -m arizon_usb_apiserver apiserver.grpc\n```\n\n## Testing with cli tools\n\nTo test RESTful API, run:\n\n```shell\npython -m arizon_usb_apiserver test.restful\n```\n\nYou will be asked to input API endpoint.\n\nTo test gRPC API, run:\n\n```shell\npython -m arizon_usb_apiserver test.grpc\n```\n\nYou will be asked to input API endpoint.\n\n## Generate Client\n\n### Restful\n\nFirst launch the apiserver, then run `openapi-python-client`:\n\n```shell\nopenapi-python-client generate --url http://127.0.0.1:8080/openapi.json\nrm -rf ./arizon_usb_driver/client/restful\nmv fast-api-client/fast_api_client ./arizon_usb_driver/client/restful\nrm -rf ./fast-api-client\n```\n\n### GRPC\n\nFirst `cd arizon_usb_apiserver/grpc`, then run:\n\n```shell\npython -m grpc_tools.protoc -I../../manifests/protos --python_out=. --pyi_out=. --grpc_python_out=. ../../manifests/protos/force_packet.proto\n```\n\nYou might need to replace `import force_packet_pb2 as force__packet__pb2` with `import arizon_usb_apiserver.grpc.force_packet_pb2 as force__packet__pb2`\n\n## Serial Protocol\n\n| Field | Content |\n| ------------ | ------- |\n| Head | 0xFE |\n| Status | 1 Byte |\n| Data | 3 Byte |\n| XOR checksum | 1 Byte |\n\n- Status: 4 bits of address + 4 bits represents number of digits\n- Data: 3 bytes of signed integers, no digit, big-endian.\n- Checksum: xor() of first 5 bytes\n\n## Configuration\n\nHere is an template of configuration\n\n```yaml\narizon_usb_apiserver: # Key\n api: # Control API settings\n interface: 0.0.0.0 # Listen interface\n port: 8080 # Listen port\n debug: false # Enable debug\n serials: # Serial connections, can be a list\n - baudrate: 115200 # Baudrate, default is 115200, no need to change\n port: COM8 # Port name\n addr: \"dev1\" # Friendly name\n data_path: ./arizon_data # Path to save data\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Driver for Arizona USB Pressure Sensor",
"version": "0.4.7",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "895e9bf8d28ecc9241746b9f08cef6c26ef8bb1658134bde7eb088302529f458",
"md5": "cf9becbbc7dfc2f2822ddd4a5ece30ce",
"sha256": "7abefa21f337a60f639739b60a63d9a86b9f6f5ab07af433b0be0f4c91b3cf14"
},
"downloads": -1,
"filename": "arizon_usb_apiserver-0.4.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cf9becbbc7dfc2f2822ddd4a5ece30ce",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 19585,
"upload_time": "2023-06-01T06:42:16",
"upload_time_iso_8601": "2023-06-01T06:42:16.509776Z",
"url": "https://files.pythonhosted.org/packages/89/5e/9bf8d28ecc9241746b9f08cef6c26ef8bb1658134bde7eb088302529f458/arizon_usb_apiserver-0.4.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3a375f09dc73e65bd7af51387fc922cf6114cbb10451d96128d24672f5d58b2d",
"md5": "760eb252d1823474c0a4729201d9ce64",
"sha256": "495b0f7a9bb6171c6b79d8d7bd167f061c91f59b5c5c6a0756dea872a2c3d390"
},
"downloads": -1,
"filename": "arizon-usb-apiserver-0.4.7.tar.gz",
"has_sig": false,
"md5_digest": "760eb252d1823474c0a4729201d9ce64",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 14649,
"upload_time": "2023-06-01T06:42:18",
"upload_time_iso_8601": "2023-06-01T06:42:18.260453Z",
"url": "https://files.pythonhosted.org/packages/3a/37/5f09dc73e65bd7af51387fc922cf6114cbb10451d96128d24672f5d58b2d/arizon-usb-apiserver-0.4.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-01 06:42:18",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "arizon-usb-apiserver"
}