Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SimpleModbusMaster.h>
- int flag;
- #define baud 9600
- #define timeout 1000
- #define polling 200 // the scan rate
- #define retry_count 10
- #define TxEnablePin 2
- #define LED 9
- #define LUZ 13
- #define TOTAL_NO_OF_REGISTERS 3
- enum
- {
- PACKET1,
- PACKET2,
- PACKET3,
- TOTAL_NO_OF_PACKETS // leave this last entry
- };
- Packet packets[TOTAL_NO_OF_PACKETS];
- unsigned int regs[TOTAL_NO_OF_REGISTERS];
- void setup()
- { // 1 int Addr 0001
- Serial.begin(9600); // 1 int data 0001
- // 2 start addr Reg[2]
- // modbus_construct(&packets[PACKET1], 2, READ_HOLDING_REGISTERS, 0, 1, 0);
- // modbus_construct(&packets[PACKET2], 2, READ_HOLDING_REGISTERS, 1, 1, 2);
- // modbus_construct(&packets[PACKET3], 1, READ_HOLDING_REGISTERS, 0, 1, 0);
- modbus_construct(&packets[PACKET1], 2, READ_HOLDING_REGISTERS, 0, 1, 0);
- modbus_construct(&packets[PACKET2], 2, READ_HOLDING_REGISTERS, 1, 1, 2);
- modbus_construct(&packets[PACKET3], 2, READ_HOLDING_REGISTERS, 2, 1, 4);
- modbus_configure(&Serial1, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
- pinMode(LED, OUTPUT);
- pinMode(LUZ, OUTPUT);
- }
- void loop()
- {
- modbus_update();
- unsigned long temp = (unsigned long)regs[0] << 16 | regs[1];
- Serial.println(" ");
- Serial.println("Regs");
- Serial.println(regs[0]);
- Serial.println(regs[2]);
- Serial.println(regs[4]);
- }
Add Comment
Please, Sign In to add comment