TCP slave with separated memory maps

D

Thread Starter

DaleCooper

Hi everybody

I am making a java tcp slave where i have two memory maps that are gone to be readed/written by other device:

Map1: from 40001 to 40003
Map2: from 45001 to 45100

The problem here is thar I don't know how to make this because my first idea whas making this way:

public ModbusSlave (int port) {

//Next we add the instances and variables the application will need, acquiring the value of the port number from the first commandline parameter if given:

/* The important instances and variables */
ModbusTCPListener listener = null;
SimpleProcessImage spi = null;

//Next we will construct the process image and setup the coupler to hold the reference:

//2. Prepare a process image from 40001 to 40003
spi = new SimpleProcessImage();
spi.addRegister(new SimpleRegister(0));
spi.addRegister(new SimpleRegister(0));
spi.addRegister(new SimpleRegister(0));

//2b. Prepare a process image from 45001 to 45100
spi.setRegister(45001, new SimpleRegister(0));

//3. Set the image on the coupler
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);

//4. Create a listener with 3 threads in pool
listener = new ModbusTCPListener(3);
listener.setPort(port);
listener.start();

}
And Instruction 2b makes me an error (logically) , because this memory direction has not been added to the SimpleProcessImage (is a vector and instruction crashes).

How can i solve the problem? ¿Do i have to add registers from 40003 to 45000?
Tx in advance
 
>//2b. Prepare a process image from 45001 to 45100 spi.setRegister(45001, new SimpleRegister(0))<

Should not 2b be written as 5000, not 45001?
 
Top