CallAT example (was PAP not working in X)
CallAT example (was PAP not working in X)
- Subject: CallAT example (was PAP not working in X)
- From: Will <email@hidden>
- Date: Tue, 23 Apr 2002 12:29:38 -0500
Ok so I have PAP working like I want it too and it is able to query the
printer over and over 100's of times without a problem. But now I am
getting this error after it is done "ATPsndreq: Operation timed out".
From what I have seen when debugging it actually finishes the loop of
messages (no pap_write with 2 true values is ever sent) then after a few
seconds the message about a ATPsnreq pops up and I get a Sig 11 error
that crashes the program. I think it always happens "after" the
function has exited. I have looked everywhere to find the problem.
The biggest pain is I can do this almost identical code by itself in a
stand alone program and it doesn't do this. Here is the modified code I
have which doesn't use the first part from the example where it locates
the printer and I don't have a cmd . to stop the process so I took out
the code looking for that, but other than that everything else is in
there, anyone sees something I am missing I would appreciate the help:
int GetConfig::getConfigVals()
{
PAPBuffer *pBuf;
EventRecord theEvent;
MPQueueID termQueue;
MPTaskID papTaskID;
int error = 0;
OSStatus termErr;
OSStatus status = 0;
int result = 0;
register int fd = -1;
register int i;
register int c;
char buffx[PRINTBUFSZ] = " ";
at_entity_t entity;
char *pap_status, *pap_status_get();
extern char *get_chooserPrinter();
at_nbptuple_t *tuple;
int first;
int messageNum = 0;
UInt32 finalTicks=0;
int counter=0;
u_char tempBuf[50];
if ((result == noErr))
{
int cnt = 0;
first = 1; /* some things happening for the first time */
while(cnt<10)
{
if (first)
fprintf(stdout, MSGSTR(M_TRYING,
"Trying to connect to %s:%s@%s.\n"),
printer.tuple2->enu_entity.object.str,
printer.tuple2->enu_entity.type.str,
printer.tuple2->enu_entity.zone.str);
/* Try to connect to the printer at this adress 5 times */
for (i=0; i<5; i++)
{
/* set default result which will be cleared if PAP is opened */
result = 1;
if ((fd = My_pap_open(printer.tuple2)) < 0)
{
pap_status = My_pap_status_get();
if (!strcmp(pap_status, PAP_SOCKERR))
{
fprintf (stdout, MSGSTR(M_SKT_ERR, "Socket Error %d\n"), errno);
result = 2;
break;
} else
{
if (first || isatty(fileno(stdout)))
fprintf (stdout, "%s\n",My_pap_status);
}
} else
{
result = noErr;
break;
}
first = 0;
Delay((2*60),&finalTicks);
//sleep(5);
}
/* If the connection has been successfully established, get
* out of the while loop!
*/
if (fd >= 0)
break;
cnt++;
}
if (result == noErr)
{
UInt32 finalTicks=0;
if (isLaser(&printer.entity2))
My_pap_read_ignore(fd);
/* init the papParms structure by setting all of the
flag fields to 0 */
papParms.processFlag = 0;
papParms.fd = fd;
/* init the MPqueues */
InitPAPQueues (&papParms);
if (status == noErr)
{
status = MPCreateQueue(&termQueue); /* create the
termination queue */
if (status)
fprintf (stderr, "error on MPCreateQueue - %d\n", status);
else
fprintf (stderr, "MPCreateQueue worked\n");
}
if (status == noErr)
{
papParms.processFlag = kMPQueueCreated;
status = MPCreateTask( (TaskProc)
CallPAPRead, &papParms,
kStackSize,termQueue,nil, nil, 0,
/* no term parameters
and 0 options */
&papTaskID);
if (status == noErr)
{
fprintf (stderr, "MPCreateTask worked\n");
}
else
{
fprintf (stderr, "error on MPCreateTask - %d\n", status);
gDone = false;
}
}
else
{
fprintf (stderr, "error on MPCreateQueue - %d\n", status);
gDone = false;
}
fprintf(stdout, "Press Command - E to stop sending flush
commands to printer\n");
fprintf(stdout, MSGSTR(M_PRINTING,
"printing on %s:%s@%s.\n"),
printer.tuple2->enu_entity.object.str,
printer.tuple2->enu_entity.type.str,
printer.tuple2->enu_entity.zone.str);
c= 0;
while (messageNum<5)//<===get the first 5 configurations
{
status = MPWaitOnQueue(termQueue, nil, nil, (void **)
&termErr, kDurationImmediate);
if (status == noErr)
{
gDone = false;
if (termErr)
fprintf(stderr," termErr returned %d \n", termErr);
}
sprintf(buffx,"/XanteProcs/ProcSet
findresource begin %d getconfiguration = flush end",messageNum);
messageNum++;
i = My_pap_write(fd, &buffx[c],
sizeof(buffx) - c, FALSE, FALSE);
if (i < 0) {
fprintf(stderr, "write failed");
return(2);
}
Delay((1),&finalTicks);
if ((pBuf = (PAPBuffer*)papParms.usedQ.qHead) != nil)
{
if (pBuf->flag == 0)
{
if (pBuf->res < 0)
{
fprintf(stderr," read failed %d\n", pBuf->res);
}
else
{
if (pBuf->res == 0)
fprintf(stderr," received got a null response\n");
else
{
strcat(printer.config,(const char*)pBuf->buffer);
}
}
status = Dequeue((QElemPtr)pBuf, (QHdrPtr)&papParms.usedQ);
if (status)
fprintf(stderr,
"Dequeue from usedQ failed %d\n", status);
else
Enqueue((QElemPtr)pBuf, (QHdrPtr)&papParms.freeQ);
}
}
}
if ((papParms.processFlag & kMPQueueCreated) != 0)
MPDeleteQueue(termQueue);
if (c)
{ //sending eof && flush
i = My_pap_write(fd, buffx, 0, TRUE, TRUE);
if (i < 0) {
fprintf(stderr, "write failed");
}
}
}
}
if (fd >= 0)
My_pap_close(fd);
if (gat_printer_list_tPtr != nil)
DisposePtr((char*)gat_printer_list_tPtr);
return (0);
}
On Friday, April 19, 2002, at 04:09 PM, Rich Kubota wrote:
At 2:14 PM -0500 4/18/02, Will wrote:
Hmmmm, well does anyone know of an example of using the pap_read
and pap_write functions? I have one called callAT and that is what I
have been using but it is also the code with the problem, I have gone
through this file and bare bones created another file that is much
cleaner and just has the 4 pap methods open, write, read, and close.
I tried with that and it still hangs on the 5th write. I am about to
check the packets between the computer and the printer as I noticed
the lock up leaves the printer in a waiting state therefore I am
guessing at least part of the 5th packet is getting over there, I just
have a feeling it is going to be corrupt.
Also, I checked the Apple example code at the web site and
couldn't find an example of a client using PAP just PAP servers anyone
got an example of a PAP client for OS X?
Will,
I've enclosed a sample. The sample is written for CodeWarrior 6,
before 7 was released. I plan to update the sample later on and post
it.
rich
--
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.