Collecting data every 250ms

I want to write a string of data into a file on disk every 250ms

I need to insert an instruction in my C program such that after every 250ms (or, some Xms), I go get the data and write it to file… and keep doing this for a long period of time (hours, days).

What QNX function can I use to do this? Or, how is this best done in QNX 6.3 please?

Cheers,
John

Hi John, C newbie I see ;-)

It depends, there are multiple ways to do this. If the program is only doing that then

for(;:wink:
{
readdata();
writedata();
delay(250); // this will pause the program for 250ms
}

If the program is doing other thing and is block in a MsgReceive then you need to setup a timer to fire a pulse every 250ms.

Cheers!

Another way is to create a thread that does this.

for(;:wink:
{
pthread_lock_mutex(&data_mutex);
GET_DATA
pthread_unlock_mutex(&data_mutex);
write();
delay(250);
}

If your 250ms cycle time is critical, ie. jitter is a problem, you might have to resort to attaching to the timer interrupt.

Thanks mario!
Thanks maschoen!
I am pretty sure this is what I need.
Yep, C newbe - and after all these years :wink:
John