void loop(){ // modbus_update() is the only method used in loop(). It returns the total error // count since the slave started. You don't have to use it but it's useful // for fault finding by the modbus master.

// If the packets internal retry register matches// the set retry count then communication is stopped// on that packet. To re-enable the packet you must// set the "connection" variable to true.#define retry_count 10

// used to toggle the receive/transmit pin on the driver#define TxEnablePin 2

// This is the easiest way to create new packets// Add as many as you want. TOTAL_NO_OF_PACKETS// is automatically updated.enum{ PACKET1, PACKET2, // leave this last entry TOTAL_NO_OF_PACKETS};

// Create an array of Packets for modbus_update()Packet packets[TOTAL_NO_OF_PACKETS];

// Create a packetPointer to access each packet// individually. This is not required you can access// the array explicitly. E.g. packets[PACKET1].id = 2;// This does become tedious though...packetPointer packet1 = &packets[PACKET1];

// The data from the PLC will be stored// in the regs arrayunsigned int regs[9];