homayoun mh / Mbed 2 deprecated SimpleModbusTest

Dependencies:   SimpleModbus mbed

Committer:
homayoun
Date:
Wed Aug 27 18:16:55 2014 +0000
Revision:
0:985e576cf826
Child:
1:24c0ddc2b2f0
Arduino SimpleModbusMaster for mbed

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