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

Page 166

Advertising
background image

Sample API Modules

Appendix B

B-8

/* Let’s initialize the status variable to success. */
memset((char *) status, 0x0, sizeof(PLC540V_STATUS_TYPE));

/* Let’s loop through the range of base addresses and see if a PLC-5/40V
is located. If one is found, then we will add it to the array.
*/
for (baseAddress =kPLC540V_MINIMUM_BASE_ADDRESS, arrayIndex = 0;

((baseAddress<=kPLC540V_MAXIMUM_BASE_ADDRESS) &&
(status->plc540vStatus == kPLC540V_SUCCESS));
baseAddress+=kPLC540V_GLOBAL_MEMORY_SIZE)

{

/* Read the manufacture-ID */
read_plc540v_register(baseAddress, kPLC540V_ID_REG, &manId, status);

/* If we successfully read the manufacter id, then we’ll attempt to
read the PLC-5/40V’s device type.
*/
if (status->plc540vStatus == kPLC540V_SUCCESS)
{
/* Read the PLC-5/40V’s device type. */
read_plc540v_register(baseAddress,kPLC540V_DT_REG,&devType,status);

if (status->plc540vStatus == kPLC540V_SUCCESS)
{

/* Determine if this device is a PLC-5/40V */
if ((manId == kPLC540V_MANUFACTURE_ID) &&
(devType == kPLC540V_DEVICE_TYPE))
{
/* We’ve located a PLC-5/40V so let’s
save its base address
*/
plcList[arrayIndex++] = baseAddress;
}

}
}

}
}

Advertising