[Tutor] Hello! Questions

Alan Gauld alan.gauld at btinternet.com
Thu Feb 18 20:16:42 EST 2016


On 18/02/16 21:17, Marco Soldavini wrote:

> *# While loop - scanning and storing OPC values at scan rate 

**while *(abort == 0):
> 
> 
> *# ESC pressed?     **if *msvcrt.kbhit() *and *ord(msvcrt.getch()) == 27:
>         abort = 1
> 
> 

As you can see your code is all messed up.
You need to post in plain text format.

> Let's say I can have 30-40 variables (so 30-40 append instructions at every
> cycle, with same scan rate).

Its not clear what the scan rate actually is.
How many scans per second?

> Is this scalable when variables are getting bigger. 

The variables stay the same size it's the data that
gets bigger. But how scalable it is depends on how
much memory you have. And how fast your storage
devices are. And what else is running on your
system at the time.

> shall run for 2 hours and gather let's say 2000 elements in 40 arrays,
> could this be a problem in term of computation?

Yes it could, but it depends on what size the data is.
You need to do some basic math to calculate it out.

40 * 2000 = 80k items. If they are integers then its
4 bytes per item so 320Kbytes. Not too bad. If they
are 100 character strings then its into MB but on a
modern PC still not too bad. But if it's intended to
run in an embedded controller with only 1M of RAM
it might be a big issue.

> Second question is I want the arguments in the opc.read command not to be
> hard coded but coming from a configuration files.

OK. You might want to think about what that file
format would look like.

> You see the names of my arrays? bool1, ana1, ana2, etc... Is it possible to
> derive number and names of these variables from an external files.

It is but its usually a bad idea.
Better is to use a dictionary with your "variables"
as keys and your arrays as values. So your append
looks like

data = dict()
keyName = readFromFile()
value = readFromFile()

data[keyName].append(value)

> Let's say in this configuration file I can say I have to read 10 arrays or
> 20 arrays and then my program adjust the while cycle consequently.

Yes that's doable.

> Maybe an array of array where the second dimension is coming from the
> config file.

I'd use the dictionary approach rather than arrays of arrays.
(Which are probably lists of lists in Python.)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list