Priority in real time process

Posted on 2003-02-18
Medium Priority
Last Modified: 2010-05-01
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?
Question by:kenkiiro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 7980237
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 ;)

Author Comment

ID: 7980520
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!!  :)

Accepted Solution

HarmnKardn earned 280 total points
ID: 7982004
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.

Expert Comment

ID: 8940470
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?
LVL 49

Expert Comment

ID: 8959596
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question