LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

I need a timeout or break on the ScanIn function

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 );

0 Kudos
Message 1 of 5
(3,372 Views)

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.

0 Kudos
Message 2 of 5
(3,345 Views)

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);

 

0 Kudos
Message 3 of 5
(3,281 Views)

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.

0 Kudos
Message 4 of 5
(3,225 Views)

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.

0 Kudos
Message 5 of 5
(3,222 Views)