Skip to content

Commit ca0a05c

Browse files
untzagpre-commit-ci[bot]ksunden
authored
add new daemon for iseries controlers (#28)
* add new daemon for iseries controlers * add * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changelog * type ignore * Update .github/workflows/run-entry-points.yml Co-authored-by: Kyle Sunden <git@ksunden.space> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kyle Sunden <git@ksunden.space>
1 parent 3717a64 commit ca0a05c

File tree

7 files changed

+432
-1
lines changed

7 files changed

+432
-1
lines changed

.github/workflows/run-entry-points.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ jobs:
2727
run: |
2828
yaqd-omega-platinum --version
2929
yaqd-omega-platinum --help
30+
yaqd-omega-iseries-modbus --version
31+
yaqd-omega-iseries-modbus --help

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
55

66
## [Unreleased]
77

8+
### Added
9+
- new daemon for iseries controllers supporting modbus
10+
811
## [2023.1.0]
912

1013
### Changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ yaq daemons for Omega Engineering hardware
1111

1212
This package contains the following daemon(s):
1313

14+
- https://yaq.fyi/daemons/omega-iseries-modbus
1415
- https://yaq.fyi/daemons/omega-platinum
1516

1617
Maintainers:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ home-page = "https://yaq.fyi"
1010
description-file = "README.md"
1111
requires-python = ">=3.7"
1212
requires = ["yaqd-core>=2020.06.3",
13+
"minimalmodbus",
1314
"pymodbus>=3.1"]
1415
classifiers = [
1516
"Development Status :: 2 - Pre-Alpha",
@@ -33,7 +34,7 @@ dev = ["black", "pre-commit"]
3334

3435
[tool.flit.scripts]
3536
yaqd-omega-platinum = "yaqd_omega._omega_platinum:OmegaPlatinum.main"
36-
37+
yaqd-omega-iseries-modbus = "yaqd_omega._omega_iseries_modbus:OmegaIseriesModbus.main"
3738

3839
[tool.black]
3940
line-length = 99
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
__all__ = ["OmegaPlatinum"]
2+
3+
import asyncio
4+
from typing import Dict, Any, List
5+
import struct
6+
7+
import minimalmodbus # type: ignore
8+
from yaqd_core import UsesSerial, UsesUart, IsDaemon, HasPosition
9+
10+
11+
parity_options = {"even": "E", "odd": "O", "none": "N"}
12+
13+
stop_bit_options = {"one": 1, "one_and_half": 1.5, "two": 2}
14+
15+
PV_REGISTER = 39
16+
17+
SV_REGISTER = 1
18+
19+
20+
# https://bl831.als.lbl.gov/~gmeigs/PDF/omega_CNi16_communications.pdf
21+
class OmegaIseriesModbus(UsesUart, UsesSerial, HasPosition, IsDaemon):
22+
_kind = "omega-iseries-modbus"
23+
24+
def __init__(self, name, config, config_filepath):
25+
print(config)
26+
super().__init__(name, config, config_filepath)
27+
self.client = minimalmodbus.Instrument(
28+
port=self._config["serial_port"],
29+
slaveaddress=self._config["modbus_address"],
30+
debug=False,
31+
)
32+
self.client.serial.baudrate = self._config["baud_rate"]
33+
self.client.serial.parity = parity_options[self._config["parity"]]
34+
self.client.serial.bytesize = self._config["byte_size"]
35+
self.client.serial.stopbits = stop_bit_options[self._config["stop_bits"]]
36+
self.client.handle_local_echo = self._config["modbus_handle_echo"]
37+
38+
def direct_serial_write(self, bytes):
39+
client.serial.write(bytes)
40+
41+
def _set_position(self, position: float) -> None:
42+
out = int(position * 10)
43+
try:
44+
self.client.write_register(registeraddress=SV_REGISTER, value=out, functioncode=0x06)
45+
except minimalmodbus.NoResponseError:
46+
self._set_position(position=position)
47+
48+
async def update_state(self):
49+
while True:
50+
await asyncio.sleep(0.25)
51+
try:
52+
pv = self.client.read_register(PV_REGISTER) / 10.0
53+
sv = self.client.read_register(SV_REGISTER) / 10.0
54+
self._state["position"] = pv
55+
self._state["destination"] = sv
56+
except minimalmodbus.LocalEchoError:
57+
continue
58+
except minimalmodbus.InvalidResponseError:
59+
continue
60+
except minimalmodbus.NoResponseError:
61+
continue
62+
except minimalmodbus.SlaveReportedException:
63+
continue

0 commit comments

Comments
 (0)