lib-femtican.py
Environment setup
Consult DevBook section 10-50.
If you have conda installed correctly, run conda env create in the root project folder.
How to build this as a package
Change the package version in the pyproject.toml file according to semantic versioning rules.
Inside a conda environment, run:
python -m build . --sdist
Importing the package
pip install [path]/femtican-[version].tar.gz
Importing the package in Thonny IDE
Tools -> Manage packages -> Install from local file -> locate femtican-[version].tar.gz
Usage
Communication happens over NATS. All messages use the FemticanV3 topic.
The default NATS port is 60214.
Listening to broadcasts
import time
from femtican import FemticanClient
client = FemticanClient()
# default port is 60214. If running on host connected to laser system router use port 4222. If you want to use a different IP or port, connect like this:
# e.g. client.connect("172.168.1.2", 4222)
client.connect("cmp.local")
def global_handler(device_id, register_id, value):
match device_id, register_id:
case 208, 49:
print(f"Filtered data {value} from Device: 208, Register: 49")
client.broadcast_handler = global_handler
time.sleep(2)
client.disconnect()
Listening to broadcast (using per-register handlers)
import time
from femtican import FemticanClient
client = FemticanClient()
client.connect("cmp.local") # default port: 60214
def aries_handler(device_id, register_id, value):
print(f"{device_id}-{register_id}----{value} -- aries")
def random_handler(device_id, register_id, value):
print(f"{device_id}-{register_id}----{value} -- random")
client.add_broadcast_handler(162, 50, aries_handler)
client.add_broadcast_handler(162, 48, random_handler)
# optional: trigger a few broadcasts (example)
for _ in range(10):
client.trigger_broadcast(162, 50)
time.sleep(0.05)
# wait for incoming broadcasts
time.sleep(2)
client.remove_broadcast_handler(162, 50)
client.remove_broadcast_handler(162, 48)
client.disconnect()
Triggering a broadcast on a device
from femtican import FemticanClient
client = FemticanClient()
client.connect("cmp.local")
client.trigger_broadcast(208, 49) # device_id, register_id
client.disconnect()
Setting a value to a register
from femtican import FemticanClient
client = FemticanClient()
client.connect("cmp.local")
client.set_register(208, 49, 0) # device_id, register_id, value. Value can be text (string), float or None type
client.set_register_index(208, 49, 1, 3.0) # device_id, register_id, index, value. Value can only be float type
client.disconnect()
Error handling
import time
from femtican import FemticanClient
client = FemticanClient()
client.connect("cmp.local")
def error_handler(error_message):
print(f"Error: {error_message}")
client.error_handler = error_handler
time.sleep(2)
client.disconnect()
Metadata
Release files for femtican 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| femtican-0.4.0.tar.gz | 13.2 kB | Without provenance | Details for femtican-0.4.0.tar.gz |
Release files / femtican-0.4.0.tar.gz
| Download URL | femtican-0.4.0.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a556db845253ac9e9925389932d25519fb71e2c98b6761d286c280484c28a798
|
|
BLAKE2b-256 checksum How to use checksums |
cc9ccc4730797f6c1026001522a372ab82e8404c9a11d109a9f5cef8477b1de2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for femtican 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.