ionotify() question

I am trying to use ionotify and a pulse to signal my program when data come
into 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 geminately 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.
Thanks in advance!
Mike

p.s. the code is far from complete so it is a little messy…

#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”);
}
}
}

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…

Thanks…

“Mike Toreno” <no.spam@address.com> wrote in message
news:9pfn8v$khn$1@inn.qnx.com

I am trying to use ionotify and a pulse to signal my program when data
come
into 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 geminately 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.
Thanks in advance!
Mike

p.s. the code is far from complete so it is a little messy…

#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 come
into 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 geminately 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.

I think the problem is that you are using _NOTIFY_ACTION_TRANARM,
this means to notify you when the condition changes from empty to
non-empty on input – in other words, to notify you when the first
byte is received into an empty (internal to the serial driver) buffer.
If even one byte has already come accross the wire when you use that
flag, you will not be notified.

If using _TRANARM, you should enable notification, then drain the seral
port – read bytes from it until read() returns 0. You will then be
notified on the next byte received, and the notification will be removed.

You would then rearm notification & drain the serial port.

You might instead want to use _NOTIFY_ACTION_POLLARM.

You might also find looking through the docs for readcond() useful,
maybe not directly applicable, but useful for controlled serial
port access.

-David

Thanks in advance!
Mike

p.s. the code is far from complete so it is a little messy…

#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