I'm trying to read and write to a PLC via a gateway using modbus4j. I've gotten the read function to work, but I'm not getting anywhere on the setValue() method. I've tried various variations of this:

IpParameters params = new IpParameters();

//create modbus TCP master
ModbusMaster master = new ModbusFactory().createTcpMaster(params, false);

int regValue=0;
regValue = regValue | 1 << 0;
ModbusLocator loc0 = new ModbusLocator(1,RegisterRange.HOLDING_REGISTER,0,DataType.TWO_BYTE_INT_UNSIGNED);

Also the getValue() method only works sporadically maybe 30% of the time I call getValue() I get the response I expect, and the other times I get all 0s out.


Am I misunderstanding some aspect of the get and set value methods? Thanks.