Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A vision camera scans the pallet bar codes as they pass, the number of parts on

ID: 3855665 • Letter: A

Question

A vision camera scans the pallet bar codes as they pass, the number of parts on the pallet (not a constant value) is extracted from the bar code data, and that number is transferred to a PLC and placed in a register e.g. N7: 5. A bit (e.g. B3: 0/3) in the PLC is turned on by the vision system when the quantity data has transferred. The total number of pallets is stored in a register e.g. N7: 4. Design a ladder program that keeps a running total for pallet parts in a register (e.g. N7: 6) and the number of pallets left in the batch in another register (e.g. N7: 4). Include logic for a normally open push button (PB) switch (e.g. I: 1/4) that is used to clear register the total register (e.g. N7: 6 mentioned above) at the end of a production run in preparation for the next batch.

Explanation / Answer

import com.abbyy.ocrsdk.*;

public class TestApp {

  
public static void main(String[] args) {
System.out.println( "App started" );

// The application takes as input parameters:
// - Application ID
// - Application Password
// - Path to the image file to be recognized
// - Path to the file to save recognized values to
// Application ID and Application Password can be created
// by a registered user. To do it,
// log in to the ABBYY Cloud OCR SDK web site.
// If you are not registered yet, register
// at http://cloud.ocrsdk.com/Account/Register
if( args.length != 4 ) {
System.out.println( "Invalid arguments. Usage:" );
System.out.println( "program <app id> <password> <input file> <output file>" );
return;
}

// See implementation of the Client class below.
Client restClient = new Client();
restClient.ApplicationId = args[0];
restClient.Password = args[1];

String filePath = args[2];
String outputFile = args[3];

try {
System.out.println( "Uploading.." );

// To extract barcode values from an image,
// send an image to Cloud OCR server using processImage call
// with barcodeRecognition profile as a parameter.
Task task = restClient.ProcessImage(filePath);
// See implementation of the Task class below.

// To read a single barcode field,
// send an image of a barcode to Cloud OCR server
// using processBarcodeField call:
// Task task = restClient.ProcessBarcodeField(filePath);
// See implementation of the Task class below.

while( task.IsTaskActive() ) {
Thread.sleep(2000);

System.out.println( "Waiting.." );
task = restClient.GetTaskStatus(task.Id);
}

if( task.Status == Task.TaskStatus.Completed ) {
System.out.println( "Downloading.." );
restClient.DownloadResult(task, outputFile);
} else {
System.out.println( "Task failed" );
}

// Parse output XML to extract barcode values.
// Note that output XML files have different structure
// depending on the method you used for processing.

System.out.println( "Ready" );

} catch( Exception e) {
System.out.println( "Exception occurred:" + e.getMessage() );
}
}

}

Clint class

package com.abbyy.ocrsdk;

import java.io.*;
import java.net.*;

public class Client {
public String ApplicationId;
public String Password;

public String ServerUrl = "http://cloud.ocrsdk.com";

public Task ProcessImage( String filePath) throws Exception
{
// Use barcodeRecognition profile to extract barcode values
// Save results in XML (you can use any other available output format).
// For details, see API Reference for processImage method.
URL url = new URL(ServerUrl + "/processImage?profile=barcodeRecognition&exportFormat=xml");
byte[] fileContents = readDataFromFile( filePath );

HttpURLConnection connection = openPostConnection(url);

connection.setRequestProperty("Content-Length",
Integer.toString(fileContents.length));
connection.getOutputStream().write( fileContents );

BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream()));
return new Task(reader);
}

public Task ProcessBarcodeField( String filePath) throws Exception
{
// Specify the region of a barcode (by default, the whole image is recognized),
// barcode type, and other parameters.
// For details, see API Reference for processBarcodeField method.
URL url = new URL(ServerUrl + "/processBarcodeField?region=0,0,100,100&barcodeType=pdf417");
byte[] fileContents = readDataFromFile( filePath );

HttpURLConnection connection = openPostConnection(url);

connection.setRequestProperty("Content-Length",
Integer.toString(fileContents.length));
connection.getOutputStream().write( fileContents );

BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream()));
return new Task(reader);
}

public Task GetTaskStatus( String taskId ) throws Exception
{
URL url = new URL( ServerUrl + "/getTaskStatus?taskId=" + taskId );

URLConnection connection = openGetConnection( url );
BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream()));
return new Task(reader);
}

public void DownloadResult( Task task, String outputFile ) throws Exception
{
if( task.Status != Task.TaskStatus.Completed ) {
throw new IllegalArgumentException("Invalid task status");
}

if( task.DownloadUrl == null ) {
throw new IllegalArgumentException( "Cannot download result without url" );
}

URL url = new URL( task.DownloadUrl );
URLConnection connection = url.openConnection(); // do not use authenticated connection

BufferedInputStream reader = new BufferedInputStream( connection.getInputStream());

FileOutputStream out = new FileOutputStream(outputFile);

byte data[] = new byte[1024];
int count;
while ((count = reader.read(data, 0, 1024)) != -1)
{
out.write(data, 0, count);
}
}

private HttpURLConnection openPostConnection( URL url ) throws Exception
{
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
setupAuthorization( connection );
connection.setRequestProperty("Content-Type", "applicaton/octet-stream" );

return connection;
}

private URLConnection openGetConnection( URL url ) throws Exception
{
URLConnection connection = url.openConnection();
setupAuthorization( connection );
return connection;
}

private void setupAuthorization( URLConnection connection )
{
connection.addRequestProperty( "Authorization", "Basic: " + encodeUserPassword());
}

private byte[] readDataFromFile( String filePath ) throws Exception
{
File file = new File( filePath );
InputStream inputStream = new FileInputStream( file );
long fileLength = file.length();
byte[] dataBuffer = new byte[(int)fileLength];

int offset = 0;
int numRead = 0;
while( true ) {
if( offset >= dataBuffer.length ) {
break;
}
numRead = inputStream.read( dataBuffer, offset, dataBuffer.length - offset );
if( numRead < 0 ) {
break;
}
offset += numRead;
}
if( offset < dataBuffer.length ) {
throw new IOException( "Could not completely read file " + file.getName() );
}
return dataBuffer;
}

private String encodeUserPassword()
{
String toEncode = ApplicationId + ":" + Password;
return Base64.encode( toEncode );
}

}

implementation

package com.abbyy.ocrsdk;

import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.xml.sax.*;

public class Task {
public enum TaskStatus {
Unknown,
Submitted,
Queued,
InProgress,
Completed,
ProcessingFailed,
Deleted,
NotEnoughCredits
}

public Task( Reader reader ) throws Exception
{
// Read full task information from xml
InputSource source = new InputSource();
source.setCharacterStream(reader);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(source);

NodeList taskNodes = doc.getElementsByTagName("task");
Element task = (Element)taskNodes.item(0);

parseTask(task);
}

public TaskStatus Status = TaskStatus.Unknown;
public String Id;
public String DownloadUrl;

public Boolean IsTaskActive()
{
if( Status == TaskStatus.Queued || Status == TaskStatus.InProgress )
return true;

return false;
}

private void parseTask( Element taskElement )
{
Id = taskElement.getAttribute("id");
Status = parseTaskStatus( taskElement.getAttribute( "status" ) );
if( Status == TaskStatus.Completed )
DownloadUrl = taskElement.getAttribute("resultUrl");
}

private TaskStatus parseTaskStatus( String status )
{
if( status.equals( "Submitted") )
return TaskStatus.Submitted;
else if( status.equals( "Queued" ) )
return TaskStatus.Queued;
else if( status.equals( "InProgress" ) )
return TaskStatus.InProgress;
else if( status.equals( "Completed") )
return TaskStatus.Completed;
else if (status.equals( "ProcessingFailed") )
return TaskStatus.ProcessingFailed;
else if (status.equals( "Deleted") )
return TaskStatus.Deleted;
else if (status.equals( "NotEnoughCredits") )
return TaskStatus.NotEnoughCredits;
else
return TaskStatus.Unknown;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote