Discussion:
[Tutor] Connecting with running module and capturing the data
Patrycja Niewosz
2015-07-20 07:26:47 UTC
Permalink
Hi All,

I am a beginner in python and have just started using it a couple weeks ago.
I am using python 3.4.3 on windows 7 machine together with IDLE 3.4.3 for compiling a code.
The following steps are:

I have a program, called PyAquire, such as:

import PyAquireUi
import sys
from PySide import QtGui
import PyAquireMain

def main():
master = PyAquireMain.PyAquireMain()
app = QtGui.QApplication(sys.argv)
ex = PyAquireUi.PyAquireMainWindow(master)
sys.exit(app.exec_())



if __name__ == '__main__':
main()

which opens a new window, where by clicking RUN/STOP button, program acquires data. The data is running in the window.
Program runs in the background, acquiring data all the time and
my task is to write a code, where I will be able

a) to connect with this program without interrupting the process

b) capture the current available data

c) and save data to excel file.

The code I have written is:

import PyAquireMain

def main():
obj = PyAquireMain.PyAquireMain()# Create instance obj
obj.saveSweepData()# call the method from PyAquireMain to save the file


if __name__ == '__main__':
main()


saveSweepData function from PyAquireMain is:
def saveSweepData(self):
fileSuffix = QtCore.QDateTime.currentDateTime().toString('yyyy-MM-dd_hh.mm.ss')
fileType = '.csv' # was .txt
if self.ch1.yData is not None:
saveFileName = 'data' + fileSuffix + fileType
with open(os.path.join(self.settings.saveDir,saveFileName),'wb') as f:
# f.writelines(header)
np.savetxt(f,self.ch1.yData,fmt='%d',delimiter='\n')


Therefore the question is how can I access the PyAquireMain, capture data and save file simultaneously when other program is running in the background.


Thanks,
Patrycja

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-07-20 09:23:13 UTC
Permalink
Post by Patrycja Niewosz
I am a beginner in python and have just started using it a couple weeks ago.
I am using python 3.4.3 on windows 7 machine together with IDLE 3.4.3 for compiling a code.
Can you tell us where you got it?
I did a search and the only one I could find was called pyacquire
(with a c) and seems to be an astronomy tool that is allegedly
hosted on google code but the site has no code! And no wiki
entries or issues or logged changes - in short its dead!

Is this the same package or something else? (Or did you
write it yourself?)

The reason I did the search is that this list is for questions about the
Python language and its standard library so normally I'd suggest you ask
on the pyaquire list or forum. But since I can't find one
that's not much help! The only other place you might get help is the
main Python mailing list.
Post by Patrycja Niewosz
import PyAquireUi
import sys
from PySide import QtGui
For PySide questions you can try any of several Qt mailing lists/fora
Post by Patrycja Niewosz
import PyAquireMain
master = PyAquireMain.PyAquireMain()
app = QtGui.QApplication(sys.argv)
ex = PyAquireUi.PyAquireMainWindow(master)
sys.exit(app.exec_())
main()
which opens a new window, where by clicking RUN/STOP button,
program acquires data. The data is running in the window.
Program runs in the background, acquiring data all the time
That last line is probably not true, but without knowing more about the
module I can't be sure. However I strongly suspect that it is probably
running within an event loop which gives your code the opportunity to
register an event whereby you can intercept the results. But without any
sign of code or documentation we can't really help.
Post by Patrycja Niewosz
a) to connect with this program without interrupting the process
b) capture the current available data
See comment above but we need to see the API.
Post by Patrycja Niewosz
c) and save data to excel file.
There are a couple of modules for saving to Excel native format,
but I'd suggest you use a csv file instead since that is compatible with
most spreadsheets etc - not everyone uses Excel and you might
have to share the results someday! The csv module will do that for
you.
Post by Patrycja Niewosz
import PyAquireMain
obj = PyAquireMain.PyAquireMain()# Create instance obj
obj.saveSweepData()# call the method from PyAquireMain to save the file
Its not clear how this relates to the other program above?
Do you run the previous code in one interpreter and this
code in another? That's almost certainly the wrong way to
go about things.
Post by Patrycja Niewosz
fileSuffix = QtCore.QDateTime.currentDateTime().toString('yyyy-MM-dd_hh.mm.ss')
fileType = '.csv' # was .txt
saveFileName = 'data' + fileSuffix + fileType
# f.writelines(header)
np.savetxt(f,self.ch1.yData,fmt='%d',delimiter='\n')
This doesn't help us very much except that the reference to np
suggests this might be part of numpy so the numpy or scipy fora
might be able to help.
Post by Patrycja Niewosz
Therefore the question is how can I access the PyAquireMain, capture data and save file
simultaneously when other program is running in the background.
It all depends on how pyaquire does its job.
One possibility might be to use the new asyncio module in Python 3.4
but until we know more about this module we can't be sure.
--
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


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Continue reading on narkive:
Loading...