Search in sources :

Example 1 with LifecycleException

use of com.serotonin.util.LifecycleException in project ma-core-public by infiniteautomation.

the class SerialPortManagerImpl method initialize.

/* (non-Javadoc)
     * @see com.infiniteautomation.mango.io.serial.SerialPortManager#initialize(boolean)
     */
@Override
public void initialize(boolean safe) throws LifecycleException {
    if (safe)
        return;
    try {
        String[] portNames;
        Map<String, Boolean> portOwnership = new HashMap<String, Boolean>();
        switch(SerialNativeInterface.getOsType()) {
            case SerialNativeInterface.OS_LINUX:
                portNames = SerialPortList.getPortNames(Common.envProps.getString("serial.port.linux.path", "/dev/"), Pattern.compile(Common.envProps.getString("serial.port.linux.regex", "((cu|ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO|COM)[0-9]{1,3}|rs(232|485)-[0-9])")));
                break;
            case SerialNativeInterface.OS_MAC_OS_X:
                portNames = SerialPortList.getPortNames(Common.envProps.getString("serial.port.osx.path", "/dev/"), Pattern.compile(Common.envProps.getString("serial.port.osx.regex", // Was "tty.(serial|usbserial|usbmodem).*")
                "(cu|tty)..*")));
                break;
            case SerialNativeInterface.OS_WINDOWS:
                portNames = SerialPortList.getPortNames(Common.envProps.getString("serial.port.windows.path", ""), Pattern.compile(Common.envProps.getString("serial.port.windows.regex", "")));
            default:
                portNames = SerialPortList.getPortNames();
                break;
        }
        for (SerialPortIdentifier port : ownedPorts) portOwnership.put(port.getName(), true);
        for (String portName : portNames) {
            if (!portOwnership.containsKey(portName)) {
                freePorts.add(new SerialPortIdentifier(portName, SerialPortTypes.JSSC));
                portOwnership.put(portName, false);
            } else if (LOG.isDebugEnabled())
                LOG.debug("Not adding port " + portName + " to free ports because it is owned.");
        }
        // Collect any Virtual Comm Ports from the DB and load them in
        List<VirtualSerialPortConfig> list = VirtualSerialPortConfigDao.instance.getAll();
        if (list != null) {
            for (VirtualSerialPortConfig config : list) {
                if (!portOwnership.containsKey(config.getPortName())) {
                    freePorts.add(new VirtualSerialPortIdentifier(config));
                    portOwnership.put(config.getPortName(), false);
                } else if (LOG.isWarnEnabled()) {
                    LOG.warn("Virtual serial port config " + config.getXid() + " named " + config.getPortName() + " not available due to name conflict with other serial port or it was open during refresh.");
                }
            }
        }
        initialized = true;
    } catch (UnsatisfiedLinkError e) {
        throw new LifecycleException(e.getMessage());
    } catch (NoClassDefFoundError e) {
        throw new LifecycleException("Comm configuration error. Check that your serial port DLL or libraries have been correctly installed. " + e.getMessage());
    }
}
Also used : LifecycleException(com.serotonin.util.LifecycleException) HashMap(java.util.HashMap) VirtualSerialPortConfig(com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig)

Example 2 with LifecycleException

use of com.serotonin.util.LifecycleException in project ma-core-public by infiniteautomation.

the class CompoundEventDetectorRT method initialize.

// 
// 
// /
// / Lifecycle interface
// /
// 
// 
@Override
public void initialize(boolean safe) throws LifecycleException {
    // Validate the condition statement.
    try {
        condition = parseConditionStatement(vo.getCondition());
    } catch (ConditionParseException e) {
        throw new LifecycleException(e);
    }
    try {
        condition.initialize();
    } catch (LocalizableException e) {
        throw new LifecycleException(e);
    }
    condition.initSource(this);
    // Create a convenience reference to the event type.
    eventType = new CompoundDetectorEventType(vo.getId());
    if (!vo.isReturnToNormal())
        eventType.setDuplicateHandling(EventType.DuplicateHandling.ALLOW);
    // Evaluate the current state.
    currentState = condition.evaluate();
    if (currentState)
        raiseEvent(Common.timer.currentTimeMillis());
    else
        returnToNormal(Common.timer.currentTimeMillis());
}
Also used : LifecycleException(com.serotonin.util.LifecycleException) LocalizableException(com.serotonin.web.i18n.LocalizableException) CompoundDetectorEventType(com.serotonin.m2m2.rt.event.type.CompoundDetectorEventType)

Aggregations

LifecycleException (com.serotonin.util.LifecycleException)2 VirtualSerialPortConfig (com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig)1 CompoundDetectorEventType (com.serotonin.m2m2.rt.event.type.CompoundDetectorEventType)1 LocalizableException (com.serotonin.web.i18n.LocalizableException)1 HashMap (java.util.HashMap)1