How best to reference parameters.

David Poundall david at jotax.com
Tue Oct 25 23:13:16 CEST 2005


I am writing a scada package that has a significant amount of user
defined parameters stored in text files that I wish to cleanly access
in code.  By way of an example, a few lines from the configuration file
would typically be ...

[Plant Outputs]
Y0	P1	Pump 1 Pressure
Y1	P2	Pump 2 Fluid Transfer Pump
Y2	P3	Pump 3 Vac Pump
Y3	P4	Pump 4 Vac Pump
Y4	P5	Pump 5 / Pump 1B
Y5	P6	Pump 6 / Pump 2B
Y6	M
Y7	D
Y10	E
Y11	F

I can read these values in as dictionary items and refernce them in
code like this...

Y['P4'] = 1   # Which will ultimately switch my pump on
Y['P3'] = 0   # Which will ultimately switch my pump off

but I would much rather reference the plant outputs like this ...

Y.P4 = 1
Y.P3 = 0

basically it makes it easier for third parties to code, also my IDE
(wing) is able to use intellisense to determine exactly which Y outputs
have been loaded during code configuration.

Now I can achieve this by loading the configuration parameters in a
class like this...

class c_y:
    def __init__(self):
        self.P1 = 0
        self.P2 = 0
        self.P3 = 0
        self.P4 = 0

so I can do

Y = c_y()
Y.P4 = 1
Y.P3 = 0
etc

However, what I really would like is something like...

class c_y:
    def __init__(self):
        self.P1 = [0, 'OB1', 0 ]
        self.P2 = [0, 'OB1', 1 ]
        self.P3 = [0, 'OB1', 2 ]
        self.P4 = [0, 'OB1', 3 ]

Because that way I can also hold binary loadings and data register
(this is a PLC application) references which give me full information
for handling the pump bits.

However, this means that I have to access the pump status bits like
this...

Y.P4[0] = 1
Y.P3[0] = 0

Which takes me away from the clean code

Y.P4 = 1
Y.P3 = 0

That I would like to have.

Can anyone suggets a technique for parameter storage that may be able
to give me what I want here ?

Thanks in advance.

David




More information about the Python-list mailing list