当前位置: 首页>>代码示例>>Java>>正文


Java ModbusFactory类代码示例

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


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

示例1: ModbusConnection

import com.serotonin.modbus4j.ModbusFactory; //导入依赖的package包/类
public ModbusConnection(ModbusLink link, Node node) {
    this.link = link;
    this.node = node;

    modbusFactory = new ModbusFactory();
    this.statnode = node.createChild(NODE_STATUS, true).setValueType(ValueType.STRING)
            .setValue(new Value(NODE_STATUS_SETTINGUP)).build();
    slaves = new HashSet<>();
    node.setAttribute(ATTR_RESTORE_TYPE, new Value("conn"));
    link.connections.add(this);
}
 
开发者ID:IOT-DSA,项目名称:dslink-java-modbus,代码行数:12,代码来源:ModbusConnection.java

示例2: configureSerial

import com.serotonin.modbus4j.ModbusFactory; //导入依赖的package包/类
private static void configureSerial(Config configuration) {
    ModbusFactory factory = new ModbusFactory();
    //SerialParameters params = new SerialParameters();
    String commPortId = configuration.getStringProperty("port", PORT_NAME);
    System.out.println("port name: " + commPortId);
    int baudRate = configuration.getIntProperty("baudrate", PORT_BAUDRATE);
    System.out.println("baudrate: " + baudRate);
    int dataBits = configuration.getIntProperty("data-bits", PORT_DATABITS);
    System.out.println("databits: " + dataBits);
    int parity = configuration.getIntProperty("parity", PORT_PARITY);
    System.out.println("parity: " + parity);
    int stopBits = configuration.getIntProperty("stop-bits", PORT_STOPBITS);
    System.out.println("stopbits: " + stopBits);
    int flowControlIn = configuration.getIntProperty("flow-control-in", PORT_FLOW_CONTROL_IN);
    System.out.println("flowcontrolin: " + flowControlIn);
    int flowControlOut = configuration.getIntProperty("flow-control-out", PORT_FLOW_CONTROL_OUT);
    System.out.println("flowcontrolout: " + flowControlOut);
    SerialPortWrapperImpl params = new SerialPortWrapperImpl(commPortId, baudRate, dataBits, stopBits, parity, flowControlIn,
            flowControlOut);
    //params.setCommPortId(port);
    //params.setBaudRate(baudrate);
    //params.setDataBits(databits);
    //params.setParity(parity);
    //params.setStopBits(stopbits);
    master = factory.createRtuMaster(params);
    connectionInfo = "Serial Connection to: " + commPortId;
}
 
开发者ID:freedomotic,项目名称:freedomotic,代码行数:28,代码来源:ModbusMasterGateway.java

示例3: configureTCP

import com.serotonin.modbus4j.ModbusFactory; //导入依赖的package包/类
private static void configureTCP(Config configuration) {
    ModbusFactory factory = new ModbusFactory();
    IpParameters params = new IpParameters();
    String host = configuration.getStringProperty("host", "localhost");
    System.out.println("host: " + host);
    int tcpport = configuration.getIntProperty("tcp-port", 502);
    System.out.println("tcpport: " + tcpport);
    Boolean encap = configuration.getBooleanProperty("encapsulated", false);
    params.setEncapsulated(encap);
    params.setHost(host);
    params.setPort(tcpport);
    master = factory.createTcpMaster(params, true);
    connectionInfo = "TCP Connection to: " + host + ":" + tcpport;
}
 
开发者ID:freedomotic,项目名称:freedomotic,代码行数:15,代码来源:ModbusMasterGateway.java

示例4: getMaster

import com.serotonin.modbus4j.ModbusFactory; //导入依赖的package包/类
@Override
ModbusMaster getMaster() {
	if (this.master != null) {
		return this.master;
	}

	readSerialAttributes();
	readMasterAttributes();

	SerialPortWrapper wrapper = new SerialPortWrapperImpl(commPortId, baudRate, dataBits, stopBits, parity);
	switch (transType) {
	case RTU:
		master = new ModbusFactory().createRtuMaster(wrapper);
		break;
	case ASCII:
		master = new ModbusFactory().createAsciiMaster(wrapper);
		break;
	default:
		return null;
	}

	master.setTimeout(timeout);
	master.setRetries(retries);
	master.setMaxReadBitCount(maxrbc);
	master.setMaxReadRegisterCount(maxrrc);
	master.setMaxWriteRegisterCount(maxwrc);
	master.setDiscardDataDelay(ddd);
	master.setMultipleWritesOnly(MULTIPLE_WRITE_COMMAND_ALWAYS.equals(mw));

	try {
		master.init();
	} catch (ModbusInitException e) {
		LOGGER.error("error in initializing master : " + e.getMessage());
		LOGGER.debug("error in initializing master : ", e);
		master = null;
		return null;
	}

	link.masters.add(master);
	return master;
}
 
开发者ID:IOT-DSA,项目名称:dslink-java-modbus,代码行数:42,代码来源:SerialConn.java


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