Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Priority in real time process

I hav develop a program in VBA environment, to get data through serial comm.
In the program i use the timer (can be set from 0.5s -> ) to get the data. The process of getting data take around 0.2s.

I face 2 problem:

1)  The Timer is not given the highest priority in the program. When an interupt (eg. open a data file) occur, it will then go on with the interupt. This will then stop the process in timer for a while. This will miss out some real time data.

2)  When open others application/program in O/S (Win2000), the program will also be interupted. Different with (1) is that the timer will run but overflow in memory happen to be.

How to set the timer to highest priority in program and memory priority?
0
kenkiiro
Asked:
kenkiiro
1 Solution
 
rdrunnerCommented:
Point 2:

Dont you mean a STACK overflow?

This happens when you start to process your getdata() while you are still in it..

You need to make sure that your getdata Function wont start while it is running. This can be acomplished with a static variable inside the function (isRunning) - just set it to true while you process your data and then set it back to false when you leave your function...

Only process data when it is false...

Another thing you might consider is to split up your processes... Create one for gathering data , one for processing and one for controlling the other 2.. So they wont run into each other and cause themself to miss something....

P.s: 0.5 s is no realtime ;)
0
 
kenkiiroAuthor Commented:
rdrunner,
Thanks for reply.
What actually u mean by STACK overflow?

what u say is good idea, but if i want the getdata() to run at priority process and its run all the time once the program start (eg. getting data every 0.2s), so in between the 0.2s can do other process after doing the getdata().

But problem is that can we run the "process 2" half way and continue running it after the "process 1"(getdata())?
Because the getdata() is time consuming, and the process to most of the time can't be finish between 0.2s (eg. saving a large file to harddisk)

thanks for the proffesional advice!!  :)
0
 
HarmnKardnCommented:
It would probably be much more advisable to write a program like this in a truly multithreaded environment such as Visual C++ so that you can spawn a seperate thread to read the serial COMM data and in the background perform any file IO you need to take care of.  Plus, you'll have control over your thread priority.

It is possible to call kernel32's CreateThread(...) within a VB6 program but it's really not recommended.
0
 
CleanupPingCommented:
kenkiiro:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Accept HarmnKardn's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now