• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ModbusUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.wimpi.modbus.util.ModbusUtil的典型用法代码示例。如果您正苦于以下问题:Java ModbusUtil类的具体用法?Java ModbusUtil怎么用?Java ModbusUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ModbusUtil类属于net.wimpi.modbus.util包,在下文中一共展示了ModbusUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: run

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void run() {
  do {
    try {
      //1. pickup the message and corresponding request
      byte[] message = (byte[]) m_SendQueue.take();
      DatagramPacket req = (DatagramPacket)
          m_Requests.remove(new Integer(ModbusUtil.registersToInt(message)));
      //2. create new Package with corresponding address and port
      DatagramPacket res = new DatagramPacket(message,
          message.length,
          req.getAddress(),
          req.getPort());
      m_Socket.send(res);
      logger.trace("Sent package from queue");
    } catch (Exception ex) {
      DEBUG:ex.printStackTrace();
    }
  } while (m_Continue || !m_SendQueue.isEmpty());
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:20,代码来源:UDPSlaveTerminal.java


示例2: write

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Writes a byte encoded as two hexadecimal characters to
 * the raw output stream.
 *
 * @param b the byte to be written as <tt>int</tt>.
 * @throws IOException if an I/O error occurs.
 */
public void write(int b) throws IOException {
  if (b == ModbusASCIITransport.FRAME_START) {
    out.write(58);
    //System.out.println("Wrote FRAME_START");
    return;
  } else if (b == ModbusASCIITransport.FRAME_END) {
    out.write(13);
    out.write(10);
    //System.out.println("Wrote FRAME_END");
    return;
  } else {
    out.write(ModbusUtil.toHex(b));
    //System.out.println("Wrote byte "+b+"="+new String(ModbusUtil.toHex(b)));
  }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:23,代码来源:ASCIIOutputStream.java


示例3: run

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void run() {
  do {
    try {
      //1. pickup the message and corresponding request
      byte[] message = (byte[]) m_SendQueue.take();
      DatagramPacket req = (DatagramPacket)
          m_Requests.remove(new Integer(ModbusUtil.registersToInt(message)));
      //2. create new Package with corresponding address and port
      DatagramPacket res = new DatagramPacket(message,
          message.length,
          req.getAddress(),
          req.getPort());
      m_Socket.send(res);
      if (Modbus.debug) System.out.println("Sent package from queue.");
    } catch (Exception ex) {
      DEBUG:ex.printStackTrace();
    }
  } while (m_Continue || !m_SendQueue.isEmpty());
}
 
开发者ID:dog-gateway,项目名称:jamod-rtu-over-tcp,代码行数:20,代码来源:UDPSlaveTerminal.java


示例4: readEcho

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Reads the own message echo produced in RS485 Echo Mode
 * within the given time frame.
 *
 * @param len is the length of the echo to read.  Timeout will occur if the
 * echo is not received in the time specified in the SerialConnection.
 *
 * @throws IOException if a I/O error occurred.
 */
public void readEcho(int len) throws IOException {

  byte echoBuf[] = new byte[len];
  setReceiveThreshold(len);
  int echoLen = m_CommPort.getInputStream().read(echoBuf, 0, len);
  if (Modbus.debug)
    System.out.println("Echo: " +
                       ModbusUtil.toHex(echoBuf, 0, echoLen));
  m_CommPort.disableReceiveThreshold();
  if (echoLen != len) {
    if (Modbus.debug)
      System.err.println("Error: Transmit echo not received.");
    throw new IOException("Echo not received.");
  }
}
 
开发者ID:dog-gateway,项目名称:jamod-rtu-over-tcp,代码行数:25,代码来源:ModbusSerialTransport.java


示例5: run

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void run() {
	do {
		try {
			// 1. pickup the message and corresponding request
			byte[] message = (byte[]) m_SendQueue.take();
			DatagramPacket req = (DatagramPacket) m_Requests
					.remove(new Integer(ModbusUtil
							.registersToInt(message)));
			// 2. create new Package with corresponding address and port
			DatagramPacket res = new DatagramPacket(message,
					message.length, req.getAddress(), req.getPort());
			m_Socket.send(res);
			if (Modbus.debug)
				System.out.println("Sent package from queue.");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} while (m_Continue || !m_SendQueue.isEmpty());
}
 
开发者ID:jeick,项目名称:jamod,代码行数:20,代码来源:UDPSlaveTerminal.java


示例6: readEcho

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Reads the own message echo produced in RS485 Echo Mode within the given
 * time frame.
 * 
 * @param len
 *            is the length of the echo to read. Timeout will occur if the
 *            echo is not received in the time specified in the
 *            SerialConnection.
 * 
 * @throws IOException
 *             if a I/O error occurred.
 */
public void readEcho(int len) throws IOException {

	byte echoBuf[] = new byte[len];
	try {
		inputStream.blockingRead(echoBuf);
	} catch (IOException e) {
		if (Modbus.debug)
			System.err.println("Error: Transmit echo not received (serial port exception).");
		throw e;
	}
	
	if (Modbus.debug) {
		System.out.println("Echo: " + ModbusUtil.toHex(echoBuf, 0, echoBuf.length));
	}
}
 
开发者ID:jeick,项目名称:jamod,代码行数:28,代码来源:ModbusSerialTransport.java


示例7: write

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Writes a byte encoded as two hexadecimal characters to the raw output
 * stream.
 * 
 * @param b
 *            the byte to be written as <tt>int</tt>.
 * @throws IOException
 *             if an I/O error occurs.
 */
public void write(int b) throws IOException {
	if (b == ModbusASCIITransport.FRAME_START) {
		out.write(58);
		// System.out.println("Wrote FRAME_START");
		return;
	} else if (b == ModbusASCIITransport.FRAME_END) {
		out.write(13);
		out.write(10);
		// System.out.println("Wrote FRAME_END");
		return;
	} else {
		out.write(ModbusUtil.toHex(b));
		// System.out.println("Wrote byte "+b+"="+new
		// String(ModbusUtil.toHex(b)));
	}
}
 
开发者ID:jeick,项目名称:jamod,代码行数:26,代码来源:ASCIIOutputStream.java


示例8: run

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
@Override
public void run() {
    do {
        try {
            // 1. pickup the message and corresponding request
            byte[] message = (byte[]) m_SendQueue.take();
            DatagramPacket req = (DatagramPacket) m_Requests
                    .remove(new Integer(ModbusUtil.registersToInt(message)));
            // 2. create new Package with corresponding address and port
            DatagramPacket res = new DatagramPacket(message, message.length, req.getAddress(), req.getPort());
            m_Socket.send(res);
            logger.trace("Sent package from queue");
        } catch (Exception ex) {
            DEBUG: ex.printStackTrace();
        }
    } while (m_Continue || !m_SendQueue.isEmpty());
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:UDPSlaveTerminal.java


示例9: write

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Writes a byte encoded as two hexadecimal characters to
 * the raw output stream.
 *
 * @param b the byte to be written as <tt>int</tt>.
 * @throws IOException if an I/O error occurs.
 */
@Override
public void write(int b) throws IOException {
    if (b == ModbusASCIITransport.FRAME_START) {
        out.write(58);
        // System.out.println("Wrote FRAME_START");
        return;
    } else if (b == ModbusASCIITransport.FRAME_END) {
        out.write(13);
        out.write(10);
        // System.out.println("Wrote FRAME_END");
        return;
    } else {
        out.write(ModbusUtil.toHex(b));
        // System.out.println("Wrote byte "+b+"="+new String(ModbusUtil.toHex(b)));
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:24,代码来源:ASCIIOutputStream.java


示例10: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg) throws ModbusIOException {
  try {
    int len;
    synchronized (m_ByteOut) {
      // first clear any input from the receive buffer to prepare
      // for the reply since RTU doesn't have message delimiters
      clearInput();
      //write message to byte out
      m_ByteOut.reset();
      msg.setHeadless();
      msg.writeTo(m_ByteOut);
      len = m_ByteOut.size();
      int[] crc = ModbusUtil.calculateCRC(m_ByteOut.getBuffer(), 0, len);
      m_ByteOut.writeByte(crc[0]);
      m_ByteOut.writeByte(crc[1]);
      //write message
      len = m_ByteOut.size();
      byte buf[] = m_ByteOut.getBuffer();
      m_OutputStream.write(buf, 0, len);     //PDU + CRC
      m_OutputStream.flush();
      logger.debug("Sent: {}", ModbusUtil.toHex(buf, 0, len));
      // clears out the echoed message
      // for RS485
      if (m_Echo) {
        readEcho(len);
      }
      lastRequest = new byte[len];
      System.arraycopy(buf, 0, lastRequest, 0, len);
    }

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

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:36,代码来源:ModbusRTUTransport.java


示例11: clearInput

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Clear the input if characters are found in the input stream.
 *
 * @throws IOException
 */
public void clearInput() throws IOException {
  if (m_InputStream.available() > 0) {
    int len = m_InputStream.available();
    byte buf[] = new byte[len];
    m_InputStream.read(buf, 0, len);
    logger.debug("Clear input: {}", ModbusUtil.toHex(buf, 0, len));
  }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:14,代码来源:ModbusRTUTransport.java


示例12: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg)
    throws ModbusIOException {

  try {
    int len;
    synchronized (m_ByteOut) {
      //write message to byte out
      msg.setHeadless();
      msg.writeTo(m_ByteOut);
      byte[] buf = m_ByteOut.getBuffer();
      len = m_ByteOut.size();

      //write message
      m_OutputStream.write(FRAME_START);               //FRAMESTART
      m_OutputStream.write(buf, 0, len);                 //PDU
      int[] crc = ModbusUtil.calculateCRC(buf, 0, len); //CRC
      m_OutputStream.write(crc[0]);
      m_OutputStream.write(crc[1]);
      m_OutputStream.write(FRAME_END);                 //FRAMEEND
      m_OutputStream.flush();
      m_ByteOut.reset();
    }
    // clears out the echoed message
    // for RS485
    if (m_Echo) {
      // read back the echoed message
      readEcho(len + 4);
    }
  } catch (Exception ex) {
    throw new ModbusIOException("I/O failed to write");
  }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:33,代码来源:ModbusBINTransport.java


示例13: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg)
    throws ModbusIOException {

  try {
    synchronized (m_ByteOut) {
      //write message to byte out
      msg.setHeadless();
      msg.writeTo(m_ByteOut);
      byte[] buf = m_ByteOut.getBuffer();
      int len = m_ByteOut.size();

      //write message
      m_OutputStream.write(FRAME_START);               //FRAMESTART
      m_OutputStream.write(buf, 0, len);                 //PDU
      logger.debug("Writing: {}", ModbusUtil.toHex(buf, 0, len));
      m_OutputStream.write(ModbusUtil.calculateLRC(buf, 0, len)); //LRC
      m_OutputStream.write(FRAME_END);                 //FRAMEEND
      m_OutputStream.flush();
      m_ByteOut.reset();
      // clears out the echoed message
      // for RS485
      if (m_Echo) {
        // read back the echoed message
        readEcho(len + 3);
      }
    }
  } catch (Exception ex) {
    throw new ModbusIOException("I/O failed to write" + ex);
  }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:31,代码来源:ModbusASCIITransport.java


示例14: readEcho

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Reads the own message echo produced in RS485 Echo Mode
 * within the given time frame.
 *
 * @param len is the length of the echo to read.  Timeout will occur if the
 * echo is not received in the time specified in the SerialConnection.
 *
 * @throws IOException if a I/O error occurred.
 */
public void readEcho(int len) throws IOException {

  byte echoBuf[] = new byte[len];
  setReceiveThreshold(len);
  int echoLen = m_CommPort.getInputStream().read(echoBuf, 0, len);
  
  logger.debug("Echo: {}", ModbusUtil.toHex(echoBuf, 0, echoLen));
  m_CommPort.disableReceiveThreshold();
  if (echoLen != len) {
    final String errMsg = "Echo not received";
    logger.error("Transmit {}", errMsg);
    throw new IOException(errMsg);
  }
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:24,代码来源:ModbusSerialTransport.java


示例15: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg) throws ModbusIOException {
  try {
    int len;
    synchronized (m_ByteOut) {
      // first clear any input from the receive buffer to prepare
      // for the reply since RTU doesn't have message delimiters
      clearInput();
      //write message to byte out
      m_ByteOut.reset();
      msg.setHeadless();
      msg.writeTo(m_ByteOut);
      len = m_ByteOut.size();
      int[] crc = ModbusUtil.calculateCRC(m_ByteOut.getBuffer(), 0, len);
      m_ByteOut.writeByte(crc[0]);
      m_ByteOut.writeByte(crc[1]);
      //write message
      len = m_ByteOut.size();
      byte buf[] = m_ByteOut.getBuffer();
      m_OutputStream.write(buf, 0, len);     //PDU + CRC
      m_OutputStream.flush();
      if(Modbus.debug) System.out.println("Sent: " + ModbusUtil.toHex(buf, 0, len));
      // clears out the echoed message
      // for RS485
      if (m_Echo) {
        readEcho(len);
      }
      lastRequest = new byte[len];
      System.arraycopy(buf, 0, lastRequest, 0, len);
    }

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

}
 
开发者ID:dog-gateway,项目名称:jamod-rtu-over-tcp,代码行数:36,代码来源:ModbusRTUTransport.java


示例16: clearInput

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Clear the input if characters are found in the input stream.
 *
 * @throws IOException
 */
public void clearInput() throws IOException {
  if (m_InputStream.available() > 0) {
    int len = m_InputStream.available();
    byte buf[] = new byte[len];
    m_InputStream.read(buf, 0, len);
    if(Modbus.debug) System.out.println("Clear input: " +
                ModbusUtil.toHex(buf, 0, len));
  }
}
 
开发者ID:dog-gateway,项目名称:jamod-rtu-over-tcp,代码行数:15,代码来源:ModbusRTUTransport.java


示例17: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg)
    throws ModbusIOException {

  try {
    synchronized (m_ByteOut) {
      //write message to byte out
      msg.setHeadless();
      msg.writeTo(m_ByteOut);
      byte[] buf = m_ByteOut.getBuffer();
      int len = m_ByteOut.size();

      //write message
      m_OutputStream.write(FRAME_START);               //FRAMESTART
      m_OutputStream.write(buf, 0, len);                 //PDU
      if(Modbus.debug)
        System.out.println("Writing: " + ModbusUtil.toHex(buf, 0, len));
      m_OutputStream.write(ModbusUtil.calculateLRC(buf, 0, len)); //LRC
      m_OutputStream.write(FRAME_END);                 //FRAMEEND
      m_OutputStream.flush();
      m_ByteOut.reset();
      // clears out the echoed message
      // for RS485
      if (m_Echo) {
        // read back the echoed message
        readEcho(len + 3);
      }
    }
  } catch (Exception ex) {
    throw new ModbusIOException("I/O failed to write" + ex);
  }
}
 
开发者ID:dog-gateway,项目名称:jamod-rtu-over-tcp,代码行数:32,代码来源:ModbusASCIITransport.java


示例18: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg) throws ModbusIOException {
	try {
		int len;
		synchronized (m_ByteOut) {
			// first clear any input from the receive buffer to prepare
			// for the reply since RTU doesn't have message delimiters
			clearInput();
			// write message to byte out
			m_ByteOut.reset();
			msg.setHeadless();
			msg.writeTo(m_ByteOut);
			len = m_ByteOut.size();
			int[] crc = ModbusUtil.calculateCRC(m_ByteOut.getBuffer(), 0,
					len);
			m_ByteOut.writeByte(crc[0]);
			m_ByteOut.writeByte(crc[1]);
			// write message
			len = m_ByteOut.size();
			byte buf[] = m_ByteOut.getBuffer();
			m_OutputStream.write(buf, 0, len); // PDU + CRC
			m_OutputStream.flush();
			if (Modbus.debug)
				System.out
						.println("Sent: " + ModbusUtil.toHex(buf, 0, len));
			// clears out the echoed message
			// for RS485
			if (m_Echo) {
				readEcho(len);
			}
			lastRequest = new byte[len];
			System.arraycopy(buf, 0, lastRequest, 0, len);
		}

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

}
 
开发者ID:jeick,项目名称:jamod,代码行数:39,代码来源:ModbusRTUTransport.java


示例19: clearInput

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
/**
 * Clear the input if characters are found in the input stream.
 * 
 * @throws IOException
 */
public void clearInput() throws IOException {
	if (m_InputStream.available() > 0) {
		int len = m_InputStream.available();
		byte buf[] = new byte[len];
		m_InputStream.read(buf, 0, len);
		if (Modbus.debug)
			System.out.println("Clear input: "
					+ ModbusUtil.toHex(buf, 0, len));
	}
}
 
开发者ID:jeick,项目名称:jamod,代码行数:16,代码来源:ModbusRTUTransport.java


示例20: writeMessage

import net.wimpi.modbus.util.ModbusUtil; //导入依赖的package包/类
public void writeMessage(ModbusMessage msg) throws ModbusIOException {

		try {
			int len;
			synchronized (m_ByteOut) {
				// write message to byte out
				msg.setHeadless();
				msg.writeTo(m_ByteOut);
				byte[] buf = m_ByteOut.getBuffer();
				len = m_ByteOut.size();

				// write message
				m_OutputStream.write(FRAME_START); // FRAMESTART
				m_OutputStream.write(buf, 0, len); // PDU
				int[] crc = ModbusUtil.calculateCRC(buf, 0, len); // CRC
				m_OutputStream.write(crc[0]);
				m_OutputStream.write(crc[1]);
				m_OutputStream.write(FRAME_END); // FRAMEEND
				m_OutputStream.flush();
				m_ByteOut.reset();
			}
			// clears out the echoed message
			// for RS485
			if (m_Echo) {
				// read back the echoed message
				readEcho(len + 4);
			}
		} catch (Exception ex) {
			throw new ModbusIOException("I/O failed to write");
		}
	}
 
开发者ID:jeick,项目名称:jamod,代码行数:32,代码来源:ModbusBINTransport.java



注:本文中的net.wimpi.modbus.util.ModbusUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SpatialContextFactory类代码示例发布时间:2022-05-22
下一篇:
Java NativeType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap