Appendix a – Rockwell Automation 1785-Vx0B, D17856.5.9 PLC-5 VME VMEbus Programmable Controllers User Manual User Manual

Page 140

Advertising
background image

Appendix A

Sample Applications

A-18

// Open the output file for saving PLC memory.
if ((out = fopen(argv[1], ”w+b”)) == NULL)
{

printf(”\n\nFailed to open %s file”, argv[1]);
exit(1);

}

// Make certain the processor is in remote program mode
plc_in_remote_program_mode();

// Make certain there are no faults...
check_for_faults();

// Get the edit resource from the processor.
get_edit_resource();

// Ensure that the current port configuration will be saved in the
// physical image.
restore_port_configuration();

// Issue the upload all request.
upload_all(&replyPacket);

// Show upload stats and dump the reply packet contents
printf(”\n\nUpload all request was successful.”);
show_upload_statistics(&replyPacket);

// Now let’s read the PLC memory and write it to a file.
// Let’s get the starting address to read from and other
// statistics. The PLC-5/V40 currently has only one segment
readAddr = extract_start_pointer(replyPacket.data);
endPointer = extract_end_pointer(replyPacket.data);
segmentSize=calc_segment_size(readAddr, endPointer);
physicalReadCount=calc_physical_read_count(segmentSize);
finalPhysicalReadSize=calc_final_phys_read_size(segmentSize);

// Let’s upload each kReadSize chunk of memory from the
// PLC and write it to disk. The final read may or may
// not be necessary. It is handled outside of this loop.

// REMEMBER... PHYSICAL READ COUNT IS FOR THE NUMBER OF FULL READS...
// YOU WILL STILL NEED TO DETERMINE IF AN ADDITIONAL ONE IS
// NECESSARY FOR THE FINAL NON-FULL READ. FOR EXAMPLE, IF
// YOU ARE GOING TO UPLOAD 101912 BYTES AND WILL BE READING
// 244 BYTES AT A TIME, YOU WILL PERFORM 417 FULL READS AND
// ONE ADDITIONAL ONE OF 164 BYTES.

for (i=0; i<physicalReadCount; i++)
{

read_plc_to_file(readAddr, out, kReadSize, i+1);
readAddr = readAddr + kReadSize;

}

// Determine if there are any left over bytes to read.
// They may exist because the number of bytes wasn’t an
// exact multiple of kReadSize.
if (finalPhysicalReadSize != 0)
{

printf(”\n\nFinal Physical Read Required:”);
read_plc_to_file(readAddr, out,

finalPhysicalReadSize, i+1);

Advertising