# Example for Reading Buffered Results

The following image shows an example for reading Buffered Results:

The signals used are the following:

Signal Name | vision system Defined Signal or Tag | PLC User Defined Tag | Notes
--- | --- | --- | ---
EnableBufferResultsReq | - | Yes | Setting this bit enabled buffering of sets of results in the vision system.
BufferResultsEnable | Yes | - | This bit controls if buffering of result sets is enabled or not.
ResultsValid | Yes | - | This bit is set when results are ready for PLC to read. In the buffer results case it is set when the next result set is ready to read. This bit stays set if results still remain in the buffer and clears to 0 if there are no results.
InspectionResultsAck | Yes | - | PLC sets this bit after it has read the results from the vision system. In the buffer results case the next result set is loaded if they are available in the buffer.
RV_ONS | - | Yes | This bit detects the rising edge of ResultsValid and enables the rung outputs for one program scan (internal bit, it is set or unset automatically by the PLC).
InspectionResults | Yes | Yes | Tool results as defined the in the vision system job copied into a data array, [0] is the first element of the array.
Saved_Results[] | - | Yes | Copy of the result set read for PLC to operate on as needed depending on the application. This is a 100 element array to hold the tool results, InspectionID, Inspection Result Code (if used) and Job Pass state (if used).
InspectionID | Yes | - | Acquisition ID associated with the current set of results.
InspectionResultCode | Yes | - | You can set a meaningful code to the result set beyond just pass or fail.
JobPass | Yes | - | Bit denoting inspection pass or fail.
ID_Count | - | Yes | This is a PLC defined counter (0-99) to index through the results array that the buffered vision system results are copied into.

Rung 0 is enables the buffering of the results by setting the EnableBufferResultsReq bit to 1 which in turn causes the BufferResultsEnable bit to be set to 1 and sent to the vision system.

Once the vision system finishes the inspection of the acquired image after being triggered, it sends the result set to the PLC along with the state of ResultsValid bit set to 1 similar to the unbuffered case.

The ResultsValid bit in rung 1 is read in and set to 1 (and the InspectionResultsAck bit is not set or 0) so the RV_ONS bit becomes set for one PLC scan and enables the COP and MOV instructions to run and the counter to increment by 1.

The COP instruction is a copy instruction that copies multiple bytes of data from one source tag to another tag. So the Results array bytes of the vision system are copied to the Saved_Results[ID_Count.ACC]. Results element for the PLC to evaluate and act on as needed for the application.

For completeness there is also PLC logic in the 3 branches in rung 1 to save the Inspection ID (using the MOV instruction into Saved_Results[ID_Count.ACC].InspID), Inspection Result Code (using a MOV instruction into Saved_Results[ID_Count.ACC].InspResCode) and JobPass bit (setting a bit output into Saved_Results[ID_Count.ACC].JobPass) as needed for the application.

The CTU counter (ID_Count) increments with each new result set read into the PLC and it is used as an index for the Saved_Results array using the counter's accumulated value [ID_Count.ACC]. The results saved in the 100 element Saved_Results array is copied over once the ID_Count reaches 100 since the ID_Count.DN bit resets the counter back to 0 therefore the array index back to 0. The last branch performs the counter reset back to 0 function.

After the results are copied into PLC tags to be acted upon further, rung 2 sees that ResultsValid is still set and the InspectionResultsAck bit is then set to 1 and sent to the vision system. The vision system sees this and then resets or 0 out the ResultsValid bit and send that back to the PLC. This then causes the InspectionResultsAck to be reset to 0 in rung 2 of the PLC logic. If the vision system has more results to send in the buffer they are sent, and ResultsValid is set to 1 again and the pattern of copies or moves of results data continues until the buffer is empty and ResultsValid and InspectionResultsAck are both reset to 0.