Skip to main content

serial to socket bridge

Project description

ser2sock

Pypi version

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:

pip install ser2sock

Usage

ser2net -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:

bridges = [
    {
        'serial': {'address': '/dev/ttyS0'},
        'tcp': {'address': ("0", 18500)}
    },
    {
        'serial': {'address': '/dev/ttyS1', 'baudrate': 19200},
        'tcp': {'address': ("0", 18501), 'no_delay': False}
    }
]
  • serial: address 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:

bridges = [
    [serial(address="/dev/ttyS0"), tcp(address=("0", 18500))],
    [serial(address="/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:

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

bridges = [
    [serial(address="/dev/ttyS0"), tcp(address=("0", 18500))],
    [serial(address="/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:

$ pip install ser2sock[web]

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

bridges = [...]

web = ':8000'

ser2sock should now be visible here.

You should see something like this:

web screenshot

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

That's all folks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ser2sock-4.1.0.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file ser2sock-4.1.0.tar.gz.

File metadata

  • Download URL: ser2sock-4.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.0.post20200616 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for ser2sock-4.1.0.tar.gz
Algorithm Hash digest
SHA256 9be12bc8eafc39ee24e4900ae33094046cb9bed64c84bdc1b45965c1f696fc6b
MD5 3a9dc6b55f76ce5e34b6364d9f5085e0
BLAKE2b-256 6fb62d71955c1f271cc5f17886c9328962032a04ab7a04881c5dc1311eaf0fee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page