Package: pydrs
PyDRS - Sirius Power Supplies communication.What is PyDRS?PyDRSis a Python package based on the Basic Small Messages ProtocolBSMP. It is used to communicate with and command Sirius Current Power Supplies and its peripherals of the Digital Regulation System (DRS).
The tailored protocol specification for the power supplies can be found hereDRS Communication Protocol.Communication is established through RS-485, USB or Ethernet interfaces of the UDC (Universal Digital Controller) cards. For USB and Ethernet, there should be only used Application Layer of the BSMP protocol (defined as bsmp message), and for those cases the transport layer address bytes and checksum, shall be omitted.In order to cover all DRS driven current power supplies whilst meeting models specificities, BSMP entities are standardized as follows: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.Specific variables: Each power supply model (chosen through thePS Modelparameter) 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.Basic Small Messages Protocol LibraryThe 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.This protocol manipulates 4 simple things, which are called Entities:VariablesGroupsCurvesFunctionsVariablescan be either writable or read-only and have a value of up to 128 bytes.AGroupcontains a bunch of Variables that can be read from or written to with only one command.ACurvecan be seen as a very large Variable, with up to 65536 blocks of 65520 bytes each.Finally, aFunctionis a very simple way to perform a Remote Procedure Call (RPC).Prerequisitespython==3.6at leastpyserial==3.5numpyDisclaimer:Although pydrs is tested up toPython 3.10.0, you may want to check whether other apps dependant on it support Python 3.10.
Also, these other apps might depend onvisualcppbuildtools.Dev Utility scriptsLinux shell script to clear cachesh./scripts/clean.shInstallation GuideUser level:User-level version must be installed from thePyPIrepository, using the 'pip install pydrs' command, which will install PyDRS onto the current Python path version.Optional: CondaConda is an open source package management system and environment management system that runs on Windows, macOS and Linux.It can be used to create a specific environment where PyDRS module can be installed.
Useminicondafor a free minimal installer for condaoranacondafor a full version for Conda.conda create --name pydrs python=3.6
conda activate pydrspip install -U pydrsDeveloper level:For a developer level firstly clone the project repository fromGitHubtoyour_local_foldervia git command:git clone https://github.com/lnls-sirius/pydrs.gitProceed to thepydrsfolder and then you can use pip command bytwo meansat yourchoice:1. Just copying the repository locally. (Local changes on the project won't take effect on current pydrs installation).Python module can be installed from the cloned source code. By using the 'pip install.' command at the root of the repository, the module will be installed normally, i.e. cloned files will be copied to the active python 'site-packages' folder.pip install .2. Copying the repository locally with the update feature. (Local changes will immediately take effect on pydrs current installation).The use of the '-e' flag in the local installation is recommended for situations where the code is under development and the changes are wanted to be used immediately. Installing it with the 'pip install -e.' command will link it to the repository folder, so package reinstallation won't be needed whenever a change in the active local repository occurs.pip install -e .Testspip install -e .[dev] -v
coverage run -m unittest discover
coverage xml
coverage reportUsageUpgradingdrs.set_slave_addanddrs.get_slave_addwere replaced by a property. Set the slave address withdrs.slave_addr = 5and get withaddress = drs.slave_addrdrs.set_timeoutanddrs.get_timeoutare also proprerties. Set withdrs.timeout = 5and get withtimeout = drs.timeoutdrs.closed_loopis nowdrs.close_loop(verb form) to indicate that is an action.drs.get_param_bankreturns a dictionary instead of a nested list. Printing behavior stays the same.drs.read_vars_xfunctions 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 runningdrs = pydrs.SerialDRS()and thendrs.connect(), you should rundrs = pydrs.SerialDRS("COM1", 3000000)for example.drs.read_vars_fac_nwas deprecated in favor of reading the vars you want through eitherread_vars_fac_acdcorread_vars_fac_dcdcto avoid confusion.drs.read_vars_xfunctions 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>>>importpydrs# Import the module>>>drs=pydrs.GenericDRS("10.0.6.64",5000)# Connect to a device. It will automatically detect whether this is a serial or TCP/IP connectionpyDRS-compatibleUDCfirmwareversion:0.442022-06-30>>>drs.slave_addr=5# Set slave address (optional)>>>drs.read_ps_status()# Run your command{'state':'Off','open_loop':0,'interface':0,'active':1,'model':'FBP','unlocked':0}