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

Page 145

Advertising
background image

Appendix A

Sample Applications

A-23

/***************************************************************************/
/************************ CALC_FINAL_PHYS_READ_SIZE ************************/
/***************************************************************************/
unsigned short calc_final_phys_read_size(unsigned long segmentSize)
{

// Returns the number of bytes we will need to read to get the
// last remaining bytes of memory. In other words, if the amount
// of memory wasn’t an exact multiple of kReadSize.

return(segmentSize % kReadSize);

}

/***************************************************************************/
/************************* SHOW_UPLOAD_STATISTICS **************************/
/***************************************************************************/
void show_upload_statistics(PLC540V_PCCC_ULA_RPY_TYPE *replyPacket)
{

// Dump upload statistics to the terminal.

unsigned long segmentSize = 0L;
unsigned short physicalReadCount = 0;
unsigned short finalPhysicalReadSize = 0;
unsigned long startPointer = 0L;
unsigned long endPointer = 0L;
PCCC_RPY_PKT_TYPE *replyPointer;
char *ptr;

// Extract and calculate the upload parameters.
startPointer = extract_start_pointer(replyPacket->data);
endPointer = extract_end_pointer(replyPacket->data);
segmentSize=calc_segment_size(startPointer, endPointer);
physicalReadCount=calc_physical_read_count(segmentSize);
finalPhysicalReadSize=calc_final_phys_read_size(segmentSize);

// Display the stats...
printf(”\n\nUpload Statistics:”);
printf(”\n\tStart Pointer: 0x%08.8lx”, startPointer);
printf(”\n\tEnd Pointer: 0x%08.8lx”, endPointer);
printf(”\n\tSegment Size: 0x%08.8lx (%lu)”, segmentSize, segmentSize);
printf(”\n\tPhysical Read Count (w/o possible final read): 0x%04x (%u)”,
physicalReadCount, physicalReadCount);
printf(”\n\tFinal Physical Read Size: 0x%04x (%u)”,
finalPhysicalReadSize, finalPhysicalReadSize);

ptr = (char *) replyPacket;
replyPointer = (PCCC_RPY_PKT_TYPE *) ptr;

printf(”\n\nReply Packet Contents:”);
printf(”\n\tlnh First Byte: %x”, replyPointer->lnhFirstByte);
printf(”\n\tlnh Second Byte: %x”, replyPointer->lnhSecondByte);
printf(”\n\tdst: %x”, replyPointer->dstRpyPkt);
printf(”\n\tpsn: %x”, replyPointer->psn1RpyPkt);
printf(”\n\tsrc: %x”, replyPointer->srcRpyPkt);
printf(”\n\tpsn: %x”, replyPointer->psn2RpyPkt);
printf(”\n\tcommand: %x”, replyPointer->command);
printf(”\n\tremote error: %x”, replyPointer->remoteError);
printf(”\n\ttns: %x”, replyPointer->tns);

// The PLC-5/40V always responds with a single segment and its
// compare segment. Let’s dump their contents.
printf(”\n\nMemory Segment Information:”);
printf(”\n\tSegment 1 lng: %x”, replyPointer->optionalData[0]);

Advertising