Scan Loop Problem

Scan Loop Problem

Anonymous
Not applicable
262 Views
0 Replies
Message 1 of 1

Scan Loop Problem

Anonymous
Not applicable
I wrote a ADS application for AutoCAD 13 with a colleague several years ago
that prints job tickets, cutplan slab maps, pallet layouts for our plant
floor. The application runs in a loop with a timer that every 10 seconds
goes out to look at a print queue table (SQL Server 2000) to see if anything
needs to be printed.

When I converted this application to ObjectARX for AutoCAD 2000, I have been
able to get everything else converted and working except for the capability
of the application to run in a loop. When I start the application if the
print queue table has records(tickets) to print the job tickets are printed
and the application continues the loop and hangs up after a short period of
time requiring a "end task" of AutoCAD 2000. If there are no job tickets in
the print queue table to print when the application is started the
application hangs up after a short period of time also. This time varies
whether there are other tasks running and where I move the mouse across the
screen.

I have included the section of code that I have the loop ( I have removed
some code that was unnecessary for this discussion)

****************************************************************************
****************************
void getTickets ()
{
//////////////////////////////////////////////
// START SCAN LOOP
/////////////////////////////////////////////

ads_printf("\nStarting scan loop...\n");
lsleeptime = 0;

while (!(stop = fopen("c:\\process\\stop.","rt")))
{
//ads_printf("\nChecking);
open_ticket_queue();

// Check For Data to Process
if (rsTicketQueue.GetRecordCount() == 0)
{
// Tickets Don't Exist In Ticket Que
// Check for CutPlan
//ads_printf("Ticket Queue Empty, Checking for CutPlan");
if (rsCPSlab.CanRestart())
{
// At least one record exists
if (!rsCPSlab.Requery()) // If no records
{
AfxMessageBox("Failed to Requery CPSLAB table",MB_OK,0);
return;
}
}
else
{
AfxMessageBox("Failed to Restart CPSLAB table",MB_OK,0);
return;
}

// CutPlan Slab
if (rsCPSlab.GetRecordCount() == 0)
{
ads_printf("\rNo Tickets - Waiting %ds", lsleeptime);
lsleeptime += 10;
Sleep(10000L);
}
else
{
lsleeptime = 0;

// CutPlan Pieces
if (rsCPPiece.GetRecordCount() > 0)
{
cpVerts = 0;
while (!rsCPPiece.IsEOF())
{
// Get Piece Information
strcpy(jobno, rsCPPiece.m_jobno.GetBuffer(1));
strcpy(pieceno, rsCPPiece.m_pieceno.GetBuffer(1));
TRY
{
sprintf(txtBuf, "jobno='%s' and
pieceno='%s'", jobno, pieceno);
rsPieceTicket.m_strFilter = txtBuf;
if (!rsPieceTicket.IsOpen())
{
rsPieceTicket.m_pDatabase = &dbCad;
int result = rsPieceTicket.Open();
if(!result)
AfxMessageBox("Failed to open
TICKET_LOG table",MB_OK,0);
}
else
{ // Able to requery
if (rsPieceTicket.CanRestart())
{
// At least one record exists
if (!rsPieceTicket.Requery()) //
If no records
{
AfxMessageBox("Failed to
Requery TICKET table",MB_OK,0);
return;
}
}
else
{
AfxMessageBox("Failed to Restart Ticket
table",MB_OK,0);
return;
}
}
}
CATCH(CDBException, e)
{
ads_printf("\nCatch Error
%s\n",e->m_strError.GetBuffer(1));
}
END_CATCH

// Move to next record

rsCPPiece.MoveNext();
cpVerts++;
}
}

// Draw the CutPlan Slab Map
strcpy(plotDevice, ticketPrinter);
draw_SlabMap();

// Draw each Piece
for (i=0; i {
strcpy(jobno, CutPlan.JobNumber);
strcpy(pieceno, CutPlan.PieceNumber);
ads_printf("\nProcessing %s %s\n", jobno, pieceno);
draw_it(3);
}

cpVerts = 0;

}
}
else //Tickets Exist in Ticket Queue
{
lsleeptime = 0;

strcpy(jobno, rsTicketQueue.m_jobno.GetBuffer(1));
strcpy(pieceno, rsTicketQueue.m_pieceno.GetBuffer(1));
csPlotDevice = rsTicketQueue.m_printer;
csPlotDevice.TrimRight();
strcpy(plotDevice, csPlotDevice);

// Retrieve Ticket Info
if (!getTicket()) return;

// Process Pallets
if (strcmp(plotDevice,"PAL9") == 0)
ProcessPallet();
else
{
ads_printf("\nProcessing %s %s\n", jobno, pieceno);
draw_it(3);
}

//if (!rsJob.IsFieldNull(&rsJob.m_locked_d)) //Only flag the
pieces if job is locked
StampTicket(1);

}//else RecordCount() > 0

//ads_printf(". ");

}// END while (!(stop = fopen("c:\\process\\stop.","rt")))

//////////////////////////////////////////////
// END SCAN LOOP
/////////////////////////////////////////////

fclose(stop);
DeleteFile("c:\\process\\stop.");

****************************************************************************
****************************

Thanks for your help,
Greg
0 Likes
263 Views
0 Replies
Replies (0)