33 lines
879 B
Python
33 lines
879 B
Python
|
# Dict for all devices params
|
||
|
|
||
|
all_params = {'func': 0, 'status': 1, 'name': 2,
|
||
|
'id': 3, 'type_of_connection': 4, 'baud_rate': 5}
|
||
|
|
||
|
# Read device params from .dat device file
|
||
|
|
||
|
|
||
|
def read_device_params(name):
|
||
|
file = open('data/{}.dat'.format(name), 'r')
|
||
|
params = file.readline().split()
|
||
|
file.close()
|
||
|
return params
|
||
|
|
||
|
# Change device params in .dat device file
|
||
|
|
||
|
|
||
|
def write_device_params(name, param, value):
|
||
|
|
||
|
try:
|
||
|
file = open('data/{}.dat'.format(name), 'r+')
|
||
|
params = file.readline().split()
|
||
|
if value != '':
|
||
|
params[all_params[param]] = str(value)
|
||
|
else:
|
||
|
params[all_params[param]] = 'none'
|
||
|
file.seek(0)
|
||
|
file.truncate()
|
||
|
file.write(' '.join(params))
|
||
|
file.close()
|
||
|
|
||
|
except IndexError:
|
||
|
print('ErrorType = FileError: File.dat for this device does not exist')
|