
prim = projects.primary
plc = prim.find("Device", True)[0]
if plc <> None :
  print("Device found")
else:
  raise Exception ("Device not found")
   
devparams = plc.device_parameters
print ("Contains param 77: {}".format(devparams.contains(77)))
print ("Contains param 5: {}".format(devparams.contains(5)))

p77 = plc.device_parameters.by_id(77)
print ("Param 77: id={} name={} channel_type={} type_string={} iec_type={} param_type={} ".format(
            p77.id, p77.name, p77.channel_type, p77.type_string, p77.iec_type, p77.param_type))
            

# p77.value = "FALSE"          

pci = prim.find("PCI", True)[0]
p88 = pci.host_parameters.by_id(88)
# p88.value = "1234"
 
cif = prim.find("CIF50_PB", True)[0]
print ("Connectors: ")
for c in cif.connectors:
  print ("  - {} {} {} {} {}".format(c.connector_id, c.connector_role, c.interface_name, c.interface, c.module_type ))
  
dp = cif.connectors.by_id(2)
station_address = dp.host_parameters.by_id(327680)["fdlAdd"]
if station_address == None:
  raise Exception("Baudrate not found")
else:
  print ("Getting station address.")
v = station_address.value
station_address.value = "74"

wdtime = dp.host_parameters.by_id(589824)
print ("Watchdog time: " + wdtime.value)
wdtime.value = "222"
# baud.value = "2"
