Skip to content

Commit 2a075ba

Browse files
committed
v1.1.0 updates
-Added set_channel_connected() and set_all_connected() as public methods -set_open_circuit_fault[_all]() enable_disable default value = True (DISCONNECTED) -private check_transition() method added to driver for code organization -Updated Test Script to include new methods -Removed some commented out print debug statements -README, pyproject minor version increase
1 parent c86ae34 commit 2a075ba

File tree

5 files changed

+86
-68
lines changed

5 files changed

+86
-68
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bloomy Fault Insertion Unit Python Driver v1.0.0
1+
# Bloomy Fault Insertion Unit Python Driver v1.1.0
22
This package enables RS485 communication to the Bloomy Fault Insertion Unit through a PC's serial ports.
33

44
The Fault Insertion Unit (FIU) is designed to be used in conjunction with the BS1200 to generate open faults and short to ground faults. It also has switching that allows precisions current and voltage measurements to be taken using an external DMM.
@@ -15,12 +15,12 @@ Tested on Windows 10 build 19043 64-bit, using Python 3.10.5
1515
Tested on Ubuntu 18.04 WSL 1, using Python 3.7.4, 3.7.14
1616

1717
### Installation
18-
To begin installation the fiu driver package, open a command line terminal in the directory that the v1.0.0 wheel distribution release was saved.
18+
To begin installation the fiu driver package, open a command line terminal in the directory that the v1.1.0 wheel distribution release was saved.
1919
To install the package run the command:
2020

21-
Windows: ```pip install bloomy_fiu_driver-1.0.0-py3-none-any.whl```
21+
Windows: ```pip install bloomy_fiu_driver-1.1.0-py3-none-any.whl```
2222

23-
Linux: ```pip3 install bloomy_fiu_driver-1.0.0-py3-none-any.whl```
23+
Linux: ```pip3 install bloomy_fiu_driver-1.1.0-py3-none-any.whl```
2424

2525
If providing a full path to the .whl file, the terminal may be opened in any directory.
2626

@@ -76,8 +76,10 @@ The FIU driver class provides the following public methods to interact with the
7676
| connect | N/A | Instructs the driver's serial RS-485 interface to establish a connection<br>with the com resource |
7777
| disconnect | N/A | Sets all channels on all FIU modules to CONNECTED state before instructing <br>the RS-485 serial interface to close the connection with the FIU |
7878
| configure | shared_dmm (bool): value setting Shared DMM status | Set whether the system is using a shared DMM across multiple FIUs. |
79-
| set_open_circuit_fault | mod_id (int): FIU module ID<br>channel (int): Channel to set open circuit state for (1-24)<br>enable_disable (bool): True to enable (DISCONNECTED) or False to disable (CONNECT) | Enable (disconnect) or disable (connect) an open circuit fault at a specified channel. |
80-
| set_open_circuit_fault_all | mod_id (int): FIU module ID<br>enable_disable (bool): True to enable (DISCONNECTED) or False to disable (CONNECT) | Enable (disconnect) or disable (connect) open circuit faults at all channels in the system. |
79+
| set_open_circuit_fault | mod_id (int): FIU module ID<br>channel (int): Channel to set open circuit state for (1-24)<br>enable_disable (bool): True to enable (DISCONNECTED) or False to disable (CONNECT) | Enable (disconnect) or disable (connect) an open circuit fault at a specified. Defaults to DISCONNECT channel. |
80+
| set_open_circuit_fault_all | enable_disable (bool): True to enable (DISCONNECTED) or False to disable (CONNECT) | Enable (disconnect) or disable (connect) open circuit faults at all channels in the system. Defaults to DISCONNECT |
81+
| set_channel_connected | mod_id (int): FIU module ID<br>channel (int): Channel to connect for (1-24)| Connect the specified channel. |
82+
| connect_channels_all | N/A | Connects all channels in the system. |
8183
| set_short_circuit_fault | mod_id (int): FIU module ID<br>channel (int): Channel to set short circuit fault on (1-24) | Sets a fault to ground at the specified channel. (Only one channel in the system can be set to ground fault at a time.) |
8284
| set_voltage_measurement | mod_id (int): FIU Module ID<br>channel (int): Channel to set DMM voltage measurement on (1-24) | Sets the specified channel to voltage mode for DMM cell voltage measurement. (Only one channel in the system can be set to measurement mode at a time.) |
8385
| set_current_measurement | mod_id (int): FIU Module ID<br>channel (int): Channel to set DMM current measurement on (1-24) | Sets the specified channel to current mode for DMM bypass current measurement. (Only one channel in the system can be set to measurement mode at a time.) |

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bloomy_fiu_driver"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
authors = [{ name = "Mikhail Kharitonov", email = "[email protected]"}]
55
description= "Python driver package to communicate with the Bloomy Fault Insertion Unit over RS-485 Protocol"
66
readme = "README.md"

src/FIU/driver.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ def __init__(self, mod_ids: list, comm_resource: str) -> None:
1414
#make sure all Box IDs are in the range required for RS-485 for the Fault Insertion Unit
1515
for id in mod_ids:
1616
if id in range(0, 8):
17-
#print(id)
1817
self.module_IDs.append(id)
1918
else: raise IndexError(f"Invalid Module ID: {id}\nFIU Module IDs must be in range 0-7 for RS-485 communication")
2019
self.module_IDs.sort()
2120

2221
#Initialize the state manager and set all channels on all modules to be in disconnected state
23-
self._state_mgr = StateManager(self.module_IDs)
24-
self._state_mgr.set_all_state(self.module_IDs, FIUState.CONNECTED)
22+
self.__state_mgr = StateManager(self.module_IDs)
23+
self.__state_mgr.set_all_state(self.module_IDs, FIUState.CONNECTED)
2524

2625
#Initialize port resource name and create an object for the pyserial RS485 serial subclass
2726
self._sharedDMM = False
@@ -54,7 +53,7 @@ def configure(self, shared_dmm: bool) -> None:
5453
"""Set whether the system is using a shared DMM across multiple FIUs."""
5554
self._sharedDMM = shared_dmm
5655

57-
def set_open_circuit_fault(self, mod_id, channel, enable_disable: bool) -> None:
56+
def set_open_circuit_fault(self, mod_id: int, channel: int, enable_disable: bool = True) -> None:
5857
"""Enable (True = disconnect) or disable (False = connect) an open circuit fault at a specified channel."""
5958
if(self.__valid_module(mod_id) and self.__valid_channel(channel)):
6059
if enable_disable:
@@ -66,19 +65,19 @@ def set_open_circuit_fault(self, mod_id, channel, enable_disable: bool) -> None:
6665
cmd_char = "C"
6766
new_state = FIUState.CONNECTED
6867
#Check to see if the new open circuit state is a valid transition
69-
safe = self._state_mgr.check_shared_DMM_transition(new_state) if self._sharedDMM else self._state_mgr.check_transition(mod_id, channel, new_state)
70-
if(safe):
68+
if(self.__check_transition(new_state, mod_id, channel)):
7169
#construct the SCPI command to write to the FIU
7270
cmd = f"{cmd_char}{mod_id}{channel:02d}"
7371
self.interface.write_cmd(cmd)
7472
#update the channel's state in the state manager
75-
self._state_mgr.set_channel_state(mod_id, channel, new_state)
73+
self.__state_mgr.set_channel_state(mod_id, channel, new_state)
7674
else:
7775
raise FIUException(5010)
7876
else:
7977
raise FIUException(5051)
8078

81-
def set_open_circuit_fault_all(self, enable_disable: bool) -> None:
79+
80+
def set_open_circuit_fault_all(self, enable_disable: bool = True) -> None:
8281
"""Enable (True = disconnect) or disable (False = connect) open circuit faults at all channels in the system."""
8382
if enable_disable:
8483
#Disconnected state
@@ -90,28 +89,36 @@ def set_open_circuit_fault_all(self, enable_disable: bool) -> None:
9089
new_state = FIUState.CONNECTED
9190
#set open circuit state for all channels on all modules
9291
for box in self.module_IDs:
93-
write_buff = f"{cmd_char}{box}99"
94-
#print(write_buff)
95-
self.interface.write_cmd(write_buff)
92+
cmd = f"{cmd_char}{box}99"
93+
self.interface.write_cmd(cmd)
9694
#Update the state in StateManager
97-
self._state_mgr.set_all_state(self.module_IDs, new_state)
95+
self.__state_mgr.set_all_state(self.module_IDs, new_state)
96+
97+
def set_channel_connected(self, mod_id: int, channel: int) -> None:
98+
"""Dedicated method to set open circuit fault state of the provided channel to CONNECTED"""
99+
if(self.__valid_module(mod_id) and self.__valid_channel(channel)):
100+
cmd = f"C{mod_id}{channel:02d}"
101+
self.interface.write_cmd(cmd)
102+
self.__state_mgr.set_channel_state(mod_id, channel, FIUState.CONNECTED)
98103

104+
def connect_channels_all(self) -> None:
105+
"""Dedicated method to set all channels on every FIU on serial bus to CONNECTED state"""
106+
for box in self.module_IDs:
107+
cmd = f"C{box}99"
108+
self.interface.write_cmd(cmd)
109+
self.__state_mgr.set_all_state(self.module_IDs, FIUState.CONNECTED)
99110

100111
def set_short_circuit_fault(self, mod_id, channel):
101112
"""Sets a fault to ground at the specified channel.
102113
(Only one channel in the system can be set to ground fault at a time.)"""
103114
if(self.__valid_module(mod_id) and self.__valid_channel(channel)):
104115
#Check to see if the fault state at given channel is a valid transition
105-
if self._sharedDMM:
106-
safe = self._state_mgr.check_shared_DMM_transition(FIUState.FAULT_TO_GND)
107-
else:
108-
safe = self._state_mgr.check_transition(mod_id, channel, FIUState.FAULT_TO_GND)
109-
if(safe):
116+
if(self.__check_transition(FIUState.FAULT_TO_GND, mod_id, channel)):
110117
#construct the SCPI command to write to the FIU
111118
cmd = f"F{mod_id}{channel:02d}"
112119
self.interface.write_cmd(cmd)
113120
#update the channel's state in the state manager
114-
self._state_mgr.set_channel_state(mod_id, channel, FIUState.FAULT_TO_GND)
121+
self.__state_mgr.set_channel_state(mod_id, channel, FIUState.FAULT_TO_GND)
115122
else:
116123
raise FIUException(5010, channel, FIUState.FAULT_TO_GND.name)
117124
else:
@@ -122,16 +129,12 @@ def set_voltage_measurement(self, mod_id, channel):
122129
(Only one channel in the system can be set to measurement mode at a time.)"""
123130
if(self.__valid_module(mod_id) and self.__valid_channel(channel)):
124131
#Check to see if another channel is set to voltage measurement mode
125-
if self._sharedDMM:
126-
safe = self._state_mgr.check_shared_DMM_transition(FIUState.VOLT_MEASUREMENT)
127-
else:
128-
safe = self._state_mgr.check_transition(mod_id, channel, FIUState.VOLT_MEASUREMENT)
129-
if(safe):
132+
if(self.__check_transition(FIUState.VOLT_MEASUREMENT, mod_id, channel)):
130133
#construct the SCPI command to write to the FIU
131134
cmd = f"V{mod_id}{channel:02d}"
132135
self.interface.write_cmd(cmd)
133136
#update the channel's state in the state manager
134-
self._state_mgr.set_channel_state(mod_id, channel, FIUState.VOLT_MEASUREMENT)
137+
self.__state_mgr.set_channel_state(mod_id, channel, FIUState.VOLT_MEASUREMENT)
135138
else:
136139
raise FIUException(5010, channel, FIUState.VOLT_MEASUREMENT.name)
137140
else:
@@ -142,16 +145,12 @@ def set_current_measurement(self, mod_id, channel):
142145
(Only one channel in the system can be set to measurement mode at a time.)"""
143146
if(self.__valid_module(mod_id) and self.__valid_channel(channel)):
144147
#Check to see if another channel is set to current measurement
145-
if self._sharedDMM:
146-
safe = self._state_mgr.check_shared_DMM_transition(FIUState.CURR_MEASUREMENT)
147-
else:
148-
safe = self._state_mgr.check_transition(mod_id, channel, FIUState.CURR_MEASUREMENT)
149-
if(safe):
148+
if(self.__check_transition(FIUState.CURR_MEASUREMENT, mod_id, channel)):
150149
#construct the SCPI command to write to the FIU
151150
cmd = f"I{mod_id}{channel:02d}"
152151
self.interface.write_cmd(cmd)
153152
#update the channel's state in the state manager
154-
self._state_mgr.set_channel_state(mod_id, channel, FIUState.CURR_MEASUREMENT)
153+
self.__state_mgr.set_channel_state(mod_id, channel, FIUState.CURR_MEASUREMENT)
155154
else:
156155
raise FIUException(5010, channel, FIUState.CURR_MEASUREMENT.name)
157156
else:
@@ -219,3 +218,10 @@ def __valid_module(self, mod_id: int) -> bool:
219218
def __valid_channel(self, channel) -> bool:
220219
"""Ensures entered channel number is within valid range of 1-24"""
221220
return True if (channel in range (1, 25)) else False
221+
222+
def __check_transition(self, new_state, mod_id, channel) -> bool:
223+
"""Asks the state manager to check if it is safe to transition to the new state, given the configuration of the FIU Bus"""
224+
if self._sharedDMM:
225+
return self.__state_mgr.check_shared_DMM_transition(new_state)
226+
else:
227+
return self.__state_mgr.check_transition(mod_id, channel, new_state)

src/FIU/interfaces.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def write_cmd(self, msg: str) -> str:
6363

6464
def __check_return_msg(self, sent_cmd: str, readbuff: str) -> str:
6565
"""Parses the returned message buffer based on the return code"""
66-
#print(sent_cmd, readbuff)
6766
return_msg = readbuff[0]
6867
if return_msg == '0':
6968
#Success - No Data

0 commit comments

Comments
 (0)