Search in sources :

Example 1 with ModbusRuntimeException

use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.

the class TracerLoadActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    TracerModbusEnvironment tracerModbusEnvironment = actionEnvironment.getInjectEnvironment().get(TracerModbusEnvironment.class);
    TracerWriteTable write = tracerModbusEnvironment.getWrite();
    return Actions.createRunOnce(() -> {
        try {
            write.setLoadControlMode(LoadControlMode.MANUAL_CONTROL);
            write.setManualLoadControlOn(on);
            LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Successfully executed tracer load command. on: " + on);
        } catch (ModbusRuntimeException e) {
            LOGGER.error("Unable to perform tracer write Modbus request", e);
        }
    });
}
Also used : TracerModbusEnvironment(me.retrodaredevil.solarthing.actions.environment.TracerModbusEnvironment) TracerWriteTable(me.retrodaredevil.solarthing.solar.tracer.TracerWriteTable) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException)

Example 2 with ModbusRuntimeException

use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.

the class RoverBoostSetActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    RoverModbusEnvironment environment = actionEnvironment.getInjectEnvironment().get(RoverModbusEnvironment.class);
    RoverWriteTable write = environment.getWrite();
    return Actions.createRunOnce(() -> {
        try {
            if (boostVoltageRaw != null) {
                write.setBoostChargingVoltageRaw(boostVoltageRaw);
            }
            if (boostTimeMinutes != null) {
                write.setBoostChargingTimeMinutes(boostTimeMinutes);
            }
            LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Successfully executed changed boost parameters.");
        } catch (ModbusRuntimeException e) {
            LOGGER.error("Unable to perform Modbus request", e);
        }
    });
}
Also used : RoverModbusEnvironment(me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException) RoverWriteTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)

Example 3 with ModbusRuntimeException

use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.

the class RoverLoadActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    RoverModbusEnvironment environment = actionEnvironment.getInjectEnvironment().get(RoverModbusEnvironment.class);
    RoverWriteTable write = environment.getWrite();
    return Actions.createRunOnce(() -> {
        try {
            write.setLoadWorkingMode(LoadWorkingMode.MANUAL);
            write.setStreetLightStatus(on ? StreetLight.ON : StreetLight.OFF);
            LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Successfully executed load command. on: " + on);
        } catch (ModbusRuntimeException e) {
            LOGGER.error("Unable to perform Modbus request", e);
        }
    });
}
Also used : RoverModbusEnvironment(me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException) RoverWriteTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)

Example 4 with ModbusRuntimeException

use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.

the class ModbusListUpdaterWrapper method receive.

@Override
public void receive(List<Packet> packets) {
    final long startTimeNanos = System.nanoTime();
    try {
        reloadCache.run();
        packetListReceiver.receive(packets);
    } catch (ModbusRuntimeException e) {
        LOGGER.error("Modbus exception", e);
        if (isSendErrorPackets) {
            LOGGER.debug("Sending error packets");
            packets.add(new ImmutableExceptionErrorPacket(e.getClass().getName(), e.getMessage(), MODBUS_RUNTIME_EXCEPTION_CATCH_LOCATION_IDENTIFIER, errorIdentifierString));
        }
        boolean isTimeout = false;
        if (e.getCause() instanceof NotInitializedIOException) {
            isTimeout = true;
        }
        if (e instanceof ModbusTimeoutException) {
            isTimeout = true;
            // These messages will hopefully help people with problems fix it faster.
            if (hasBeenSuccessful) {
                LOGGER.info("\n\nHey! We noticed you got a ModbusTimeoutException after getting this to work.\n" + "This is likely a fluke and hopefully this message isn't printed a bunch of times. If it is not a fluke, you may want to check your cable.\n");
            } else {
                LOGGER.info("\n\nHey! We noticed you got a ModbusTimeoutException.\n" + "This is likely a problem with your cable. SolarThing is communicating fine with your serial adapter, but it cannot reach the device.\n" + "Make sure the cable you have has the correct pinout, and feel free to open an issue at https://github.com/wildmountainfarms/solarthing/issues if you need help.\n");
            }
        } else if (e instanceof ParsedResponseException) {
            ParsedResponseException parsedResponseException = (ParsedResponseException) e;
            ModbusMessage message = parsedResponseException.getResponse();
            String hexFunctionCode = String.format("%02X", message.getFunctionCode());
            LOGGER.info("Communication with rover working well. Got this response back: function code=0x" + hexFunctionCode + " data='" + dataToSplitHex(message.getByteData()) + "' feel free to open issue at https://github.com/wildmountainfarms/solarthing/issues/");
        } else if (e instanceof RawResponseException) {
            byte[] data = ((RawResponseException) e).getRawData();
            LOGGER.info("Got part of a response back. (Maybe timed out halfway through?) data='" + dataToSplitHex(data) + "' Feel free to open an issue at https://github.com/wildmountainfarms/solarthing/issues/");
        }
        if (isTimeout) {
            successReporter.reportTimeout();
        } else {
            successReporter.reportSuccessWithError();
        }
        return;
    }
    hasBeenSuccessful = true;
    successReporter.reportSuccess();
    final long readDurationNanos = System.nanoTime() - startTimeNanos;
    LOGGER.debug("took " + TimeUtil.nanosToSecondsString(readDurationNanos) + " seconds to read from device");
}
Also used : ImmutableExceptionErrorPacket(me.retrodaredevil.solarthing.misc.error.ImmutableExceptionErrorPacket) ParsedResponseException(me.retrodaredevil.io.modbus.handling.ParsedResponseException) ModbusTimeoutException(me.retrodaredevil.io.modbus.ModbusTimeoutException) RawResponseException(me.retrodaredevil.io.modbus.handling.RawResponseException) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException) NotInitializedIOException(me.retrodaredevil.solarthing.io.NotInitializedIOException) ModbusMessage(me.retrodaredevil.io.modbus.ModbusMessage)

Example 5 with ModbusRuntimeException

use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.

the class TracerPacketListUpdater method receive.

@Override
public void receive(List<Packet> packets) {
    TracerStatusPacket packet = TracerStatusPackets.createFromReadTable(number, read);
    packets.add(packet);
    if (tracerClockOptions != null) {
        // Sorry to anyone in the year 2256, that's just too bad for you
        // We make the year 21 represent 2021, because the tracer stores the year using 8 bits
        LocalDateTime currentTime = packet.getSolarThingLocalDateTime();
        final LocalDateTime desiredTime;
        ZoneOffset zoneOffset = tracerClockOptions.getZoneOffset();
        if (zoneOffset != null) {
            desiredTime = Instant.now().atOffset(zoneOffset).toLocalDateTime();
        } else {
            ZoneId zone = tracerClockOptions.getZoneId() != null ? tracerClockOptions.getZoneId() : ZoneId.systemDefault();
            desiredTime = Instant.now().atZone(zone).toLocalDateTime();
        }
        if (Duration.between(currentTime, desiredTime).abs().compareTo(tracerClockOptions.getDurationThreshold()) > 0) {
            LOGGER.info("Going to update time to " + desiredTime + " from " + currentTime);
            write.setSolarThingLocalDateTime(desiredTime);
            LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Success updating time!");
        }
    }
    if (connectionHandler != null) {
        TracerBatteryConfigBuilder builder = new TracerBatteryConfigBuilder(packet);
        connectionHandler.handleRequests(request -> {
            String[] split = StringUtil.terminalSplit(request);
            if (split.length == 1) {
                if ("flushBatteryConfig".equals(split[0])) {
                    try {
                        write.setBatteryConfig(builder);
                    } catch (FunctionCodeException ex) {
                        return ex.getMessage();
                    } catch (ModbusRuntimeException ex) {
                        LOGGER.error("Got modbus exception while flushing", ex);
                        return "Unknown error:" + ex.getMessage();
                    }
                    return "flush success";
                }
            }
            if (connectionHandlerHasFlushLogic && split.length > 1) {
                // check if we're writing something
                String fieldName = split[0];
                String value = split[1];
                // If we can successfully read from this reader, then that means that the input is a field in TracerBatteryConfigBuilder
                // 
                ObjectReader reader = MAPPER.readerForUpdating(builder);
                ObjectNode input = new ObjectNode(JsonNodeFactory.instance);
                input.put(fieldName, value);
                boolean success = true;
                try {
                    reader.readValue(input);
                } catch (IOException e) {
                    success = false;
                }
                if (success) {
                    return "queued up";
                }
            }
            return NetCatUtil.handle(write, packet, request);
        });
    }
}
Also used : FunctionCodeException(me.retrodaredevil.io.modbus.handling.FunctionCodeException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException) IOException(java.io.IOException) TracerStatusPacket(me.retrodaredevil.solarthing.solar.tracer.TracerStatusPacket) TracerBatteryConfigBuilder(me.retrodaredevil.solarthing.solar.tracer.batteryconfig.TracerBatteryConfigBuilder) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Aggregations

ModbusRuntimeException (me.retrodaredevil.io.modbus.ModbusRuntimeException)7 ModbusTimeoutException (me.retrodaredevil.io.modbus.ModbusTimeoutException)2 RoverModbusEnvironment (me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment)2 RoverWriteTable (me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 IOModbusSlaveBus (me.retrodaredevil.io.modbus.IOModbusSlaveBus)1 ModbusMessage (me.retrodaredevil.io.modbus.ModbusMessage)1 ModbusSlaveBus (me.retrodaredevil.io.modbus.ModbusSlaveBus)1 RtuDataEncoder (me.retrodaredevil.io.modbus.RtuDataEncoder)1 FunctionCodeException (me.retrodaredevil.io.modbus.handling.FunctionCodeException)1 ParsedResponseException (me.retrodaredevil.io.modbus.handling.ParsedResponseException)1 RawResponseException (me.retrodaredevil.io.modbus.handling.RawResponseException)1 JSerialIOBundle (me.retrodaredevil.io.serial.JSerialIOBundle)1 TracerModbusEnvironment (me.retrodaredevil.solarthing.actions.environment.TracerModbusEnvironment)1 NotInitializedIOException (me.retrodaredevil.solarthing.io.NotInitializedIOException)1 ImmutableExceptionErrorPacket (me.retrodaredevil.solarthing.misc.error.ImmutableExceptionErrorPacket)1 MutableAddressModbusSlave (me.retrodaredevil.solarthing.program.modbus.MutableAddressModbusSlave)1 BatteryVoltage (me.retrodaredevil.solarthing.solar.common.BatteryVoltage)1