homayoun mh / Mbed 2 deprecated SimpleModbusTest

Dependencies:   SimpleModbus mbed

Committer:
homayoun
Date:
Wed Aug 27 18:18:10 2014 +0000
Revision:
1:24c0ddc2b2f0
Parent:
0:985e576cf826
-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
homayoun 0:985e576cf826 1 #include "mbed.h"
homayoun 0:985e576cf826 2 #include <SimpleModbus.h>
homayoun 0:985e576cf826 3
homayoun 0:985e576cf826 4 #define timeout 1000
homayoun 0:985e576cf826 5 #define polling 200 // the scan rate
homayoun 0:985e576cf826 6 #define retry_count 10
homayoun 0:985e576cf826 7 #define TxEnablePin 2
homayoun 0:985e576cf826 8 #define LED 13
homayoun 0:985e576cf826 9
homayoun 0:985e576cf826 10 enum {
homayoun 0:985e576cf826 11 PACKET1,
homayoun 0:985e576cf826 12 PACKET2,
homayoun 0:985e576cf826 13 TOTAL_NO_OF_PACKETS // leave this last entry
homayoun 0:985e576cf826 14 };
homayoun 0:985e576cf826 15 Packet packets[TOTAL_NO_OF_PACKETS];
homayoun 0:985e576cf826 16 packetPointer packet1 = &packets[PACKET1];
homayoun 0:985e576cf826 17 packetPointer packet2 = &packets[PACKET2];
homayoun 0:985e576cf826 18 unsigned int readRegs[2];
homayoun 0:985e576cf826 19 unsigned int writeRegs[2];
homayoun 0:985e576cf826 20
homayoun 0:985e576cf826 21 void setup()
homayoun 0:985e576cf826 22 {
homayoun 0:985e576cf826 23 modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0, 2, readRegs);
homayoun 0:985e576cf826 24 modbus_construct(packet2, 1, PRESET_MULTIPLE_REGISTERS, 2, 2, writeRegs);
homayoun 0:985e576cf826 25 modbus_configure(timeout, polling, retry_count, packets, TOTAL_NO_OF_PACKETS);
homayoun 0:985e576cf826 26
homayoun 0:985e576cf826 27 }
homayoun 0:985e576cf826 28
homayoun 0:985e576cf826 29 void loop()
homayoun 0:985e576cf826 30 {
homayoun 0:985e576cf826 31 modbus_update();
homayoun 0:985e576cf826 32
homayoun 0:985e576cf826 33 writeRegs[0] = 255;
homayoun 0:985e576cf826 34 // writeRegs[1] = analogRead(A1); // update data to be written to arduino slave
homayoun 0:985e576cf826 35 //
homayoun 0:985e576cf826 36 // if (readRegs[0]==255) digitalWrite(LED, HIGH);
homayoun 0:985e576cf826 37 // else digitalWrite(LED, LOW);
homayoun 0:985e576cf826 38
homayoun 0:985e576cf826 39 }
homayoun 0:985e576cf826 40
homayoun 0:985e576cf826 41 int main()
homayoun 0:985e576cf826 42 {
homayoun 0:985e576cf826 43 setup();
homayoun 0:985e576cf826 44 while(1) loop();
homayoun 0:985e576cf826 45 }