/*----------------------------------------------------------------------------*\ Read method for the Modbus Master agent \*----------------------------------------------------------------------------*/ static pwr_tStatus IoAgentRead(io_tCtx ctx, io_sAgent* ap) { io_sAgentLocal* local; io_sRackLocal* local_rack; pwr_tUInt16 sts; io_sRack* rp; pwr_tCid cid; pwr_sClass_Modbus_TCP_Slave* sp; local = (io_sAgentLocal*)ap->Local; /* Do configuration check and initialize modules. */ rp = ap->racklist; while (rp) { cid = rp->Class; while (ODD(gdh_GetSuperClass(cid, &cid, rp->Objid))) ; switch (cid) { case pwr_cClass_Modbus_TCP_Slave: sp = (pwr_sClass_Modbus_TCP_Slave*)rp->op; local_rack = rp->Local; /* Start receving old data so the input buffer is flushed */ if (sp->Status == MB__NORMAL) { sts = mb_recv_data(local_rack, rp, sp); } /* Request new data */ if (sp->Status == MB__NORMAL && sp->DisableSlave != 1) { sts = mb_send_data(local_rack, rp, sp, mb_mSendMask_ReadReq); } break; } /* End - switch ... */ rp = rp->next; } return IO__SUCCESS; }
/*----------------------------------------------------------------------------*\ Write method for the Modbus_TCP slave \*----------------------------------------------------------------------------*/ static pwr_tStatus IoRackWrite ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp ) { io_sRackLocal *local; pwr_sClass_Modbus_TCP_Slave *sp; pwr_tStatus sts; local = rp->Local; sp = (pwr_sClass_Modbus_TCP_Slave *) rp->op; local->expected_msgs = 0; if (sp->Status == MB__NORMAL && sp->DisableSlave != 1) { sts = mb_send_data(local, rp, sp, mb_mSendMask_WriteReq); } if (sp->DisableSlave == 1) sp->Status = MB__DISABLED; return IO__SUCCESS; }