Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发送读写保持寄存器时会出现 Connection reset by peer: socket write error 。再次发送却成功了 #54

Open
hxc-mkp opened this issue Sep 19, 2022 · 1 comment

Comments

@hxc-mkp
Copy link

hxc-mkp commented Sep 19, 2022

public static ModbusFactory modbusFactory = new ModbusFactory();

/**
 * 获取tcpMaster
 */
public static ModbusMaster getMaster() throws Exception {
    IpParameters params = new IpParameters();
    params.setHost("192.168.100.66");
    params.setPort(502);
    params.setEncapsulated(false);

    ModbusMaster tcpMaster = modbusFactory.createTcpMaster(params, false);
    tcpMaster.setTimeout(500);
    tcpMaster.setRetries(3);
    tcpMaster.init();
    return tcpMaster;
}

public static void readHoldingRegister(int slaveId, int offset, int dataType) throws Exception {
BaseLocator locator = BaseLocator.holdingRegister(slaveId, offset, dataType);
Number value = getMaster().getValue(locator);
System.out.println("HoldingRegister寄存器第" + offset + "位数据为:" + value);
}

@jdzhang1221
Copy link

怎么解决的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants