Can't fprintf with SIGEV_PULSE

Hi all,

I’m trying to log local computer time periodically into a file.
When I run the program, my time.txt file has nothing in it.

I’ve written the code to retrive the local computer time.
Here is part of my code:


#define OneMilliSec 1000000

FILE *myfile1;

typedef union{
   struct _pulse pulse;
} my_message_t;

int main (void){

...

initTimer();
myfile1 = fopen("/root/time.txt");

while(1){
   rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
   if (rcvid == 0){
     fprintf(myfile1, "%d %d %d\n", Hour, Min, Sec);

      ...

   }
}

void initTimer(void){
   struct sigevent event;
   struct itimerspec itime;

   timer _t timer_id;

   chid = ChannelCreate (0);

   event.sigev_notify = SIGEV_PULSE;
   event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0);
   event.sigve_proprity = getprio(0);

   timer_create(CLOCK_REALTIME, &event, &timer_id);

   itime.it_value.tv_sec = 0;
   itime.it_value.tv_nsec = 10 * OneMilliSec;
   itime.it_interval.tv_sec = 0;
   itime.it_interval.tv_nsec = 10 * OneMilliSec;
   timer_settime(timer_id, 0, &itimer, NULL);
}

If I comment off the MsgReceive line, etc:

   //rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);

I’m able to log the time but it is not at interval of 10ms.
It is logged continuously as fast as the computer can.

What changes must I make in order to log the time at the specific interval?
Or are there better ways to do it?

Thanks for helping.

Rabbit

ALWAYS check the return value of thinks like ChannelCreate, ConnectAttach, timer_create, timer_settime, and on error check the value of errno.

It’s pretty hard to know what is wrong since you clearly didn’t
give us real code. The above would have compiler errors even
if the missing code was not. I redid your code below, and it works
as expected.

#include <libc.h>
#include <sys/neutrino.h>
#include <sys/netmgr.h>

FILE *myfile1; 
int chid;
typedef union
{ 
	struct _pulse pulse; 
} my_message_t; 

void initTimer(void);
int main (void)
{ 
	int rcvid;
	char msg[80];

	initTimer(); 
	myfile1 = stderr; 

	while(1)
	{ 
		rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL); 
		if (rcvid == 0)
		{ 
			fprintf(myfile1, "Got Pulse\n"); 
		}
	} 
} 

void initTimer(void)
{ 
	struct sigevent event; 
	struct itimerspec itime; 

	timer_t timer_id; 

	chid = ChannelCreate(0); 

	event.sigev_notify = SIGEV_PULSE; 
	event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0); 
	event.sigev_priority = getprio(0); 

	timer_create(CLOCK_REALTIME, &event, &timer_id); 

	itime.it_value.tv_sec = 1; 
	itime.it_value.tv_nsec = 0;
	itime.it_interval.tv_sec = 1; 
	itime.it_interval.tv_nsec = 0; 
	timer_settime(timer_id, 0, &itime, NULL); 
} 

Hi mario and maschoen.

I can logged data after I restart QNX without changing any codes.
Guess there is something wrong with QNX while I’m programming.

Thanks for replying. =)

99% of the time the problem is not the OS, but the person sitting in front of it ;-)

Mario, that depends on the OS ;-). A certain prevelant OS I have to use from time to
time does non-repeatable nasty things all the time.

This is a QNX forum right ;-)