Examples of ModbusIOException


Examples of net.wimpi.modbusme.ModbusIOException

        }
        //extract length of bytes following in message
        int bf = ModbusUtil.registerToShort(buffer, 4);
        //read rest
        if (m_Input.read(buffer, 6, bf) == -1) {
          throw new ModbusIOException("Premature end of stream (Message truncated).");
        }
        m_ByteIn.reset(buffer, (6 + bf));
        m_ByteIn.skip(7);
        int functionCode = m_ByteIn.readUnsignedByte();
        m_ByteIn.reset();
        req = ModbusRequest.createModbusRequest(functionCode);
        req.readFrom(m_ByteIn);
      }
      return req;
/*
      int transactionID = m_Input.readUnsignedShort();
      int protocolID = m_Input.readUnsignedShort();
      int dataLength = m_Input.readUnsignedShort();
      if (protocolID != Modbus.DEFAULT_PROTOCOL_ID || dataLength > 256) {
        throw new ModbusIOException();
      }
      int unitID = m_Input.readUnsignedByte();
      int functionCode = m_Input.readUnsignedByte();
      ModbusRequest request =
          ModbusRequest.createModbusRequest(functionCode, m_Input, false);
      if (request instanceof IllegalFunctionRequest) {
        //skip rest of bytes
        for (int i = 0; i < dataLength - 2; i++) {
          m_Input.readByte();
        }
      }
      //set read parameters
      request.setTransactionID(transactionID);
      request.setProtocolID(protocolID);
      request.setUnitID(unitID);
      return request;

      */
    } catch (EOFException eoex) {
      throw new ModbusIOException(true);
    } catch (IOException/*SocketException*/ sockex) {
      //connection reset by peer, also EOF
      throw new ModbusIOException(true);
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new ModbusIOException("I/O exception - failed to read.");
    }
  }//readRequest
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

        //use same buffer
        byte[] buffer = m_ByteIn.getBuffer();

        //read to byte length of message
        if (m_Input.read(buffer, 0, 6) == -1) {
          throw new ModbusIOException("Premature end of stream (Header truncated).");
        }
        //extract length of bytes following in message
        int bf = ModbusUtil.registerToShort(buffer, 4);
        //read rest
        if (m_Input.read(buffer, 6, bf) == -1) {
          throw new ModbusIOException("Premature end of stream (Message truncated).");
        }
        m_ByteIn.reset(buffer, (6 + bf));
        m_ByteIn.skip(7);
        int functionCode = m_ByteIn.readUnsignedByte();
        m_ByteIn.reset();
        res = ModbusResponse.createModbusResponse(functionCode);
        res.readFrom(m_ByteIn);
      }
      return res;
      /*
       try {
         int transactionID = m_Input.readUnsignedShort();
         //System.out.println("Read tid="+transactionID);
         int protocolID = m_Input.readUnsignedShort();
         //System.out.println("Read pid="+protocolID);
         int dataLength = m_Input.readUnsignedShort();
         //System.out.println("Read length="+dataLength);
         int unitID = m_Input.readUnsignedByte();
         //System.out.println("Read uid="+unitID);
         int functionCode = m_Input.readUnsignedByte();
         //System.out.println("Read fc="+functionCode);
         ModbusResponse response =
             ModbusResponse.createModbusResponse(functionCode, m_Input, false);
         if (response instanceof ExceptionResponse) {
           //skip rest of bytes
           for (int i = 0; i < dataLength - 2; i++) {
             m_Input.readByte();
           }
         }
         //set read parameters
         response.setTransactionID(transactionID);
         response.setProtocolID(protocolID);
         response.setUnitID(unitID);
         return response;
         */
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new ModbusIOException("I/O exception - failed to read.");
    }
  }//readResponse
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

      if (m_Echo) {
        // read back the echoed message
        readEcho(len + 4);
      }
    } catch (Exception ex) {
      throw new ModbusIOException("I/O failed to write");
    }
  }//writeMessage
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

        done = true;
      } while (!done);
      return request;
    } catch (Exception ex) {
      if(Modbus.debug) System.out.println(ex.getMessage());
      throw new ModbusIOException("I/O exception - failed to read.");
    }

  }//readRequest
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

        done = true;
      } while (!done);
      return response;
    } catch (Exception ex) {
      if(Modbus.debug) System.out.println(ex.getMessage());
      throw new ModbusIOException("I/O exception - failed to read.");
    }
  }//readResponse
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

        m_ByteOut.reset();
        msg.writeTo((DataOutput) m_ByteOut);
        m_Terminal.sendMessage(m_ByteOut.getBuffer());
      }
    } catch (Exception ex) {
      throw new ModbusIOException("I/O exception - failed to write.");
    }
  }//write
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

      request.setUnitID(unitID);
      request.setDataLength(dataLength - 2);
      return request;
      */
    } catch (Exception ex) {
      throw new ModbusIOException("I/O exception - failed to read.");
    }
  }//readRequest
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

      response.setProtocolID(protocolID);
      response.setUnitID(unitID);
      return response;
      */
    } catch (InterruptedIOException ioex) {
      throw new ModbusIOException("Socket timed out.");
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new ModbusIOException("I/O exception - failed to read.");
    }
  }//readResponse
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

    if (!m_Terminal.isActive()) {
      try {
        m_Terminal.activate();
        m_IO = m_Terminal.getModbusTransport();
      } catch (Exception ex) {
        throw new ModbusIOException("Activation failed.");

      }
    }

    //3. Retry transaction m_Retries times, in case of
View Full Code Here

Examples of net.wimpi.modbusme.ModbusIOException

        lastRequest = new byte[len];
        System.arraycopy(buf, 0, lastRequest, 0, len);
      }

    } catch (Exception ex) {
      throw new ModbusIOException("I/O failed to write");
    }

  }//writeMessage
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.