[Tutor] Hello! Questions

Marco Soldavini magyar1886 at gmail.com
Thu Feb 18 16:17:58 EST 2016

On Wed, Feb 17, 2016 at 11:13 AM, Alan Gauld <alan.gauld at btinternet.com>

> > My first question is about data types, data structures in general and how
> > to organize an efficient loop for recording data.
> > while (stop condition false)
> >    read data
> >    write data into local array or something
> >    wait sample time
> That's a good start. What is the question?
> You say you know how to read data fro openopc, so the
> first loop line should be fine.
> Storing into a list involves the append method:
> myDataList.append(myData)
> and the wait will probably be openopc specific
> but if not you can use the time.sleep() function.
> hth
> --
> Alan G

Ok here my main loop for gathering data (stripped off some code to make it
easier to read):

*# 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

*break     *
*# Server up     **if *opc.ping():

        *if *opc[*'.run_batch'*] == True *and *rec_started == False:

*# Setting arrays for variables             *bool1 = []
            ana1 = []
            ana2 = []
            ana3 = []
            ana4 = []
            rec_started = True

        *if *opc[*'.run_batch'*] == True *and *rec_started == True:

*# scan time             *time2 = time.time()
            dtime = time2 - time1

            *if *dtime > 2 *and *comm_alarm == False:
                dt = datetime.datetime.now()
                time1 = time2


*# scan time         *time2 = time.time()
        dtime = time2 - time1
        *if *dtime > 2:
            *print **"ERROR: OPC Server is down"*

As you can see I am using append to store data from opc.read command which
returns elements of string array.

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

Is this scalable when variables are getting bigger. What if this program
shall run for 2 hours and gather let's say 2000 elements in 40 arrays,
could this be a problem in term of computation?

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

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.

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.

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

Is this clear?

Version of python is 2.7.9 running on Windows 7.



More information about the Tutor mailing list