diff --git a/README.md b/README.md index 6fac61b..c1004f4 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,6 @@ In order to cover all DRS driven current power supplies whilst meeting models sp 1. **Common variables**: Variables used by all power supplies models, for example, general status and operating mode parameters. These variables occupy the first 25 BSMP variable Id's. 2. **Specific variables**: Each power supply model (chosen through the *PS Model* parameter) defines ID variables greater than 24 according to its application. Thus, when communicating with a power supply, its model should prior be known in order to correctly use the specifications of those BSMP variables. This includes measures of feedback and monitoring and also interlocks records. - -Development packages are listed at [requirements-dev.txt](requirements_dev.txt) and runtime dependencies at [requirements.txt](requirements.txt). - ## Basic Small Messages Protocol Library The BSMP - Basic Small Messages Protocol - is a stateless, synchronous and lightweight protocol. It was designed to be used in serial communication networks of small embedded devices which contain a device with the role of a master. @@ -61,7 +58,7 @@ sh ./scripts/clean.sh ### **User level:** User-level version must be installed from the [**PyPI**](https://pypi.org/project/pydrs/) repository, using the 'pip install pydrs' command, which will install PyDRS onto the current Python path version. -### **Optional: - Conda** +### **Optional: Conda** Conda is an open source package management system and environment management system that runs on Windows, macOS and Linux. @@ -119,9 +116,7 @@ pip install -e . ### Tests ```command -pip install -r requirements.txt -pip install -r requirements_dev.txt -pip install -e . -v +pip install -e .[dev] -v coverage run -m unittest discover coverage xml coverage report @@ -132,17 +127,18 @@ coverage report ### Upgrading -Although old method names and operations are still supported and work as expected, a few changes were implemented to make life easier, with new preferrable ways to do things, such as: - - `drs.set_slave_add` and `drs.get_slave_add` were replaced by a property. Set the slave address with `drs.slave_addr = 5` and get with `address = drs.slave_addr` - `drs.set_timeout` and `drs.get_timeout` are also proprerties. Set with `drs.timeout = 5` and get with `timeout = drs.timeout` - `drs.closed_loop` is now `drs.close_loop` (verb form) to indicate that is an action. - `drs.get_param_bank` returns a dictionary instead of a nested list. Printing behavior stays the same. -- `drs.read_vars_x` functions return a dictionary, as well as printing the values. Somewhere in the future, implicit looping (n=10000 loops 10000 times for example) will be removed. +- `drs.read_vars_x` functions return a dictionary. - All commands run through validation. In case validation fails, a descriptive exception will be raised, which can be used to trace the problem. - Connecting to a given device is done during instantiation of the class. This means that instead of running `drs = pydrs.SerialDRS()` and then `drs.connect()`, you should run `drs = pydrs.SerialDRS("COM1", 3000000)` for example. +- `drs.read_vars_fac_n` was deprecated in favor of reading the vars you want through either `read_vars_fac_acdc` or `read_vars_fac_dcdc` to avoid confusion. +- `drs.read_vars_x` functions no longer implicitly loop or print, in favor of higher throughput and less confusion when scripting. +- Variables are read using variable groups, improving performance massively (93% reduction in read time). This means that if you attempt to read variables for a power supply type that doesn't correspond to the current power supply's type, it will most likely raise a "size mismatch" (`SerialInvalidPckgLen`) exception. -### Basic utilization (post 1.2.0) +### Basic utilization ```python >>> import pydrs # Import the module @@ -154,36 +150,3 @@ Although old method names and operations are still supported and work as expecte >>> drs.read_ps_status() # Run your command {'state': 'Off', 'open_loop': 0, 'interface': 0, 'active': 1, 'model': 'FBP', 'unlocked': 0} ``` - -### Basic usage (pre 1.2.0) - -When all installation is done, python or ipython instance can be called. - -![14](https://user-images.githubusercontent.com/19196344/138935751-d90dc9b9-1409-4dc4-98bd-66f480dcd489.png) - - -Import pydrs - -![image](https://user-images.githubusercontent.com/19196344/139112617-2629340e-fac9-4002-8456-1e3b079cd837.png) - - -Create *drs* object. - -![image](https://user-images.githubusercontent.com/19196344/139116187-fc58c909-9b4f-46fe-91ca-d80796f3256d.png) - - -Establish the connection. - -![image](https://user-images.githubusercontent.com/19196344/139116355-790b9f0e-8536-4203-9276-b3e592329661.png) - - -Set the device address to communicate. - -![image](https://user-images.githubusercontent.com/19196344/139116450-1b083db1-b257-40ca-868c-350b9af193e4.png) - - -Use BSMP commands to control the device. - -![image](https://user-images.githubusercontent.com/19196344/139116593-7fcbd965-85e4-460e-a912-91782a21d412.png) - - diff --git a/src/pydrs/base.py b/src/pydrs/base.py index 0ed9a19..52226ea 100644 --- a/src/pydrs/base.py +++ b/src/pydrs/base.py @@ -2042,20 +2042,8 @@ def save_ramp_waveform_col(self, ramp): for val in ramp: writer.writerow([val]) - def read_vars_fac_n(self, n=1, dt=0.5): - vars_dict = {} - old_add = self.slave_addr - try: - print("\n-----------------------\n") - self.slave_addr = 1 - vars_dict["dcdc"] = self.read_vars_fac_dcdc() - print("\n-----------------------\n") - self.slave_addr = 2 - vars_dict["acdc"] = self.read_vars_fac_acdc() - - return vars_dict - finally: - self.slave_addr = old_add + def read_vars_fac_n(self): + raise NotImplementedError def set_buf_samples_freq(self, fs): self.set_param("Freq_TimeSlicer", 1, fs) diff --git a/src/pydrs/consts/fac.py b/src/pydrs/consts/fac.py index 788778d..e0816bc 100644 --- a/src/pydrs/consts/fac.py +++ b/src/pydrs/consts/fac.py @@ -382,8 +382,6 @@ } bsmp_2s_acdc = { - "ps_soft_interlocks": {"addr": 31, "format": "I", "size": 4, "egu": ""}, - "ps_hard_interlocks": {"addr": 32, "format": "I", "size": 4, "egu": ""}, "v_capacitor_bank": {"addr": 33, "format": "f", "size": 4, "egu": "V"}, "i_out_rectifier": {"addr": 34, "format": "f", "size": 4, "egu": "A"}, "duty_cycle": {"addr": 35, "format": "f", "size": 4, "egu": "p.u."}, @@ -452,8 +450,6 @@ } bsmp_2p_acdc_imas = { - "ps_soft_interlocks": {"addr": 31, "format": "I", "size": 4, "egu": ""}, - "ps_hard_interlocks": {"addr": 32, "format": "I", "size": 4, "egu": ""}, "v_capacitor_bank": {"addr": 33, "format": "f", "size": 4, "egu": "V"}, "i_out_rectifier": {"addr": 34, "format": "f", "size": 4, "egu": "A"}, "duty_cycle": {"addr": 35, "format": "f", "size": 4, "egu": "p.u."}, diff --git a/src/pydrs/pydrs.py b/src/pydrs/pydrs.py index 3f1bcdf..08ad15d 100644 --- a/src/pydrs/pydrs.py +++ b/src/pydrs/pydrs.py @@ -17,16 +17,11 @@ class SerialDRS(BaseDRS): """DRS communication through serial ports""" - def __init__(self, port: str = None, baud: int = 115200): + def __init__(self, port: str, baud: int = 115200): super().__init__() self.ser: typing.Optional[serial.Serial] = None - if port is None: - print( - "From 2.0.0 onwards, creating the object then using 'connect' to connect will be deprecated. Please use 'SerialDRS(port, baud)' instead." - ) - else: - self.connect(port, baud) + self.connect(port, baud) def _transfer_write(self, msg: str): full_msg = (self._slave_addr + msg).encode("ISO-8859-1") @@ -83,15 +78,10 @@ def disconnect(self): class EthDRS(BaseDRS): """DRS communication through TCP/IP""" - def __init__(self, address: str = None, port: int = 5000): + def __init__(self, address: str, port: int = 5000): super().__init__() self._serial_timeout = 50 - if address is None: - print( - "From 2.0.0 onwards, creating the object then using 'connect' to connect will be deprecated. Please use 'EthDRS(address, port)' instead." - ) - else: - self.connect(address, port) + self.connect(address, port) def _format_message(self, msg: bytes, msg_type: bytes) -> bytes: msg = msg_type + struct.Struct(">f").pack(self._serial_timeout) + msg