Search in sources :

Example 1 with SerialPortException

use of com.infiniteautomation.mango.io.serial.SerialPortException in project ma-core-public by infiniteautomation.

the class SerialServerSocketBridge method closeImpl.

@Override
public void closeImpl() throws SerialPortException {
    if (this.serverThread != null) {
        this.serverThread.shutdown();
        Exception ex = null;
        try {
            // unblock the accept() method
            this.serverSocket.close();
        } catch (IOException e) {
            ex = e;
            LOG.error(e.getMessage(), e);
        }
        if (this.socket != null) {
            try {
                // unblock the read() method
                this.socket.close();
            } catch (IOException e) {
                ex = e;
                LOG.error(e.getMessage(), e);
            } finally {
                this.socket = null;
            }
        }
        if (ex != null)
            throw new SerialPortException(ex);
    }
}
Also used : SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) IOException(java.io.IOException) IOException(java.io.IOException) SocketException(java.net.SocketException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException)

Example 2 with SerialPortException

use of com.infiniteautomation.mango.io.serial.SerialPortException in project ma-core-public by infiniteautomation.

the class SerialServerSocketBridge method openImpl.

@Override
public void openImpl() throws SerialPortException {
    try {
        if (this.serverThread != null)
            throw new SerialPortException("Already Open.");
        this.serverSocket = new ServerSocket(this.port);
        this.serverSocket.setSoTimeout(0);
        this.serverThread = new SerialServerSocketThread(this);
        this.serverThread.start();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new SerialPortException(e);
    }
}
Also used : SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) SocketException(java.net.SocketException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException)

Example 3 with SerialPortException

use of com.infiniteautomation.mango.io.serial.SerialPortException in project ma-modules-public by infiniteautomation.

the class MangoMBusSerialConnection method open.

@Override
public void open() throws IOException {
    try {
        setConnState(State.OPENING);
        this.serialPort = Common.serialPortManager.open(ownerName, commPortId, baudRate, SerialPort.FLOWCONTROL_NONE, SerialPort.FLOWCONTROL_NONE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_EVEN);
        this.is = this.serialPort.getInputStream();
        this.os = this.serialPort.getOutputStream();
        setConnState(State.OPEN);
    } catch (SerialPortException e) {
        close();
        throw new IOException(e);
    }
}
Also used : SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) IOException(java.io.IOException)

Example 4 with SerialPortException

use of com.infiniteautomation.mango.io.serial.SerialPortException in project ma-modules-public by infiniteautomation.

the class SerialDataSourceRT method terminate.

@Override
public void terminate() {
    super.terminate();
    if (this.port != null)
        try {
            Common.serialPortManager.close(this.port);
        } catch (SerialPortException e) {
            LOG.debug("Error while closing serial port", e);
            raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.portError", this.port.getCommPortId(), e.getLocalizedMessage()));
        }
    if (this.vo.isLogIO()) {
        this.ioLog.log("Data source stopped");
        this.ioLog.close();
    }
}
Also used : SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 5 with SerialPortException

use of com.infiniteautomation.mango.io.serial.SerialPortException in project ma-core-public by infiniteautomation.

the class SerialSocketBridge method openImpl.

@Override
public void openImpl() throws SerialPortException {
    try {
        this.socket = new Socket(this.address, this.port);
        this.socket.setSoTimeout(timeout);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new SerialPortException(e);
    }
}
Also used : SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException) Socket(java.net.Socket) IOException(java.io.IOException) SerialPortException(com.infiniteautomation.mango.io.serial.SerialPortException)

Aggregations

SerialPortException (com.infiniteautomation.mango.io.serial.SerialPortException)5 IOException (java.io.IOException)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 SocketException (java.net.SocketException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1