How to run two function from same resource(plot graphic and saving infinite data to txt file)












0














I'm new in Python, try to develop gui app. My data source is from serial port. When i pressed buttons, it should plot graphics and print it on the screen and print to new txt file.



All of above that i mentioned should do separetely.



My expected is: How can i run both saving data and plotting many graphics concurrently from same resource



I used threading, time.sleep, wx.Timer. but I couldn't succeed on it. Anybody can help me? Thanks a lot.










share|improve this question




















  • 1




    Welcome to SO! Please provide your code so that users can help you , see e.g. stackoverflow.com/help/mcve. See also stackoverflow.com/help/how-to-ask how to ask good questions.
    – dr0i
    Dec 28 '18 at 14:07












  • When reading from a serial port the data is effectively consumed by that process. That process will have to plot and write to the text file or plot and store or pass on data for another process to write the text file. You cannot have 2 processes reading the same data from the serial port.
    – Rolf of Saxony
    Dec 31 '18 at 9:42
















0














I'm new in Python, try to develop gui app. My data source is from serial port. When i pressed buttons, it should plot graphics and print it on the screen and print to new txt file.



All of above that i mentioned should do separetely.



My expected is: How can i run both saving data and plotting many graphics concurrently from same resource



I used threading, time.sleep, wx.Timer. but I couldn't succeed on it. Anybody can help me? Thanks a lot.










share|improve this question




















  • 1




    Welcome to SO! Please provide your code so that users can help you , see e.g. stackoverflow.com/help/mcve. See also stackoverflow.com/help/how-to-ask how to ask good questions.
    – dr0i
    Dec 28 '18 at 14:07












  • When reading from a serial port the data is effectively consumed by that process. That process will have to plot and write to the text file or plot and store or pass on data for another process to write the text file. You cannot have 2 processes reading the same data from the serial port.
    – Rolf of Saxony
    Dec 31 '18 at 9:42














0












0








0


0





I'm new in Python, try to develop gui app. My data source is from serial port. When i pressed buttons, it should plot graphics and print it on the screen and print to new txt file.



All of above that i mentioned should do separetely.



My expected is: How can i run both saving data and plotting many graphics concurrently from same resource



I used threading, time.sleep, wx.Timer. but I couldn't succeed on it. Anybody can help me? Thanks a lot.










share|improve this question















I'm new in Python, try to develop gui app. My data source is from serial port. When i pressed buttons, it should plot graphics and print it on the screen and print to new txt file.



All of above that i mentioned should do separetely.



My expected is: How can i run both saving data and plotting many graphics concurrently from same resource



I used threading, time.sleep, wx.Timer. but I couldn't succeed on it. Anybody can help me? Thanks a lot.







python multithreading serial-port wxpython pyserial






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 5:24







gcs

















asked Dec 28 '18 at 11:10









gcsgcs

33




33








  • 1




    Welcome to SO! Please provide your code so that users can help you , see e.g. stackoverflow.com/help/mcve. See also stackoverflow.com/help/how-to-ask how to ask good questions.
    – dr0i
    Dec 28 '18 at 14:07












  • When reading from a serial port the data is effectively consumed by that process. That process will have to plot and write to the text file or plot and store or pass on data for another process to write the text file. You cannot have 2 processes reading the same data from the serial port.
    – Rolf of Saxony
    Dec 31 '18 at 9:42














  • 1




    Welcome to SO! Please provide your code so that users can help you , see e.g. stackoverflow.com/help/mcve. See also stackoverflow.com/help/how-to-ask how to ask good questions.
    – dr0i
    Dec 28 '18 at 14:07












  • When reading from a serial port the data is effectively consumed by that process. That process will have to plot and write to the text file or plot and store or pass on data for another process to write the text file. You cannot have 2 processes reading the same data from the serial port.
    – Rolf of Saxony
    Dec 31 '18 at 9:42








1




1




Welcome to SO! Please provide your code so that users can help you , see e.g. stackoverflow.com/help/mcve. See also stackoverflow.com/help/how-to-ask how to ask good questions.
– dr0i
Dec 28 '18 at 14:07






Welcome to SO! Please provide your code so that users can help you , see e.g. stackoverflow.com/help/mcve. See also stackoverflow.com/help/how-to-ask how to ask good questions.
– dr0i
Dec 28 '18 at 14:07














When reading from a serial port the data is effectively consumed by that process. That process will have to plot and write to the text file or plot and store or pass on data for another process to write the text file. You cannot have 2 processes reading the same data from the serial port.
– Rolf of Saxony
Dec 31 '18 at 9:42




When reading from a serial port the data is effectively consumed by that process. That process will have to plot and write to the text file or plot and store or pass on data for another process to write the text file. You cannot have 2 processes reading the same data from the serial port.
– Rolf of Saxony
Dec 31 '18 at 9:42












1 Answer
1






active

oldest

votes


















0














You can certainly use a wx.Timer event to fetch the latest data from the serial port. With that data, you can stream it to an open file and update a graph of the data.



Without a more detailed question, it's hard to give a detailed answer. But, you may find the wxmplot library (https://newville.github.io/wxmplot/) useful. In fairness, I am the lead author of that library. One of its features I use it for is very similar to your need: "live updated plots" of data from an external source, and without recreating a new matplotlib figure for each new data set.



You might find the example at https://github.com/newville/wxmplot/blob/master/examples/stripchart.py to be a useful example. It has a function that simulates data, but you can replace this with "read from serial port" or fetching other data sources.






share|improve this answer





















  • Is wx.Timer enough, or should i use threading also?
    – gcs
    Jan 4 at 5:34










  • that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
    – M Newville
    Jan 4 at 14:54










  • The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
    – gcs
    2 days ago










  • as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
    – M Newville
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957584%2fhow-to-run-two-function-from-same-resourceplot-graphic-and-saving-infinite-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can certainly use a wx.Timer event to fetch the latest data from the serial port. With that data, you can stream it to an open file and update a graph of the data.



Without a more detailed question, it's hard to give a detailed answer. But, you may find the wxmplot library (https://newville.github.io/wxmplot/) useful. In fairness, I am the lead author of that library. One of its features I use it for is very similar to your need: "live updated plots" of data from an external source, and without recreating a new matplotlib figure for each new data set.



You might find the example at https://github.com/newville/wxmplot/blob/master/examples/stripchart.py to be a useful example. It has a function that simulates data, but you can replace this with "read from serial port" or fetching other data sources.






share|improve this answer





















  • Is wx.Timer enough, or should i use threading also?
    – gcs
    Jan 4 at 5:34










  • that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
    – M Newville
    Jan 4 at 14:54










  • The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
    – gcs
    2 days ago










  • as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
    – M Newville
    2 days ago
















0














You can certainly use a wx.Timer event to fetch the latest data from the serial port. With that data, you can stream it to an open file and update a graph of the data.



Without a more detailed question, it's hard to give a detailed answer. But, you may find the wxmplot library (https://newville.github.io/wxmplot/) useful. In fairness, I am the lead author of that library. One of its features I use it for is very similar to your need: "live updated plots" of data from an external source, and without recreating a new matplotlib figure for each new data set.



You might find the example at https://github.com/newville/wxmplot/blob/master/examples/stripchart.py to be a useful example. It has a function that simulates data, but you can replace this with "read from serial port" or fetching other data sources.






share|improve this answer





















  • Is wx.Timer enough, or should i use threading also?
    – gcs
    Jan 4 at 5:34










  • that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
    – M Newville
    Jan 4 at 14:54










  • The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
    – gcs
    2 days ago










  • as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
    – M Newville
    2 days ago














0












0








0






You can certainly use a wx.Timer event to fetch the latest data from the serial port. With that data, you can stream it to an open file and update a graph of the data.



Without a more detailed question, it's hard to give a detailed answer. But, you may find the wxmplot library (https://newville.github.io/wxmplot/) useful. In fairness, I am the lead author of that library. One of its features I use it for is very similar to your need: "live updated plots" of data from an external source, and without recreating a new matplotlib figure for each new data set.



You might find the example at https://github.com/newville/wxmplot/blob/master/examples/stripchart.py to be a useful example. It has a function that simulates data, but you can replace this with "read from serial port" or fetching other data sources.






share|improve this answer












You can certainly use a wx.Timer event to fetch the latest data from the serial port. With that data, you can stream it to an open file and update a graph of the data.



Without a more detailed question, it's hard to give a detailed answer. But, you may find the wxmplot library (https://newville.github.io/wxmplot/) useful. In fairness, I am the lead author of that library. One of its features I use it for is very similar to your need: "live updated plots" of data from an external source, and without recreating a new matplotlib figure for each new data set.



You might find the example at https://github.com/newville/wxmplot/blob/master/examples/stripchart.py to be a useful example. It has a function that simulates data, but you can replace this with "read from serial port" or fetching other data sources.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 31 '18 at 17:07









M NewvilleM Newville

2,8532719




2,8532719












  • Is wx.Timer enough, or should i use threading also?
    – gcs
    Jan 4 at 5:34










  • that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
    – M Newville
    Jan 4 at 14:54










  • The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
    – gcs
    2 days ago










  • as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
    – M Newville
    2 days ago


















  • Is wx.Timer enough, or should i use threading also?
    – gcs
    Jan 4 at 5:34










  • that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
    – M Newville
    Jan 4 at 14:54










  • The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
    – gcs
    2 days ago










  • as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
    – M Newville
    2 days ago
















Is wx.Timer enough, or should i use threading also?
– gcs
Jan 4 at 5:34




Is wx.Timer enough, or should i use threading also?
– gcs
Jan 4 at 5:34












that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
– M Newville
Jan 4 at 14:54




that is a separate question and a longer topic. A wx.Timer is good enough if the data comes predictably and quickly, as is the case for the example I linked to. You may want to use threads or other mechanisms if i/o is slow, which it might be for data from a serial port. I'd recommend starting with just wx.Timer and see if it is good enough.
– M Newville
Jan 4 at 14:54












The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
– gcs
2 days ago




The data comes every second. I skipped that problem and now i stuck with new one. The problem is my program run for 2 minutes then it give 'stack overflow' error. I append my infinite data to list and delete it after plotting, using wx.Timer. I dont know why it gave that error.
– gcs
2 days ago












as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
– M Newville
2 days ago




as earlier, that is a completely different question. It cannot be addressed in comments to an answer. If data comes every second, you should not fill memory in two minutes. Please post a complete example and the complete traceback you get as a separate question.
– M Newville
2 days ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957584%2fhow-to-run-two-function-from-same-resourceplot-graphic-and-saving-infinite-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas