@@ -42,7 +42,8 @@ def apply_config_file(self, cfg_file_path, restart: bool = True):
4242 {
4343 "Box_ID" : 1,
4444 "Write_Period_ms" : 5
45- }
45+ },
46+ "Enable_SafetyInterlock" : true
4647 }
4748 """
4849 with open (cfg_file_path ) as json_file :
@@ -55,14 +56,15 @@ def apply_config_file(self, cfg_file_path, restart: bool = True):
5556 config ["Ethernet_Settings" ]['TCP_Cmd_Interval_ms' ],
5657 config ["Ethernet_Settings" ]['UDP_Read_Port' ],
5758 config ["Ethernet_Settings" ]['UDP_Read_Interval_ms' ])
59+ en_interlock = config ["Enable_SafteyInterlock" ]
5860 #print(mode)
5961 #print(can_cfg)
6062 #print(eth_cfg)
6163
6264 self .apply_general_settings (mode , False )
6365 self .apply_can_config (can_cfg , False )
6466 self .apply_ethernet_settings (eth_cfg , False )
65-
67+ self . enable_safety_interlock ( en_interlock , False )
6668 if restart :
6769 self .__restart_unit ()
6870
@@ -75,6 +77,7 @@ def get_all_settings(self, export_to_file: bool,
7577 ethernet = self .get_ethernet_settings ()
7678 can = self .get_can_settings ()
7779 mode = self .get_protocol ()
80+ interlock = self .interlock_enabled ()
7881 config = {'Protocol' : mode , 'IP_Address' : ethernet .IP_Address ,
7982 'Ethernet_Settings' :{
8083 'TCP_Cmd_Port' : ethernet .Command_Port ,
@@ -86,7 +89,8 @@ def get_all_settings(self, export_to_file: bool,
8689 {
8790 'Box_ID' : can .box_id ,
8891 'Write_Period_ms' : int (can .publish_period_us / 1000 )
89- }
92+ },
93+ 'Enable_SafetyInterlock' : interlock
9094 }
9195 if export_to_file :
9296 with open (file_name , 'w' ) as f :
@@ -165,12 +169,37 @@ def apply_can_config(self, can_cfg: CAN_Settings, restart: bool = True):
165169 if restart :
166170 self .__restart_unit ()
167171
172+ def enable_safety_interlock (self , interlock , restart : bool = True ):
173+ """
174+ Enables or disables the BS1200 Safety Interlock feature
175+ """
176+ rt_path = "/ni-rt/startup/Data/BS1200 Configuration.ini"
177+ temp_path = "BS1200 Configuration.ini"
178+ cfgfile_path = self .FTP .getFile (rt_path , temp_path )
179+ self .__fix_XML_tags (cfgfile_path )
180+ #build an XML tree for the .ini file 🤦♂️
181+ tree = ET .parse (cfgfile_path )
182+ root = tree .getroot ()
183+ #Replace Enable_Cell_Inhibit
184+ root [3 ].text = "TRUE" if interlock else "FALSE"
185+ #Rewrite the temp config file
186+ tree .write (cfgfile_path , encoding = "utf-8" , xml_declaration = True , short_empty_elements = False )
187+ #replace the configuration file on the target
188+ self .__replace_xml_declaration (cfgfile_path )
189+ self .FTP .uploadFile (cfgfile_path , rt_path )
190+ os .remove (temp_path )
191+ #restart unit by default
192+ if restart :
193+ self .__restart_unit ()
168194
169195 def set_ip_address (self , new_ip_address : str ):
170196 """
171197 Sets a new IP Address for the target BS1200, restarting the unit and updating
172198 the ip address used by the ConfigTools for further configuration method calls
173199 """
200+ #no broadcast bytes allowed
201+ if ("255" in new_ip_address ):
202+ raise ValueError ("Broadcast bytes are not allowed for the unit IP address" )
174203 #get the ni-rt.ini file from the BS1200 controller root directory
175204 self .FTP .getFile ('ni-rt.ini' , 'ni-rt.ini' )
176205 #open the local copy of the cfg file and set the IP Address parameter of the
@@ -247,7 +276,7 @@ def set_udp_settings(self, rep_port: int, rep_interval_ms: int):
247276 self .FTP .uploadFile (cfgfile_path , rt_path )
248277 os .remove (temp_path )
249278
250- def get_can_settings (self ) -> CAN_Settings :
279+ def get_can_settings (self ):
251280 """
252281 Retreive the can settings from the target BS1200
253282 """
@@ -261,7 +290,7 @@ def get_can_settings(self) -> CAN_Settings:
261290 os .remove (temp_path )
262291 return CAN_Settings (int (root [0 ][3 ].text ), int (root [0 ][4 ].text ))
263292
264- def get_ethernet_settings (self ) -> Ethernet_Settings :
293+ def get_ethernet_settings (self ):
265294 """
266295 Retreive the ethernet settings and IP address from the target device
267296 """
@@ -306,8 +335,23 @@ def get_ethernet_settings(self) -> Ethernet_Settings:
306335 os .remove (temp_path2 )
307336 os .remove ('ni-rt.ini' )
308337 return Ethernet_Settings (ip , tcp_port , tcp_interval , udp_port , udp_interval )
338+
339+ def interlock_enabled (self ):
340+ """
341+ Retreive the state of the Safety Interlock from the target BS1200
342+ """
343+ rt_path = "/ni-rt/startup/Data/BS1200 Configuration.ini"
344+ temp_path = "BS1200 Configuration.ini"
345+ cfgfile_path = self .FTP .getFile (rt_path , temp_path )
346+ self .__fix_XML_tags (cfgfile_path )
347+ #build an XML tree for the .ini file 🤦♂️
348+ tree = ET .parse (cfgfile_path )
349+ root = tree .getroot ()
350+ os .remove (temp_path )
351+ return True if root [3 ].text == "TRUE" else False
352+
309353
310- def get_protocol (self ) -> str :
354+ def get_protocol (self ):
311355 """
312356 Get the procotol form the general settings
313357 """
@@ -333,7 +377,7 @@ def __restart_unit(self):
333377 with nisyscfg .Session (self .ip_address , self .user , self .pwd ) as s :
334378 #updates IP address for the ConfigTools instance to the new IP address once restart complete
335379 ev = self .__start_anim (f"Restarting BS1200 ({ self .ip_address } )... " )
336- self .ip_address = self . ip_address = s .restart ()
380+ self .ip_address = s .restart ()
337381 ev .set ()
338382 #do this again just in case
339383 self .FTP .tgt_address = self .ip_address
0 commit comments