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

Appendix A
Sample Applications
A-22
/***************************************************************************/
/************************** EXTRACT_START_POINTER **************************/
/***************************************************************************/
unsigned long extract_start_pointer(char far *data)
{
// This function will extract the starting pointer to the segment.
unsigned long startPointer = 0L;
unsigned long far *ptr = NULL;
// Set a pointer to the first segment address and extract the long.
(char *) ptr = &data[1];
startPointer = *ptr;
return(startPointer);
}
/***************************************************************************/
/*************************** EXTRACT_END_POINTER ***************************/
/***************************************************************************/
unsigned long extract_end_pointer(char far *data)
{
// This function will extract the ending segment address.
unsigned long endPointer = 0L;
unsigned long far *ptr = NULL;
// Set a pointer to the second segment address and extract the long.
(char *) ptr = &data[5];
endPointer = *ptr;
return(endPointer);
}
/***************************************************************************/
/*************************** CALC_SEGMENT_SIZE *****************************/
/***************************************************************************/
unsigned long calc_segment_size(unsigned long startPointer,
unsigned long endPointer)
{
// Calculate the size of the segment.
return(endPointer - startPointer + 1);
}
/***************************************************************************/
/************************ CALC_PHYSICAL_READ_COUNT *************************/
/***************************************************************************/
unsigned short calc_physical_read_count(unsigned long segmentSize)
{
// Returns the number of physical reads which will be necessary
// to read the entire segment. This calculation assumes that
// we are reading kReadSize bytes at a time.
// REMEMBER... THIS 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.
return(segmentSize / kReadSize);
}