07-02-2013 09:08 AM
I have a PLC controlling my printer. I tell it to print but occasionally the command is lost. I execute ScanIn to read the barcode for validation. The Process hangs, waiting on the ScanIn to read something. I want to timeout the ScanIn and fire the print cycle a second time. The Label is loaded but the print command was lost.
// send command to drive printer to print label
StatDigWrite = DAQmxWriteDigitalLines (Task1, SampChanRead, 1, 10.0,
DAQmx_Val_GroupByChannel, WriteDigOut, &SampChanWrite, 0);
Lcnt++;
printf("\n>> Lcnt = %d \n",Lcnt);
sprintf(ProgFailStr,"Scan-Failure");
sprintf(Printer_LabelPrint_ErrorString,ProgFailStr);
if(MSM_HVSM_Flag ==3)S2_number = ComRdTerm(4,scan_code_in,19,13);
// this is where the program will hang when no label is printed
if(MSM_HVSM_Flag <=2){S2_number = ScanIn ("%s[w19]",scan_code_in);}
if(MSM_HVSM_Flag <=2){S1_number = ScanIn ("%s[w19]",scan_code_extra);}
S_number = strncmp(scan_code_in,"20TD",4); //strncmp = 0 (a = b)
printf(">> S_number = \"%d\"\n scan_code_in = \"%s\" \n",S_number,scan_code_in );
printf(">> S2_number = \"%d\"\n S1_number = \"%d\"\n",S2_number,S1_number );
07-04-2013 07:11 AM
Maybe run your ScanIn in a separate thread with a delay in the main one, and kill it after the delay expire. But usually this kind of devices are left in unstable states when they start hanging. You mileage may vary.
07-24-2013 08:01 AM
Hello gdargaud,
I have been trying to find some examples of how these 2 commands are executed. Is there an example in existence utilizing these commands ?
int CmtGetThreadPoolFunctionAttribute (CmtThreadPoolHandle poolHandle, CmtThreadFunctionID threadFunctionID, int attributeID, void *attributeValue);
int CmtTerminateThreadPoolThread (CmtThreadPoolHandle poolHandle, unsigned int threadID, int exitCode);
I am using this command to launch my secondary thread. StatusCmtStatus = CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunctionX1, X1ThreadFunctionData,&StatusThreadFuncID);
08-05-2013 08:21 AM
I don't think you need to use pools for that. Check out the simpler multithreading examples in [Optimizing applications][Multithreading].
Note: personally I don't use the NI threads but pthreads for compatibility with various OSes.
08-05-2013 08:31 AM
I did get the code working with the thread pool. However, this caused some unexpected results with the PLC. The scanner in a separate thread did work without a hitch. Thank You for feedback. I will look into Optimizing Applications. I am always open to learning new tools for my toolbox.