From c7b326a379f023610361c72fb4760071b68fee41 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Nov 2023 15:33:17 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/agents/hi6200.rst | 6 +++--- socs/agents/hi6200/agent.py | 17 ++++++++--------- socs/agents/hi6200/drivers.py | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/docs/agents/hi6200.rst b/docs/agents/hi6200.rst index 341fc8906..8ea308973 100644 --- a/docs/agents/hi6200.rst +++ b/docs/agents/hi6200.rst @@ -8,7 +8,7 @@ Hi6200 Agent This agent uses Modbus TCP to communicate with the Hi6200 Weight Sensor. This agent uses ModbusClient from pyModbusTCP to facilitate the communication. -The agent is able to communicate over ethernet to read and monitor the net and +The agent is able to communicate over ethernet to read and monitor the net and gross weights of the scale. .. argparse:: @@ -75,6 +75,6 @@ Below is an example client demonstrating full agent functionality.:: # Begin Monitoring Weight scale.monitor_weight.start() - + #Stop Monitoring Weight - scale.stop_monitoring.start() \ No newline at end of file + scale.stop_monitoring.start() diff --git a/socs/agents/hi6200/agent.py b/socs/agents/hi6200/agent.py index a120e7df1..1dc86dd08 100644 --- a/socs/agents/hi6200/agent.py +++ b/socs/agents/hi6200/agent.py @@ -2,8 +2,7 @@ import time from ocs import ocs_agent, site_config -from ocs.ocs_twisted import TimeoutLock -from ocs.ocs_twisted import Pacemaker +from ocs.ocs_twisted import Pacemaker, TimeoutLock from socs.agents.hi6200.drivers import Hi6200Interface @@ -12,15 +11,15 @@ class Hi6200Agent: """ Agent to connect to the Hi6200 weight controller that measures the weight of the LN2 dewar on the SAT platform. - + Parameters: ip_address (string): IP address set on the Hi6200 tcp_port (int): Modbus TCP port of the Hi6200. Default Default set on the device is 502. - scale (Hi6200Interface): A driver object that allows + scale (Hi6200Interface): A driver object that allows for communication with the scale. """ - + def __init__(self, agent, ip_address, tcp_port): self.agent = agent self.log = agent.log @@ -29,7 +28,7 @@ def __init__(self, agent, ip_address, tcp_port): self.ip_address = ip_address self.tcp_port = tcp_port self.scale = None - + self.monitor = False # Registers Scale Output @@ -71,10 +70,10 @@ def monitor_weight(self, session, params=None): """ session.set_status('running') self.monitor = True - + pm = Pacemaker(1, quantize=True) while self.monitor: - + pm.sleep() with self.lock.acquire_timeout(1) as acquired: if acquired: @@ -92,7 +91,7 @@ def monitor_weight(self, session, params=None): except ValueError as e: self.log.error(f"Scale responded with an anomolous number, ignorning: {e}") - + except TypeError as e: self.log.error(f"Scale responded with 'None' and broke the hex decoding, trying again: {e}") diff --git a/socs/agents/hi6200/drivers.py b/socs/agents/hi6200/drivers.py index cec996f59..90fef895f 100644 --- a/socs/agents/hi6200/drivers.py +++ b/socs/agents/hi6200/drivers.py @@ -14,10 +14,10 @@ def __init__(self, ip_address, tcp_port, verbose=False, **kwargs): """ Connects to the Hi6200 weight sensor using a TCP ModbusClient with pyModbusTCP. The Modbus Client uses a socket connection to facillitate Modbus communications. - ModbusClient requires an IP address and port to connect. - + ModbusClient requires an IP address and port to connect. + ModbusClient will not throw errors upon incorrect ip_address! - + ModbusClient auto-reconnects upon socket failure if auto_open is True. """ @@ -26,22 +26,22 @@ def __init__(self, ip_address, tcp_port, verbose=False, **kwargs): def decode_scale_weight_registers(register_a, register_b): """ Decodes the scales weight registers and returns a single weight value (float). - + The scale holds both the net and gross weights in permanent holding registers. Each weight is held across 2 registers in 4 hex bits (2 hex bits/4 bits per register, 8 bits total). The hex bits must be concatenated and converted to a float. """ - #Strip the '0x' hex bit - #We must have 8 total bits to convert, so we zfill until each register value is 4 bits + # Strip the '0x' hex bit + # We must have 8 total bits to convert, so we zfill until each register value is 4 bits hex_a = hex(register_b)[2:].zfill(4) hex_b = hex(register_b)[2:].zfill(4) - - #Concatenate the hex bits in cdab order. + + # Concatenate the hex bits in cdab order. hex_weight = hex_b + hex_a # This struct function converts the concatenated hex bits to a float. return struct.unpack('!f', bytes.fromhex(hex_weight))[0] - + def read_scale_gross_weight(self): """ Returns the current gross weight reading of the scale in the sensors chosen unit (kg) @@ -62,4 +62,4 @@ def read_scale_net_weight(self): # Reading these registers will return an int. a, b = self.scale.read_holding_registers(6, 2) - return decode_scale_weight_registers(a, b) \ No newline at end of file + return decode_scale_weight_registers(a, b)