io.stepfunc.rodbus.DeviceMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rodbus Show documentation
Show all versions of rodbus Show documentation
Safe and fast Modbus library
// This library is provided under the terms of a non-commercial license.
//
// Please refer to the source repository for details:
//
// https://github.com/stepfunc/rodbus/blob/master/LICENSE.txt
//
// Please contact Step Function I/O if you are interested in commercial license:
//
// [email protected]
package io.stepfunc.rodbus;
import org.joou.*;
/**
* Maps endpoint handlers to Modbus address
*/
public final class DeviceMap
{
final private long self;
private java.util.concurrent.atomic.AtomicBoolean disposed = new java.util.concurrent.atomic.AtomicBoolean(false);
private DeviceMap(long self)
{
this.self = self;
}
/**
* Create a device map that will be used to bind devices to a server endpoint
*
*/
public DeviceMap()
{
DeviceMap object = NativeFunctions.device_map_new();
this.self = object.self;
object.disposed.set(true);
}
private void close()
{
if (this.disposed.getAndSet(true))
return;
NativeFunctions.device_map_destroy(this);
}
@Override
public void finalize()
{
this.close();
}
/**
* add an endpoint to the map
*
* @param unitId Unit id of the endpoint
* @param handler callback interface for handling write operations for this device
* @param configure one-time callback interface configuring the initial state of the database
* @return True if the unit id doesn't already exists, false otherwise
*/
public boolean addEndpoint(UByte unitId, WriteHandler handler, DatabaseCallback configure)
{
return NativeFunctions.map_add_endpoint(this, unitId, handler, configure);
}
}