Skip to main content

A tool to remember and detect communication ports using hardware identifiers

Project description

COMtacts

This is a tool to remember and detect communication ports using hardware identifiers.

Usage

Add a contact

Lets assume you've plugged in a USB device and you know it is currently at port "COM3". We will use COMtacts to remember this hardware so next time you plug it in, we can find it even if its not at "COM3".

comtacts add --name "My USB Device" --port "COM3"

To overwrite an existing contact:

comtacts add --name "My USB Device" --port "COM3" --overwrite

or if you're in python already:

from comtacts import add_port
add_port(name="My USB Device", port="COM3", overwrite=False) # or overwrite=True, up to you

Get the port of a contact

comtacts get --name "My USB Device"

or if you're in python already:

from comtacts import get_port
get_port(name="My USB Device")

Typical usage would be to let your Python script automatically find the port of a device.

from serial import Serial
from comtacts import get_port

ser = Serial(
    port = get_port(name="My USB Device"),
    baudrate = 9600,
    timeout = 1
)

List all contacts

comtacts all

or if you're in python already:

from comtacts import all_contacts
all_contacts()

See where contacts are stored

comtacts where

Advanced usage -- finding a contact using hardware identifiers

Under the hood, COMtacts uses serial.tools.list_ports.comports() to find serial ports. list_ports.comports() returns a list of serial.tools.list_ports.ListPortInfo objects, which have attributes that can be used to identify a device. If you know the values of these attributes for your device, you can use them to find the port. See the documentation on these functions to see which attributes are available.

For example, if you know the manufacturer, vid, and pid of your device, you can use the manufacturer, vid, and pid attributes to find the port:

from comtacts import get_port_with_attributes
get_port_with_attributes(manufacturer="My Manufacturer", vid="0403", pid="6001")

Making contacts available to all python environments

By default, COMtacts saves contacts inside its package directory. This was done such that contacts are specific to a python environment -- most of my use cases are specific to a certain application. If you would like to make contacts available to all python environments, you can set the COMTACTS_DIR environment variable to the directory where you would like to save contacts.

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

comtacts-0.1.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comtacts-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file comtacts-0.1.0.tar.gz.

File metadata

  • Download URL: comtacts-0.1.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for comtacts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ced4fa1172a00359a7022358b6bb8c8dad98a9945770efc9ead2a2aa58e584fa
MD5 4c24a817b6718152a359a1b687558edb
BLAKE2b-256 0b9ebea4fca0519b2dc78ffad6499b0f891fee57f15ab69be67aa815d6b1a6a6

See more details on using hashes here.

File details

Details for the file comtacts-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: comtacts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for comtacts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9966a0bf52dc0f0ae50f1c75f7959d822914d193b90a0d9311166c4580f1dcca
MD5 b5a824eb3cc4659d3f8e9c1f2ba15451
BLAKE2b-256 2bcbacc18f0937f67af4139cf7bf6a4ce6a3f4baa21ff3fcfc8550a96580e208

See more details on using hashes here.

Supported by

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