public class AdsSocketChannel extends AbstractDriver implements Initializable
KEY_SOCKETSERVER listening on port
KEY_SOCKETPORT.| Modifier and Type | Class and Description |
|---|---|
static class |
AdsSocketChannel.Close |
(package private) static class |
AdsSocketChannel.Group |
static class |
AdsSocketChannel.Info
Constructs an ADS driver from a properties file, read in the device info
and print out the result.
|
static class |
AdsSocketChannel.Open |
| Modifier and Type | Field and Description |
|---|---|
static Byte |
BFALSE
The byte version for false.
|
static Byte |
BTRUE
The byte version for true.
|
private static boolean |
DEFBLOCKING |
private int |
ID
A session ID.
|
private SocketChannel |
io |
static String |
KEY_BLOCKING |
static String |
KEY_KEEPALIVE |
static String |
KEY_SOCKETPORT |
static String |
KEY_SOCKETSERVER |
static String |
KEY_SOCKETTIMEOUT |
static String |
KEY_SOURCEAMSID |
static String |
KEY_SOURCEPORT |
static String |
KEY_TARGETAMSID |
static String |
KEY_TARGETPORT |
private byte[] |
sourceid |
private byte[] |
targetid |
KEY_DRIVERNAMEKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORCONFIG, KEY_CLASS| Constructor and Description |
|---|
AdsSocketChannel(Map<String,String> props) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
close()
Performs clean-up step when the driver is unloaded.
|
boolean |
deleteHandleForVariable(long handle)
Releases a handle to a variable.
|
boolean |
deleteHandlesForBlock(Collection<Long> handles)
Requests multiple variable handles by using an ADS sum command.
|
boolean |
deleteHandlesForBlock(Map<String,Long> handles)
Requests multiple variable handles by using an ADS sum command.
|
boolean |
ensureConnect()
Establish either a new connection or return immediately if already
connected.
|
private AdsPacket |
execute(AdsCommand cmd) |
Map<String,AdsValue> |
getAllVariables()
Following the sparse documentation, we are able to get a variable name
plus its value skeleton out of the device info of the beckhoff system.
|
DeviceInfoReply |
getDeviceInfo() |
long |
getHandleForVariable(String name)
Returns a handle to a variable name.
|
Map<String,Long> |
getHandlesForBlock(Collection<String> vnames)
Requests multiple variable handles by using an ADS sum command.
|
Number |
getNumericByHandle(long handle,
AdsValue skeleton)
Reads a number from a re-usable handle.
|
Number |
getNumericByName(String name,
AdsValue skeleton)
Queries a variable by name, returning the result as a number.
|
byte[] |
getSourceId()
Returns six bytes parsed out of the
KEY_SOURCEAMSID property. |
int |
getSourcePort()
Only for assemblage of correct header.
|
String |
getStringByHandle(long handle)
Queries a variable by its handle, returning the result as a string.
|
String |
getStringByName(String name)
Queries a variable by name, returning the result as a string.
|
private int |
getSumBytes(Collection<AdsValue> vars) |
byte[] |
getTargetId()
Returns six bytes parsed out of the
KEY_TARGETAMSID property. |
int |
getTargetPort()
Only for assemblage of correct header.
|
Map<String,Number> |
getValuesByHandleBlock(Map<String,Long> handle,
Map<String,AdsValue> type)
We read in numerical values for all handles.
|
Map<String,Number> |
getValuesByNameBlock(Map<String,AdsValue> skel)
Queries a variable by name, returning the result as a number.
|
void |
init() |
boolean |
isOpen()
Queries the initalization status of the driver.
|
private int |
nextID()
Returns the next session ID.
|
boolean |
open()
We open a socket channel to the socket address specified in
KEY_SOCKETSERVER and KEY_SOCKETPORT. |
private static byte[] |
parseAmsId(String ip) |
private List<String> |
prepareSumBuffer(Map<String,Long> handle,
Map<String,AdsValue> type,
ByteBuffer into) |
private void |
printVariableInfo()
Mainly for test purposes.
|
private ReadReply |
readFromHandle(long handle)
Communication cycle to read from a handle.
|
private static String |
readZeroTerminated(ByteBuffer info,
int namelen) |
boolean |
writeNumericToHandle(long handle,
AdsValue skeleton,
Number push) |
boolean |
writeNumericToName(String name,
AdsValue skeleton,
Number push) |
boolean |
writeStringToHandle(long handle,
String push) |
boolean |
writeStringToName(String name,
String push) |
private boolean |
writeToHandle(long handle,
ByteBuffer io) |
boolean |
writeValuesByHandleBlock(Map<String,Long> handle,
Map<String,AdsValue> type,
Map<String,Number> value)
We write numerical values for all handles.
|
createDriver, equals, getDriverName, hashCodeaugment, augment, augment, augment, augment, clone, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, initProperties, isNew, parseObject, parseObject, reload, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringProperties, toStringpublic static final String KEY_TARGETAMSID
public static final String KEY_TARGETPORT
public static final String KEY_SOURCEAMSID
public static final String KEY_SOURCEPORT
public static final String KEY_SOCKETSERVER
public static final String KEY_SOCKETPORT
public static final String KEY_SOCKETTIMEOUT
public static final String KEY_BLOCKING
public static final String KEY_KEEPALIVE
private static final boolean DEFBLOCKING
private byte[] targetid
private byte[] sourceid
private SocketChannel io
private int ID
public static final Byte BFALSE
public static final Byte BTRUE
private int nextID()
public void init()
init in interface Initializablepublic byte[] getTargetId()
KEY_TARGETAMSID property.public int getTargetPort()
public byte[] getSourceId()
KEY_SOURCEAMSID property.public int getSourcePort()
private static byte[] parseAmsId(String ip)
public boolean open()
throws IOException
KEY_SOCKETSERVER and KEY_SOCKETPORT. It is not advised
to state a socket timeout, but if so, the underlying socket to the
channel is manipulated in it SO timeout.open in interface DriverIOExceptionpublic boolean ensureConnect()
throws IOException
SocketChannel.finishConnect() if a connection is pending or by
invoking SocketChannel.connect(SocketAddress) with a socket
address derived from KEY_SOCKETSERVER and
KEY_SOCKETPORT.
This behavior differs from the
SocketChannel.connect(SocketAddress) as it does not throw an
exception, if already connected, but rather returns true. This method is
intended to be called repeatedly without having to worry if a connection
is already established.
IOExceptionSocketChannelpublic boolean isOpen()
Driverpublic boolean close()
throws IOException
Driverclose in interface DriverIOExceptionpublic Map<String,AdsValue> getAllVariables() throws IOException
Types that cannot be used as AdsValue skeletons are ignored.
IOExceptionprivate void printVariableInfo()
throws IOException
IOExceptionprivate static String readZeroTerminated(ByteBuffer info, int namelen)
public DeviceInfoReply getDeviceInfo() throws IOException
IOExceptionpublic String getStringByName(String name) throws IOException
name - IOExceptionpublic String getStringByHandle(long handle) throws IOException
name - IOExceptionpublic Number getNumericByName(String name, AdsValue skeleton) throws IOException
name - skeleton - IOExceptionpublic Number getNumericByHandle(long handle, AdsValue skeleton) throws IOException
handle - skeleton - IOExceptionpublic Map<String,Number> getValuesByNameBlock(Map<String,AdsValue> skel) throws IOException
name - skeleton - IOExceptionprivate ReadReply readFromHandle(long handle) throws IOException
handle - IOExceptionpublic boolean writeNumericToName(String name, AdsValue skeleton, Number push) throws IOException
IOExceptionpublic boolean writeNumericToHandle(long handle,
AdsValue skeleton,
Number push)
throws IOException
handle - skeleton - push - IOExceptionpublic boolean writeStringToName(String name, String push) throws IOException
IOExceptionpublic boolean writeStringToHandle(long handle,
String push)
throws IOException
handle - push - IOExceptionprivate boolean writeToHandle(long handle,
ByteBuffer io)
throws IOException
handle - io - IOExceptionpublic long getHandleForVariable(String name) throws IOException
name - IOExceptionpublic Map<String,Long> getHandlesForBlock(Collection<String> vnames) throws IOException
IOExceptionpublic boolean deleteHandleForVariable(long handle)
throws IOException
handle - IOExceptionpublic boolean deleteHandlesForBlock(Collection<Long> handles) throws IOException
IOExceptionpublic Map<String,Number> getValuesByHandleBlock(Map<String,Long> handle, Map<String,AdsValue> type) throws IOException
IOExceptionpublic boolean writeValuesByHandleBlock(Map<String,Long> handle, Map<String,AdsValue> type, Map<String,Number> value) throws IOException
IOExceptionprivate List<String> prepareSumBuffer(Map<String,Long> handle, Map<String,AdsValue> type, ByteBuffer into)
private int getSumBytes(Collection<AdsValue> vars)
public boolean deleteHandlesForBlock(Map<String,Long> handles) throws IOException
IOExceptionprivate AdsPacket execute(AdsCommand cmd) throws IOException
IOException