Home › Forums › Mayfly Data Logger › Wingshield for Modbus Communication with Isco Signature › Reply To: Wingshield for Modbus Communication with Isco Signature
2019-11-25 at 12:59 PM
#13398
Okay, this should get you pretty far.
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#include <Arduino.h> #include <AltSoftSerial.h> #include <SensorModbusMaster.h> // Create the stream instance AltSoftSerial modbusSerial; // OR, if AltSoftSerial isn't working consistently enough // HardwareSerial modbusSerial = Serial1; // Create the modbus instance modbusMaster modbus; // Setup function // This is in addition to any other setup you need for a timer, sleep, // and modem communication or anything else you might be doing. setup() { // Start the stream modbusSerial.begin(baudRate); // start the modbus instance // modbusSlaveID = Signature's device address as programmed in Modbus Output Setup (2.6.4) modbus.begin(modbusSlaveID, modbusSerial); // If you want the Signature to automatically update its readings every 5 minutes, // you could do something like this: // 40025 = TakeReadingFlag - Set to 1 to update readings, 2 for automatic update (SRGD: 0 for no update?) modbus.uint16ToRegister(40025, 2); // 40026 = UpdateIntervalWordSeconds - The reading update interval in seconds // 300 seconds = 5 minutes modbus.uint16ToRegister(40026, 300); } // loop function // again, this is in addtion to other timing, sleep, and communication you need loop() { // Get current level status // The manual doesn't actually specify clearly, but I'm assuming the map is to holding registers (0x03) // 40042 = Levelstatus - The level status - non-zero is an error // Since anything non-zero is error, we'll just man-handle this into a boolean bool levelStatus = !modbus.uint16FromRegister(0x03, 40042) // Should we bother getting values if there's an error? if (levelStatus) { // Ask what time the last level reading was from: // we'll get all the registers at once // 40043 - 48 = Leveltime - The last level reading time,sec-min-hour-day-month-year bool gotDateTime = modbus.getRegisters(0x03, 40043, 6) if (gotDateTime) { uint16_t sec = modbus.uint16FromFrame(0); uint16_t min = modbus.uint16FromFrame(2); uint16_t hour = modbus.uint16FromFrame(4); uint16_t day = modbus.uint16FromFrame(6); uint16_t month = modbus.uint16FromFrame(8); uint16_t year = modbus.uint16FromFrame(10); } // Ask for the value // Note: we could get this in the same call as the time if we canted // 40040 - 40041 = Level float level = modbus.float32FromRegister(0x03, 40040); } // wait 5 mintues for the next reading } |