473,765 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How best to reference parameters.

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

Oct 25 '05 #1
8 1550
It looks like I am going to have to bite the bullet and use properties.
The following should do what I want.

class test:

def __init__(self):
self.__HB = 0
self.__VPG = 0

def _get_HB(self): return (self.__HB, 'MF1', 0)
def _set_HB(self, x): self.__HB = x
HB = property(_get_H B, _set_HB)

def _get_VPG(self): return (self.__VPG, 'MF1', 1)
def _set_VPG(self, x): self.__HB = x
VPG = property(_get_V PG, _set_VPG)

Usisg this I can set / and clear HB and VPG usig the syntax

t = test()
t.HB = 1
t.VPG = 0

and when I read them I get a tuple which holds the currcnt value in
position 0 and the other parameters I need in positions 1 and 2.

Oct 25 '05 #2
In article <11************ **********@g43g 2000cwa.googleg roups.com>,
"David Poundall" <da***@jotax.co m> wrote:
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

...

d = {'a':1, 'b':2, 'c':3}

class foo:
def __init__(self, d):
self.__dict__.u pdate(d)

f = foo(d)

print f.a, f.b, f.c

(retyped from memory)
_______________ _______________ _______________ _______________ ____________
TonyN.:' *firstname*nlsn ews@georgea*las tname*.com
' <http://www.georgeanels on.com/>
Oct 26 '05 #3
Nice - I like that Tony. I had seen it around before but I didn't
catch on. Thanks for the clear example..

Oct 26 '05 #4

David Poundall wrote:
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


How about the following?
(not tested)

class Pump(object):
def __init__(self, name, ptype, number):
self.status = 0
self.name = name
self.ptype = ptype
self.number = number

class C_Y(object):
def __init__(self, *plist):
index = []
for p in plist:
self.__dict__[p[0]] = Pump(*p)
index.append(p[0])
self.index = index
def showall(self):
out = []
for item in self.index:
out.append( "%s: %r\n"
% (item, self.__dict__[item] )

Then with a list formed as ....

pumplist = [ ('p1', 'ob1', 0),
('p2', 'ob1', 1),
('p3', 'ob1', 2),
...
]

You can then do...

c_y = C_Y(pumplist)

print c_y.p1.name --> 'p1'
print c_y.p1.status --> 0
print c_y.p1.ptype --> 'ob1'
print c_y.p1.number --> 0
c_y.p1.status = 1 # p1 on
c_y.p1.status = 0 # p1 off

print c_y.p2.status --> 0
print c_y.p2.ptype --> 'ob1'
print c_y.p2.number --> 1

etc...

print c_y.showall()
Cheers,
Ron



Oct 26 '05 #5
Sadly Ron, c_y can only see index and showall in your example.

Oct 26 '05 #6


David Poundall wrote:
Sadly Ron, c_y can only see index and showall in your example.


Well, don't give up! The approach is sound and I did say it was
untested. Here's a tested version with a few corrections. :-)

Cheers,
Ron


class Pump(object):
def __init__(self, name, ptype, number):
self.status = 0
self.name = name
self.ptype = ptype
self.number = number

class C_Y(object):
def __init__(self, plist):
index = []
for p in plist:
self.__dict__[p[0]] = Pump(*p)
index.append(p[0])
self.index = index
def showall(self):
out = []
for item in self.index:
out.append( "%s: %r, %r, %r\n"
% ( self.__dict__[item].name,
self.__dict__[item].status,
self.__dict__[item].ptype,
self.__dict__[item].number ) )
return ''.join(out)
pumplist = [ ('p1', 'ob1', 0),
('p2', 'ob1', 1),
('p3', 'ob1', 2) ]

c_y = C_Y(pumplist)

print c_y.p1.name
print c_y.p1.status
print c_y.p1.ptype
print c_y.p1.number
print

c_y.p1.status = 1
print c_y.p1.status
print

print c_y.showall()

Oct 26 '05 #8
Sorry Ron, my earlier reply was too brief I wasn't thinking straight
(so what else is new ;-) my apologies. The main reason for going down
the route I am looking at (thread 2) is that intellisense runs OK in my
IDE using that aproach.

In my application this will be important as I will be using the IDE
(Wing) as a high level user editor in a limited code area. The user
will need to see (hence the use of intellisense) which properties are
available for him to work with.

The second example you gave runs similar to the first, and
unfortunately the intellisense does not pick up available properties as
you go walk the dots. Not suprisingly really as the class is dynamic
in the way it operates. It only see's the index property and the
showall function.

The code as you wrote it works fine though, and it is already salted
away in my meager (but growing) codebank.

Many thanks for your reply.

Oct 26 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
2247
by: pmatos | last post by:
Hi all, Sometimes I have a function which creates an object and returns it. Some are sets, other vectors but that's not very important. In these cases I do something like this: vector<int> * f() { vector<int> * v = new vector<int>; return v; }
3
2196
by: David Altemir | last post by:
I have a table in MS Access 2003 that contains records that I would like to copy to the end of the table. There is one slight deviation from just doing a straightforwared COPY, however, in that I want to append the new records using different value of column 1. Here's an example of what I'm talking about: Values in in Table1 before "copy" operation: Bill, 3200 Palm Blvd
39
7663
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
5
1553
by: Javier Campos | last post by:
WARNING: This is an HTML post, for the sake of readability, if your client can see HTML posts, do it, it doesn't contain any script or virus :-) I can reformat a non-HTML post if you want me to (and if this doesn't see correctly with non-HTML viewers) Ok, I'm fed up with this so I'll explain the situation here and my approach (which sucks), and see if anyone can give a better solution to this. I'm making a way to have several parameters...
5
445
by: Greg | last post by:
Hi, I have been unable to resolve this error message: Object Ref not set to an instance of an object. The issue is that I cannot determine which object reference is causing the problem. The line of user code that gives the error message is:
0
2115
by: webbsk | last post by:
I keep getting an exception when I call the DataAdapter Update method. I have been trying to figure out what is causing the null reference exception for this code for what seems like forever: private void DoInserts(OdbcDataAdapter odbcDataAdapter, string tableName) { DataTable dataTableChanged = dsTapes.Tables.GetChanges(DataRowState.Added);
13
3030
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody bother in C# with pass-by-reference using the "ref" keyword or "out" for objects in a method parameter list, when, after all, it appears in C# that for all intents and purposes a reference is always being passed, rather than the real object (with, it...
9
1616
by: alexandis | last post by:
I have a big database, a lot of tables, so I will have a lot of pages where i create a new record. There will be a lot of 'reference' items - let's say 'Create user' -> 'Select user type' <Dropdownlist-Admin, Partner, Client type A, Client type B, Contract (is taken from UserTypes table) Such 'reference' lists (based on 'reference' tables) should be used on several pages, I will have a lot of reference tables. So - what is the best...
275
12379
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.