ionotify() question

I am trying to use ionotify and a pulse to signal my program when data
comeinto the serial port. However something is not working. The program runs
and
I don’t get any errors, but It seems that I never receive the pulse because
I am peminately blocked on the MsgReceive call. I have posted the code along
with this message for reference.

I am sure that I am forgetting to do something, in the setup…
Any help would be grea
tly appreciated.

Thanks in advance!
Mike

I forgot to mention the serial port is set up correctly because if I comment
out the MsgReceive() I can get data from the serial port…

#include “serial.h”
#include <stdio.h>
#include <errno.h>

//needed for the pulse str and the event str
#include <unistd.h>
#include <sys/iomsg.h>
#include <sys/siginfo.h>

#define SER1_PULSE_CODE _PULSE_CODE_MINAVAIL+1


typedef union
{
struct _pulse pulse;
}Message_t;

int main(void)
{
int fd = 0;
int retVal = 0;
char SerBuffRead[SERIAL_READ_SIZE];
char SerBuffWrite[255] = “this is a test message\n”;

int chid;
int rcvid;
int coid;
int notret;

struct termios termios_new;
struct sigevent event;
Message_t ipc;

//create a message chanel
chid = ChannelCreate(0);
if(chid == -1)
printf(“The chanel could not be created”);

//attach to the message channel
coid = ConnectAttach(0, 0, chid, 0, 0);
if(coid == -1)
printf(“Could not attach to the chanel”);

//my function for opening a serial connection
//basically a standard open call
fd = OpenSerialConnection("/dev/ser1");

//if the serial port opened
if(fd > -1)
{
//my function gets the serial port settings
//as they are set on the open call
GetSerialPortSettings( &termios_ser, fd);

//my function to set the serial port to 9600,8N1
SetSerialPortSettings( termios_ser, fd);

//I want a pulse event to notify me when data comes into the serial port
SIGEV_PULSE_INIT(&event, chid, getprio(0), SER1_PULSE_CODE, NULL);

//attach a notification to the serial port
//when a message comes in to the port a pulse will be sent to
//this thread. We can then handle the data
notret = ionotify(fd,
_NOTIFY_ACTION_TRANARM, _NOTIFY_COND_INPUT, &event);

if(notret == -1)
printf(“Error setting up the notify”);

while(1)
{
printf(“About to block\n”);
//here is the MsgRcv, where I seem to get stuck and
//never get my pulse to unblock me??
rcvid = MsgReceive(chid, &ipc, sizeof(ipc), NULL);
if(rcvid == 0)
{
printf(“Pulse Received \n”);

retVal = ReadDataFromPort(fd, (char*)SerBuffRead);
printf(“The data read: %s\n”, SerBuffRead);

retVal = 0;
printf(“Write Buffer: %s\n”, SerBuffWrite);
retVal = WriteDataToPort(fd, SerBuffWrite);
}
//never get here??
printf(“Processd Something\n”);
}
}
}

Mike Toreno <no.spam@address.com> wrote:

I am trying to use ionotify and a pulse to signal my program when data
comeinto the serial port. However something is not working. The program runs
and
I don’t get any errors, but It seems that I never receive the pulse because
I am peminately blocked on the MsgReceive call. I have posted the code along
with this message for reference.

I am sure that I am forgetting to do something, in the setup…
Any help would be greatly appreciated.

Answered in detail elsewhere. In essence it is because you chose
_NOTIFY_ACTION_TRANARM which only notifies on the first byte, but
when you call ionotify() there is already at least one byte there.

-David

Thanks in advance!
Mike

I forgot to mention the serial port is set up correctly because if I comment
out the MsgReceive() I can get data from the serial port…

#include “serial.h”
#include <stdio.h
#include <errno.h

//needed for the pulse str and the event str
#include <unistd.h
#include <sys/iomsg.h
#include <sys/siginfo.h

#define SER1_PULSE_CODE _PULSE_CODE_MINAVAIL+1



typedef union
{
struct _pulse pulse;
}Message_t;

int main(void)
{
int fd = 0;
int retVal = 0;
char SerBuffRead[SERIAL_READ_SIZE];
char SerBuffWrite[255] = “this is a test message\n”;

int chid;
int rcvid;
int coid;
int notret;

struct termios termios_new;
struct sigevent event;
Message_t ipc;

//create a message chanel
chid = ChannelCreate(0);
if(chid == -1)
printf(“The chanel could not be created”);

//attach to the message channel
coid = ConnectAttach(0, 0, chid, 0, 0);
if(coid == -1)
printf(“Could not attach to the chanel”);

//my function for opening a serial connection
//basically a standard open call
fd = OpenSerialConnection("/dev/ser1");

//if the serial port opened
if(fd > -1)
{
//my function gets the serial port settings
//as they are set on the open call
GetSerialPortSettings( &termios_ser, fd);

//my function to set the serial port to 9600,8N1
SetSerialPortSettings( termios_ser, fd);

//I want a pulse event to notify me when data comes into the serial port
SIGEV_PULSE_INIT(&event, chid, getprio(0), SER1_PULSE_CODE, NULL);

//attach a notification to the serial port
//when a message comes in to the port a pulse will be sent to
//this thread. We can then handle the data
notret = ionotify(fd,
_NOTIFY_ACTION_TRANARM, _NOTIFY_COND_INPUT, &event);

if(notret == -1)
printf(“Error setting up the notify”);

while(1)
{
printf(“About to block\n”);
//here is the MsgRcv, where I seem to get stuck and
//never get my pulse to unblock me??
rcvid = MsgReceive(chid, &ipc, sizeof(ipc), NULL);
if(rcvid == 0)
{
printf(“Pulse Received \n”);

retVal = ReadDataFromPort(fd, (char*)SerBuffRead);
printf(“The data read: %s\n”, SerBuffRead);

retVal = 0;
printf(“Write Buffer: %s\n”, SerBuffWrite);
retVal = WriteDataToPort(fd, SerBuffWrite);
}
//never get here??
printf(“Processd Something\n”);
}
}
}






QNX Training Services
dagibbs@qnx.com