Code error using PtAppAddFd

Hello!

This is part of my code. I am trying to capture and display text typed on a laptop’s hyperterminal on to another computer’s GUI which was created with phAB. I have no problems opening and closing the comm port. Just have some problems capturing and displaying the text.
There are some errors but I do not know how to correct them. Could anyone please tell me what is wrong with it. Thanks in advance!

where the text captured is to be displayed in a multitext widget called
" base_multitext3 "

//Loop until the character q is sent via the serial port
while (iExit ==0)
{
//Read in any data if present
iBytesRead = read(iFileDescriptor, szMessage, 3);

PtArg_t args[256];
PtAppAddFd(PtAppContext_t app, int fd, unsigned Pt_FD_READ,
PtFdProc_t fun, void *data);
PtSetArg(&args[0], Pt_ARG_TEXT_STRING, data, 0);
PtSetResources(ABW_base_multitext3, 256, args);

//Check if data was successfully read
if(iBytesRead>0)
{
if(szMessage[0] ==113) iExit=1;
//Send back what was received
write(iFileDescriptor, szMessage, iBytesRead);
}
}

Oh man, I don’t know where to start. Go find a book on basic ‘C’ and work through any examples in it. Then try to find something about event driven programming which might help you understand the idea of a callback function.

Off the top of my head, and without more context, a couple obvious errors:

You can’t declare a variable after the code has started (in C anyway). So the args declaration needs to be at the top of the statement block (after the {).

Just dropping the prototype for a function you don’t understand into the middle of your code will not accomplish anything. Basically your callback function should be something like this:

int myReadFunc(void *data)
{
  PtArg_t args[1];
  iBytesRead = read(IFileDescriptor, szMessage, 3);
  if( iBytesRead > 0 )
    {
       PtSetArg(&args[0], Pt_ARG_TEXT_STRING, szMessage, 0);
       PtSetResources(ABW_base_multitext3, 1, args );
    }
}

// then in other code...
PtAppAddFd(app, iFileDescriptor, Pt_FD_READ, myReadFunc, NULL);

I won’t go into my opinion on hungarian convention naming. :confused:

Rick…

Thanks a lot Rick! Very glad that you answered my queries! :unamused: