ser2sock


Nameser2sock JSON
Version 4.1.2 PyPI version JSON
download
home_pagehttps://github.com/tiagocoutinho/ser2sock/
Summaryserial to socket bridge
upload_time2023-04-28 05:20:03
maintainer
docs_urlNone
authorJose Tiago Macara Coutinho
requires_python>=2.6
licenseGPLv3+
keywords serial line tcp udp bridge socket server
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ser2sock

![Pypi version][pypi]

A single-threaded, multi serial line to TCP bridge server.

Can run under python 2.6 up to 3.x (tested 3.8).

## Installation

From within your favorite python environment:

```console
pip install ser2sock
```

## Usage

```console
ser2sock -c <configuration file>
```

### Configuration

In order to provide flexibility, configuration is written in python.

The only requirement is to have a `bridges` member which consists of a
sequence of bridges. A bridge is a dictionary with mandatory keys `serial`
and `tcp`.

Example:

```python

bridges = [
    {
        'serial': {'port': '/dev/ttyS0'},
        'tcp': {'address': ("0", 18500)}
    },
    {
        'serial': {'port': '/dev/ttyS1', 'baudrate': 19200},
        'tcp': {'address': ("0", 18501), 'no_delay': False}
    }
]
```

* `serial`: `port` mandatory. Supports any keyword supported by
  `serial.serial_for_url` (or `serial.Serial` if `serial_for_url` does not
  exist
* `tcp`: `address` mandatory (must be a pair bind host and port).
  * `reuse_addr`: (default: True) TCP reuse address
  * `no_delay`: (default: True) disable Nagle's algorithm
  * `tos`: (default: `0x10`, meaning low delay) type of service.

`tcp` and `serial` helpers are automatically loaded to the config namespace.
Here is the equivalent above config using helpers:

```python

bridges = [
    [serial(port="/dev/ttyS0"), tcp(address=("0", 18500))],
    [serial(port="/dev/ttyS1", baudrate=19200),
     tcp(address=("0", 18501), no_delay=False)],
]
```

You are free to put any code in your python configuration file.
Here is an example setting up logging:

```python
import logging
logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s %(levelname)s %(message)s'
)

bridges = [
    [serial(port="/dev/ttyS0"), tcp(address=("0", 18500))],
    [serial(port="/dev/ttyS1", baudrate=19200),
     tcp(address=("0", 18501), no_delay=False)],
]


```

## Web UI

The active configuration can be changed online through a web UI.

To enable web you need to install the extra package:

```console
$ pip install ser2sock[web]
```

...and enable the web app in the configuration with:

```python
bridges = [...]

web = ':8000'
```

ser2sock should now be visible [here](http://localhost:8000).

You should see something like this:

![web screenshot](web_screenshot.png)

Note that changes made with the web interface only affect the
active ser2sock instance and never the original configuration file.

## Tests

Tests should be performed within a python 3.5 or higher environment.

```console
$ python setup.py test

running pytest
Searching for pytest-asyncio
Best match: pytest-asyncio 0.14.0
Processing pytest_asyncio-0.14.0-py3.7.egg

Using /home/tcoutinho/workspace/ser2sock/.eggs/pytest_asyncio-0.14.0-py3.7.egg
Searching for pytest-cov
Best match: pytest-cov 2.10.0
Processing pytest_cov-2.10.0-py3.7.egg

Using /home/tcoutinho/workspace/ser2sock/.eggs/pytest_cov-2.10.0-py3.7.egg
running egg_info
writing ser2sock.egg-info/PKG-INFO
writing dependency_links to ser2sock.egg-info/dependency_links.txt
writing entry points to ser2sock.egg-info/entry_points.txt
writing requirements to ser2sock.egg-info/requires.txt
writing top-level names to ser2sock.egg-info/top_level.txt
reading manifest file 'ser2sock.egg-info/SOURCES.txt'
writing manifest file 'ser2sock.egg-info/SOURCES.txt'
running build_ext
==================================== test session starts =====================================
platform linux -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /home/tcoutinho/miniconda/envs/py37/bin/python
cachedir: .pytest_cache
rootdir: /home/tcoutinho/workspace/ser2sock, inifile: setup.cfg
plugins: cov-2.10.0, asyncio-0.14.0
collected 8 items

tests/test_ser2sock.py::test_load_config PASSED                                        [ 12%]
tests/test_ser2sock.py::test_web_server PASSED                                         [ 25%]
tests/test_ser2sock.py::test_server PASSED                                             [ 37%]
tests/test_ser2sock.py::test_server_no_serial PASSED                                   [ 50%]
tests/test_ser2sock.py::test_server_serial_close_after_success PASSED                  [ 62%]
tests/test_ser2sock.py::test_server_no_client PASSED                                   [ 75%]
tests/test_ser2sock.py::test_server_missing_argument PASSED                            [ 87%]
tests/test_ser2sock.py::test_2_clients_to_1_serial PASSED                              [100%]

----------- coverage: platform linux, python 3.7.7-final-0 -----------
Name                   Stmts   Miss  Cover
------------------------------------------
ser2sock/__init__.py       1      0   100%
ser2sock/server.py       321     56    83%
------------------------------------------
TOTAL                    322     56    83%
Coverage HTML written to dir htmlcov


================================== slowest 2 test durations ==================================
0.02s call     tests/test_ser2sock.py::test_server_no_client
0.02s setup    tests/test_ser2sock.py::test_web_server
===================================== 8 passed in 0.30s ======================================
```

That's all folks!

[pypi]: https://img.shields.io/pypi/pyversions/ser2sock.svg



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tiagocoutinho/ser2sock/",
    "name": "ser2sock",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.6",
    "maintainer_email": "",
    "keywords": "serial line,tcp,udp,bridge,socket,server",
    "author": "Jose Tiago Macara Coutinho",
    "author_email": "coutinhotiago@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b4/09/826c3b72e133073af8447c0a2a854f74dfbf645327931cb77f52b9176a43/ser2sock-4.1.2.tar.gz",
    "platform": null,
    "description": "# ser2sock\n\n![Pypi version][pypi]\n\nA single-threaded, multi serial line to TCP bridge server.\n\nCan run under python 2.6 up to 3.x (tested 3.8).\n\n## Installation\n\nFrom within your favorite python environment:\n\n```console\npip install ser2sock\n```\n\n## Usage\n\n```console\nser2sock -c <configuration file>\n```\n\n### Configuration\n\nIn order to provide flexibility, configuration is written in python.\n\nThe only requirement is to have a `bridges` member which consists of a\nsequence of bridges. A bridge is a dictionary with mandatory keys `serial`\nand `tcp`.\n\nExample:\n\n```python\n\nbridges = [\n    {\n        'serial': {'port': '/dev/ttyS0'},\n        'tcp': {'address': (\"0\", 18500)}\n    },\n    {\n        'serial': {'port': '/dev/ttyS1', 'baudrate': 19200},\n        'tcp': {'address': (\"0\", 18501), 'no_delay': False}\n    }\n]\n```\n\n* `serial`: `port` mandatory. Supports any keyword supported by\n  `serial.serial_for_url` (or `serial.Serial` if `serial_for_url` does not\n  exist\n* `tcp`: `address` mandatory (must be a pair bind host and port).\n  * `reuse_addr`: (default: True) TCP reuse address\n  * `no_delay`: (default: True) disable Nagle's algorithm\n  * `tos`: (default: `0x10`, meaning low delay) type of service.\n\n`tcp` and `serial` helpers are automatically loaded to the config namespace.\nHere is the equivalent above config using helpers:\n\n```python\n\nbridges = [\n    [serial(port=\"/dev/ttyS0\"), tcp(address=(\"0\", 18500))],\n    [serial(port=\"/dev/ttyS1\", baudrate=19200),\n     tcp(address=(\"0\", 18501), no_delay=False)],\n]\n```\n\nYou are free to put any code in your python configuration file.\nHere is an example setting up logging:\n\n```python\nimport logging\nlogging.basicConfig(\n    level=logging.DEBUG,\n    format='%(asctime)s %(levelname)s %(message)s'\n)\n\nbridges = [\n    [serial(port=\"/dev/ttyS0\"), tcp(address=(\"0\", 18500))],\n    [serial(port=\"/dev/ttyS1\", baudrate=19200),\n     tcp(address=(\"0\", 18501), no_delay=False)],\n]\n\n\n```\n\n## Web UI\n\nThe active configuration can be changed online through a web UI.\n\nTo enable web you need to install the extra package:\n\n```console\n$ pip install ser2sock[web]\n```\n\n...and enable the web app in the configuration with:\n\n```python\nbridges = [...]\n\nweb = ':8000'\n```\n\nser2sock should now be visible [here](http://localhost:8000).\n\nYou should see something like this:\n\n![web screenshot](web_screenshot.png)\n\nNote that changes made with the web interface only affect the\nactive ser2sock instance and never the original configuration file.\n\n## Tests\n\nTests should be performed within a python 3.5 or higher environment.\n\n```console\n$ python setup.py test\n\nrunning pytest\nSearching for pytest-asyncio\nBest match: pytest-asyncio 0.14.0\nProcessing pytest_asyncio-0.14.0-py3.7.egg\n\nUsing /home/tcoutinho/workspace/ser2sock/.eggs/pytest_asyncio-0.14.0-py3.7.egg\nSearching for pytest-cov\nBest match: pytest-cov 2.10.0\nProcessing pytest_cov-2.10.0-py3.7.egg\n\nUsing /home/tcoutinho/workspace/ser2sock/.eggs/pytest_cov-2.10.0-py3.7.egg\nrunning egg_info\nwriting ser2sock.egg-info/PKG-INFO\nwriting dependency_links to ser2sock.egg-info/dependency_links.txt\nwriting entry points to ser2sock.egg-info/entry_points.txt\nwriting requirements to ser2sock.egg-info/requires.txt\nwriting top-level names to ser2sock.egg-info/top_level.txt\nreading manifest file 'ser2sock.egg-info/SOURCES.txt'\nwriting manifest file 'ser2sock.egg-info/SOURCES.txt'\nrunning build_ext\n==================================== test session starts =====================================\nplatform linux -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /home/tcoutinho/miniconda/envs/py37/bin/python\ncachedir: .pytest_cache\nrootdir: /home/tcoutinho/workspace/ser2sock, inifile: setup.cfg\nplugins: cov-2.10.0, asyncio-0.14.0\ncollected 8 items\n\ntests/test_ser2sock.py::test_load_config PASSED                                        [ 12%]\ntests/test_ser2sock.py::test_web_server PASSED                                         [ 25%]\ntests/test_ser2sock.py::test_server PASSED                                             [ 37%]\ntests/test_ser2sock.py::test_server_no_serial PASSED                                   [ 50%]\ntests/test_ser2sock.py::test_server_serial_close_after_success PASSED                  [ 62%]\ntests/test_ser2sock.py::test_server_no_client PASSED                                   [ 75%]\ntests/test_ser2sock.py::test_server_missing_argument PASSED                            [ 87%]\ntests/test_ser2sock.py::test_2_clients_to_1_serial PASSED                              [100%]\n\n----------- coverage: platform linux, python 3.7.7-final-0 -----------\nName                   Stmts   Miss  Cover\n------------------------------------------\nser2sock/__init__.py       1      0   100%\nser2sock/server.py       321     56    83%\n------------------------------------------\nTOTAL                    322     56    83%\nCoverage HTML written to dir htmlcov\n\n\n================================== slowest 2 test durations ==================================\n0.02s call     tests/test_ser2sock.py::test_server_no_client\n0.02s setup    tests/test_ser2sock.py::test_web_server\n===================================== 8 passed in 0.30s ======================================\n```\n\nThat's all folks!\n\n[pypi]: https://img.shields.io/pypi/pyversions/ser2sock.svg\n\n\n",
    "bugtrack_url": null,
    "license": "GPLv3+",
    "summary": "serial to socket bridge",
    "version": "4.1.2",
    "split_keywords": [
        "serial line",
        "tcp",
        "udp",
        "bridge",
        "socket",
        "server"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b409826c3b72e133073af8447c0a2a854f74dfbf645327931cb77f52b9176a43",
                "md5": "756616894a7d737362d2a9db0e877093",
                "sha256": "84562f8b9b30fa62b40355790b7e4631c73a33811dfe60c06a751c1ac1cc6aed"
            },
            "downloads": -1,
            "filename": "ser2sock-4.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "756616894a7d737362d2a9db0e877093",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.6",
            "size": 11285,
            "upload_time": "2023-04-28T05:20:03",
            "upload_time_iso_8601": "2023-04-28T05:20:03.827368Z",
            "url": "https://files.pythonhosted.org/packages/b4/09/826c3b72e133073af8447c0a2a854f74dfbf645327931cb77f52b9176a43/ser2sock-4.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-28 05:20:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "tiagocoutinho",
    "github_project": "ser2sock",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ser2sock"
}
        
Elapsed time: 0.12754s