@@ -42,7 +42,8 @@ def apply_config_file(self, cfg_file_path, restart: bool = True):
42
42
{
43
43
"Box_ID" : 1,
44
44
"Write_Period_ms" : 5
45
- }
45
+ },
46
+ "Enable_SafetyInterlock" : true
46
47
}
47
48
"""
48
49
with open (cfg_file_path ) as json_file :
@@ -55,14 +56,15 @@ def apply_config_file(self, cfg_file_path, restart: bool = True):
55
56
config ["Ethernet_Settings" ]['TCP_Cmd_Interval_ms' ],
56
57
config ["Ethernet_Settings" ]['UDP_Read_Port' ],
57
58
config ["Ethernet_Settings" ]['UDP_Read_Interval_ms' ])
59
+ en_interlock = config ["Enable_SafteyInterlock" ]
58
60
#print(mode)
59
61
#print(can_cfg)
60
62
#print(eth_cfg)
61
63
62
64
self .apply_general_settings (mode , False )
63
65
self .apply_can_config (can_cfg , False )
64
66
self .apply_ethernet_settings (eth_cfg , False )
65
-
67
+ self . enable_safety_interlock ( en_interlock , False )
66
68
if restart :
67
69
self .__restart_unit ()
68
70
@@ -75,6 +77,7 @@ def get_all_settings(self, export_to_file: bool,
75
77
ethernet = self .get_ethernet_settings ()
76
78
can = self .get_can_settings ()
77
79
mode = self .get_protocol ()
80
+ interlock = self .interlock_enabled ()
78
81
config = {'Protocol' : mode , 'IP_Address' : ethernet .IP_Address ,
79
82
'Ethernet_Settings' :{
80
83
'TCP_Cmd_Port' : ethernet .Command_Port ,
@@ -86,7 +89,8 @@ def get_all_settings(self, export_to_file: bool,
86
89
{
87
90
'Box_ID' : can .box_id ,
88
91
'Write_Period_ms' : int (can .publish_period_us / 1000 )
89
- }
92
+ },
93
+ 'Enable_SafetyInterlock' : interlock
90
94
}
91
95
if export_to_file :
92
96
with open (file_name , 'w' ) as f :
@@ -165,12 +169,37 @@ def apply_can_config(self, can_cfg: CAN_Settings, restart: bool = True):
165
169
if restart :
166
170
self .__restart_unit ()
167
171
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 ()
168
194
169
195
def set_ip_address (self , new_ip_address : str ):
170
196
"""
171
197
Sets a new IP Address for the target BS1200, restarting the unit and updating
172
198
the ip address used by the ConfigTools for further configuration method calls
173
199
"""
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" )
174
203
#get the ni-rt.ini file from the BS1200 controller root directory
175
204
self .FTP .getFile ('ni-rt.ini' , 'ni-rt.ini' )
176
205
#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):
247
276
self .FTP .uploadFile (cfgfile_path , rt_path )
248
277
os .remove (temp_path )
249
278
250
- def get_can_settings (self ) -> CAN_Settings :
279
+ def get_can_settings (self ):
251
280
"""
252
281
Retreive the can settings from the target BS1200
253
282
"""
@@ -261,7 +290,7 @@ def get_can_settings(self) -> CAN_Settings:
261
290
os .remove (temp_path )
262
291
return CAN_Settings (int (root [0 ][3 ].text ), int (root [0 ][4 ].text ))
263
292
264
- def get_ethernet_settings (self ) -> Ethernet_Settings :
293
+ def get_ethernet_settings (self ):
265
294
"""
266
295
Retreive the ethernet settings and IP address from the target device
267
296
"""
@@ -306,8 +335,23 @@ def get_ethernet_settings(self) -> Ethernet_Settings:
306
335
os .remove (temp_path2 )
307
336
os .remove ('ni-rt.ini' )
308
337
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
+
309
353
310
- def get_protocol (self ) -> str :
354
+ def get_protocol (self ):
311
355
"""
312
356
Get the procotol form the general settings
313
357
"""
@@ -333,7 +377,7 @@ def __restart_unit(self):
333
377
with nisyscfg .Session (self .ip_address , self .user , self .pwd ) as s :
334
378
#updates IP address for the ConfigTools instance to the new IP address once restart complete
335
379
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 ()
337
381
ev .set ()
338
382
#do this again just in case
339
383
self .FTP .tgt_address = self .ip_address
0 commit comments