Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ModbusMaster.h>
- ModbusMaster node;
- #define MAX485_RXD 16
- #define MAX485_TXD 17
- const byte addr_pm = 1;
- unsigned long cur_time, old_time;
- float van, vbn, vcn;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- Serial1.begin(9600, SERIAL_8N1, MAX485_RXD, MAX485_TXD);
- node.begin(addr_pm, Serial1);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- cur_time = millis();
- if (cur_time - old_time >= 1000) {
- uint8_t result;
- uint32_t tempdouble;
- result = node.readHoldingRegisters(3027, 6);
- if (result == node.ku8MBSuccess)
- {
- tempdouble = node.getResponseBuffer(1);
- tempdouble |= node.getResponseBuffer(0) << 16;
- van = *(float*)&tempdouble;
- tempdouble = node.getResponseBuffer(3);
- tempdouble |= node.getResponseBuffer(2) << 16;
- vbn = *(float*)&tempdouble;
- tempdouble = node.getResponseBuffer(5);
- tempdouble |= node.getResponseBuffer(4) << 16;
- vcn = *(float*)&tempdouble;
- Serial.print("van: "); Serial.print(van); Serial.print(", ");
- Serial.print("vbn: "); Serial.print(vbn); Serial.print(", ");
- Serial.print("vcn: "); Serial.print(vcn);
- Serial.println();
- } else {
- Serial.println("failed read");
- }
- old_time = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement