|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.amx.duet.tools.comm.DeviceUtil
The DeviceUtil class wraps up the standard behavior and common functions of a device module. It works in conjuction with the IDeviceListener interface, which is an optional interface but improves the flexibility of this class.
Nested Class Summary | |
class |
DeviceUtil.Property
The Property class was created to allow a method to return a property key/value pair. |
Field Summary | |
static java.lang.String |
BAUD_RATE
String constant used for getting or setting the Baud Rate property of a SerialDevice in conjunction with a NetLinx PROPERTY call. |
static int |
DEBUG
Similar to the Service.DEBUG value. |
static int |
DEFAULT_CONNECT_TIME
The default IP reconnect time in milliseconds. |
static int |
DEFAULT_HEART_TIME
The default heartbeat time in milliseconds. |
static int |
DEFAULT_POLL_TIME
The default polling time in milliseconds. |
static int |
DEFAULT_QUEUE_TIME
The default queing time in milliseconds. |
static int |
DEFAULT_TIMEOUT_COUNT
The default timeout count. |
static java.lang.String |
DEVICE_ID
String constant used for getting or setting the Device ID property of a Device in conjunction with a NetLinx PROPERTY call. |
static int |
ERROR
Similar to the Service.ERROR value. |
static int |
INFO
Similar to the Service.INFO value. |
static java.lang.String |
IP_ADDRESS
String constant used for getting or setting the IP Address property of an IP Device in conjunction with a NetLinx PROPERTY call. |
static int |
IP_ONLY
int constant used to define an IP only device. |
static java.lang.String |
IP_PORT
String constant used for getting or setting the Port property of an IP Device in conjunction with a NetLinx PROPERTY call. |
static int |
IP_SERIAL
int constant used to define an IP/Serial combonation device. |
static int |
MAX_ADJUST
maximum incremental adjust value for modules. |
static int |
MAX_LVL
maximum level range value for modules. |
static int |
MIN_ADJUST
maximum decremental adjust value for modules. |
static int |
MIN_LVL
minimum level range value for modules. |
static java.lang.String |
PASSWORD
String constant used for getting or setting the Password property for a Device in conjunction with a NetLinx PROPERTY call. |
static java.lang.String |
POLL_TIME
String constant used for getting or setting the Poll Time property for a Device in conjunction with a NetLinx PROPERTY call. |
static int |
POLL_TIME_MAX
The maximum polling time in milliseconds. |
static int |
POLL_TIME_MIN
The minimum polling time in milliseconds. |
static java.lang.String |
RECONNECT_TIME
String constant used for getting or setting the IP Reconnect Time property of an IP Device in conjunction with a NetLinx PROPERTY call. |
static int |
RECONNECT_TIME_MAX
The maximum IP reconnect time in milliseconds. |
static int |
RECONNECT_TIME_MIN
The minimum IP reconnect time in milliseconds. |
static int |
SERIAL_ONLY
int constant used to define an IP/Serial combonation device. |
static java.lang.String |
SYSTEM_DIAGNOSTIC
String constant used for getting or setting the System Diagnostic property of a Module for debugging a module with no device, used in conjunction with a NetLinx PROPERTY call. |
static long |
TIME_OUT
5 second HeartBeat Response timer interval |
static java.lang.String |
TIMEOUT_COUNT
String constant used for getting or setting the Timeout count property that allows the device port to go offline, used in conjunction with a NetLinx PROPERTY call. |
static java.lang.String |
USERNAME
String constant used for getting or setting the User Name property for a Device in conjunction with a NetLinx PROPERTY call. |
static int |
WARNING
Similar to the Service.WARNING value. |
Constructor Summary | |
DeviceUtil()
Default constructor. |
|
DeviceUtil(com.amx.duet.devicesdk.base.Module mod)
Deprecated. Constructs the DeviceUtil class. |
|
DeviceUtil(com.amx.duet.devicesdk.base.Module mod,
com.amx.duet.da.NetLinxDevice nd,
java.util.Properties props)
Constructs and initializes the DeviceUtil class. |
Method Summary | |
void |
dispose()
This operation is used as a destructor to release resources. |
java.lang.String |
fnGetBaudRate(java.lang.String sDefaultRate,
java.lang.String[] sValidRates)
Deprecated. make sure getPropertyKey(String) and
validateProperty(String, String) are in your module's overriden
getProperty and setProperty methods respectively.
Retrieve the baud rate from the properties bundle that is part of the
device that is set in setCommonDevice. |
byte |
fnGetDeviceID(java.lang.String sDefaultID,
int nMinID,
int nMaxID)
Deprecated. make sure getPropertyKey(String) and
validateProperty(String, String) are in your module's overriden
getProperty and setProperty methods respectively.
Retrieve the default device ID from the properties bundle that is part of the
device that is set in setCommonDevice.
Note: This device ID is ONLY the device ID indicated in the physical device's protocol,
which may be necessary for correct command formatting. This is NOT the same as the device beacon ID. |
void |
fnSendChannelFeedback(int chanID,
boolean chanValue,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
java.lang.Object device)
Deprecated. |
void |
fnSendLevelFeedback(int levelID,
int levelValue,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
java.lang.Object device)
Deprecated. |
void |
fnSendStringFeedback(java.lang.String msg,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
java.lang.Object device)
Deprecated. |
int |
getAdvancedIndex(com.amx.duet.core.master.netlinx.DPS eventDPS)
Validate and retrieve the port value from an advance Event object. |
com.amx.duet.devicesdk.base.Module |
getCommonDevice()
Returns the currently set device in package common. |
long |
getDeQueueTime()
Returns current amount of time between each queue interval. |
java.lang.String |
getIPAddress(java.lang.String defaultIP)
Deprecated. make sure getPropertyKey(String) and
validateProperty(String, String) are in your module's overriden
getProperty and setProperty methods respectively.
Get the currently stored IP address in properties. If one has not been set yet, store the
default IP address in properties and return it. |
int |
getMaxTimeout()
Returns the maximum number of heartbeat retries before the module disconnects from the physical device. |
com.amx.duet.da.NetLinxDevice |
getNetLinxDevice()
Retrieve the current NetLinxDevice object stored in this class. |
java.lang.String |
getPropertyKey(java.lang.String key)
Gets the correctly formatted property key. |
int |
getTimeoutCount()
Returns the current timeout count value. |
java.lang.String[] |
getValidBaudRates()
Returns all the valid baud rates that the device can accept. |
com.amx.duet.core.master.netlinx.DPS |
getVirtualDPS()
Retrieve the main virtual device DPS value for this module. |
void |
handleAdvancedEvent(com.amx.duet.core.master.netlinx.Event advancedEvent)
Method for handling incoming advanced events. |
void |
handleDataEvent(com.amx.duet.core.master.netlinx.Event evt)
Method for handling incoming data events. |
void |
handleErrorEvent(int error)
Handle the device error event. |
void |
handleOfflineEvent()
Handle the device offline event. |
void |
handleOnlineEvent()
Handle the device online event. |
void |
handleReceive(int bytesReceived,
byte[] data)
|
void |
handleSocketStatus(int status)
|
void |
handleTimelineEvent(com.amx.duet.util.Timeline timeline)
|
void |
handleTimerEvent(com.amx.duet.util.Timer timer)
|
void |
incrementTimeout()
Increments the current timeout count value. |
void |
intitializeConnection()
If this is not an IP connection treat it as if the serial device was trying to come back online. |
void |
ipClose()
Close an IP socket connection. |
boolean |
ipConnect()
Make an IP socket connection. |
boolean |
isConnected()
Determine if an IP connection is closed. |
boolean |
isDataInitialized()
Used to determine if the cached module data has been synchronized with the physical device. |
boolean |
isDeviceOnLine()
Used to determine if physical device is online, not the NetLinx port, such as a serial port. |
boolean |
isDisposing()
Used to determine if this class is currently disposing itself. |
boolean |
isDynamicDevice()
Check to see if the Dynamic Device Property is set. |
boolean |
IsFileNameValid(java.lang.String strFileName)
Checks a fully qualified path name for validity. |
boolean |
isHeartbeating()
Used to determine if the heartbeat timeline has been started. |
boolean |
isInDiagnosticMode()
Returns the module diagnostic state. |
boolean |
isIPControlEnabled()
Used to determine if the DeviceUtil class (Module) is trying to connect to the device via IP sockets. |
int |
isIPControlled()
Checks the module properties to determine if this is an IP controlled device. |
boolean |
isPolling()
Used to determine if the poll timeline has been started. |
boolean |
isQueing()
Used to determine if the queue timeline has been started. |
boolean |
isQueueLocked()
Is the queue flag set to blocked. |
boolean |
isSerialControlled(com.amx.duet.da.NetLinxDevice nd)
Checks the NetLinxDevice passed in to determine if this is a SerialDevice class. |
void |
killHeartbeatTimeline()
Stops the running heartbeat timeline. NOTE: This method should only be called if absolutely necessary, because this is handled internally within this class. |
void |
killQueueTimeline()
Stops the running queue timeline. NOTE: This method should only be called if absolutely necessary, because this is handled internally within this class. |
void |
killResponseTimer()
Kills the running resonse timeout timer. |
void |
lockQueue(boolean bLock)
Block/unblock the queue from sending any more message to the device. |
void |
pauseQueueTimeline()
Pauses the current queue timeline making sure the timeline is not already paused. |
void |
reconnect()
Restart the IP connection timeline. |
void |
refresh()
refresh the client listeners with the module's cached state
of the physical device by callback notifications. |
void |
reinitialize()
During reinitialization volatile member variables are reset to their default values, timers and timelines are stopped, sockets are closed, values are updated from their set properties, and the data initialized state is set to false. |
void |
restartQueueTimeline()
Restarts the currently paused queue timeline making sure the timeline was paused. |
void |
restartTimeline(com.amx.duet.util.Timeline timeline,
long[] alTimes)
Reload and restart an existing timeline with a new set of times. |
void |
sendChannelFeedback(int chanID,
boolean state,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
com.amx.duet.core.master.netlinx.DPS dps)
Sends feedback for the specified channel. |
void |
sendChannelFeedback(int chanID,
boolean state,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
com.amx.duet.da.NetLinxDevice device)
Sends feedback for the specified channel. |
void |
sendCommandFeedback(java.lang.String msg,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
com.amx.duet.core.master.netlinx.DPS dps)
Send string feedback back thru the virtual device to the UI. |
void |
sendCommandFeedback(java.lang.String msg,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
com.amx.duet.da.NetLinxDevice device)
Send string feedback back thru the virtual device to the UI. |
void |
sendLevelFeedback(int levelID,
int levelValue,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
com.amx.duet.core.master.netlinx.DPS dps)
Send level feedback back thru the virtual device to the UI. |
void |
sendLevelFeedback(int levelID,
int levelValue,
com.amx.duet.devicesdk.base.AdvancedEvent advEv,
int zone,
com.amx.duet.da.NetLinxDevice device)
Send level feedback back thru the virtual device to the UI. |
void |
sendString(byte[] msg)
Send a message to the device. |
void |
sendString(java.lang.String msg)
Send a message to the device. |
void |
set9BitMode(boolean on)
|
void |
setBaud(java.lang.String baud)
Set a static baud rate for the device port. |
void |
setBaud(java.lang.String baud,
boolean temporary)
Set a baud rate, which can be reset, for the device port. |
void |
setCharDelay(int time)
|
void |
setCommonDevice(com.amx.duet.devicesdk.base.Module mod)
Sets the device with which functions contained in this package will interact with. |
void |
setCTSEnable(boolean on)
Enable or disable CTS. |
boolean |
setDataInitializedState(boolean state)
Changes the state of bInitialized and triggers the event. |
void |
setDefaultBaudRate(int rate)
Sets the default communications baud rate for the device. |
void |
setDefaultIPAddress(java.lang.String ipAddress)
Sets the default communications IP address for the device. |
void |
setDefaultIPAddress(java.lang.String ipAddress,
int port)
Sets the default communications IP address and port for the device. |
void |
setDeQueueTime(long lTime)
Allows you to change the amount of time between each queue interval. |
void |
setHardwareHandshake(boolean on)
Enable or disable hardware handshaking. |
void |
setMaxTimeout(int count)
Sets the maximum number of heartbeat retries before the module disconnects from the physical device. |
void |
setNetLinxDevice(com.amx.duet.da.NetLinxDevice nd)
Allows the user to add their own NetLinxDevice to this class. |
boolean |
setOnlineState(boolean state)
Changes the state of the bOnline variable and triggers the event. |
void |
setReceiveEnable(boolean on)
|
void |
setSoftwareHandshake(boolean on)
Enable or disable software handshaking. |
void |
setTimeoutCount(int count)
Sets the current timeout count value. |
void |
setValidBaudRates(java.lang.String[] rates)
Set all the valid baud rates that the device can accept. |
void |
startHeartbeatTimeline()
Start the heartbeat timeline if it is not already running. NOTE: This method should only be called if absolutely necessary, because this is handled internally within this class. |
void |
startPolling()
Starts the polling timeline for devices that require polling. |
void |
startQueueTimeline()
Start the queue timeline if it is not already running. NOTE: This method should only be called if absolutely necessary, because this is handled internally within this class. |
void |
startResponseTimer()
Starts the response timeout timer. |
void |
startResponseTimer(long lTimeout)
Starts the response timeout timer with the specified amount of time. |
com.amx.duet.util.Timer |
startTimer(java.lang.String name,
long lTime)
Start a timer with debug messages naming the timer. |
void |
stopPolling()
Stops the polling timeline for devices that require polling. |
com.amx.duet.util.Timer |
stopTimer(com.amx.duet.util.Timer timer,
java.lang.String name)
Stop a timer with debug message naming the timer. |
DeviceUtil.Property |
validateProperty(java.lang.String key,
java.lang.String value)
Validate a property of the Module as a name/value pair. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int POLL_TIME_MIN
public static final int POLL_TIME_MAX
public static final int RECONNECT_TIME_MIN
public static final int RECONNECT_TIME_MAX
public static final int DEFAULT_POLL_TIME
public static final int DEFAULT_CONNECT_TIME
public static final int DEFAULT_QUEUE_TIME
public static final int DEFAULT_HEART_TIME
public static final int DEFAULT_TIMEOUT_COUNT
public static final long TIME_OUT
public static final java.lang.String BAUD_RATE
public static final java.lang.String PASSWORD
public static final java.lang.String USERNAME
public static final java.lang.String POLL_TIME
public static final java.lang.String DEVICE_ID
public static final java.lang.String IP_PORT
public static final java.lang.String IP_ADDRESS
public static final java.lang.String TIMEOUT_COUNT
public static final java.lang.String RECONNECT_TIME
public static final java.lang.String SYSTEM_DIAGNOSTIC
public static final int IP_ONLY
public static final int IP_SERIAL
public static final int SERIAL_ONLY
public static final int MIN_LVL
public static final int MAX_LVL
public static final int MIN_ADJUST
public static final int MAX_ADJUST
public static final int DEBUG
public static final int INFO
public static final int WARNING
public static final int ERROR
Constructor Detail |
public DeviceUtil()
public DeviceUtil(com.amx.duet.devicesdk.base.Module mod)
mod
- The current module (device class) we are working with. Pass in
this as the parameter.public DeviceUtil(com.amx.duet.devicesdk.base.Module mod, com.amx.duet.da.NetLinxDevice nd, java.util.Properties props)
Example usage:
DeviceUtil utilities = null; ... public MakeModel(BundleContext bctxt, NetLinxDevice nd, Properties props) { super(bctxt, nd, props); try { setDebugState(ERROR); utilities = new DeviceUtil(this, nd, props); // Required code for serial port devices utilities.setValidBaudRates(VALID_RATES); utilities.setDefaultBaudRate(NumericUtil.atoi(DEFAULT_RATE)); // Required code for IP connection devices utilities.setDefaultIPAddress(DEFAULT_IP); // TODO: User defined code goes here... } catch (Exception e) { System.out.println("Exception thrown in constructor: " + e.toString()); e.printStackTrace(); } }
mod
- The current module (device class) we are working with. Pass in
this as the parameter.nd
- The NetLinxDevice object passed in from the module constructor.props
- The Properties object passed in from the module constructor.Method Detail |
public void setCommonDevice(com.amx.duet.devicesdk.base.Module mod)
mod
- object of type Modulepublic com.amx.duet.devicesdk.base.Module getCommonDevice()
public boolean isDeviceOnLine()
This is not the same thing as the ONLINE/OFFLINE NetLinx data events.
Example usage:
public boolean isDeviceOnLine() { return utilities.isDeviceOnLine(); }
public boolean isDataInitialized()
Example usage:
public boolean isDataInitialized() { return utilities.isDataInitialized(); }
public void setNetLinxDevice(com.amx.duet.da.NetLinxDevice nd)
nd
- NetLinxDevicepublic com.amx.duet.da.NetLinxDevice getNetLinxDevice()
public void setMaxTimeout(int count)
count
- Maximum number of retriespublic int getMaxTimeout()
public void setTimeoutCount(int count)
Example usage:
// Handle a single response here after parsing it from your buffered // responses. In other words, don't parse the entire buffer in this // method. private void parseResponse(ByteBuffer data) { if (!this.isDeviceOnLine()) utilities.setOnlineState(true); try { // TODO: User defined code goes here... } catch (Exception e) { if (this.getDebugState() == DEBUG) e.printStackTrace(); log(ERROR, "Exception thrown in parseResponse: " + e.toString()); } finally { // Reset outgoing message states here... utilities.killResponseTimer(); utilities.setTimeoutCount(0); utilities.lockQueue(false); } }
count
- Timeout count value.public void incrementTimeout()
public int getTimeoutCount()
public void setValidBaudRates(java.lang.String[] rates)
Example usage:
public MakeModel(BundleContext bctxt, NetLinxDevice nd, Properties props) { super(bctxt, nd, props); try { setDebugState(ERROR); utilities = new DeviceUtil(this, nd, props); // Required code for serial port devices utilities.setValidBaudRates(VALID_RATES); utilities.setDefaultBaudRate(NumericUtil.atoi(DEFAULT_RATE)); } catch (Exception e) { System.out.println("Exception thrown in constructor: " + e.toString()); e.printStackTrace(); } }
rates
- String[] of baud rates.public java.lang.String[] getValidBaudRates()
public void setDefaultBaudRate(int rate)
Example usage:
public MakeModel(BundleContext bctxt, NetLinxDevice nd, Properties props) { super(bctxt, nd, props); try { setDebugState(ERROR); utilities = new DeviceUtil(this, nd, props); // Required code for serial port devices utilities.setValidBaudRates(VALID_RATES); utilities.setDefaultBaudRate(NumericUtil.atoi(DEFAULT_RATE)); } catch (Exception e) { System.out.println("Exception thrown in constructor: " + e.toString()); e.printStackTrace(); } }
rate
- int containing the baud rate.public void setDefaultIPAddress(java.lang.String ipAddress)
Example usage:
public MakeModel(BundleContext bctxt, NetLinxDevice nd, Properties props) { super(bctxt, nd, props); try { setDebugState(ERROR); utilities = new DeviceUtil(this, nd, props); // Required code for IP connection devices utilities.setDefaultIPAddress(DEFAULT_IP); } catch (Exception e) { System.out.println("Exception thrown in constructor: " + e.toString()); e.printStackTrace(); } }
ipAddress
- String containing the IP address.public void setDefaultIPAddress(java.lang.String ipAddress, int port)
Example usage:
public MakeModel(BundleContext bctxt, NetLinxDevice nd, Properties props) { super(bctxt, nd, props); try { setDebugState(ERROR); utilities = new DeviceUtil(this, nd, props); // Required code for IP connection devices utilities.setDefaultIPAddress(DEFAULT_IP, DEFAULT_PORT); } catch (Exception e) { System.out.println("Exception thrown in constructor: " + e.toString()); e.printStackTrace(); } }
ipAddress
- String containing the IP address.port
- int containing the IP port.public boolean isIPControlEnabled()
Example usage:
protected boolean doNetLinxDeviceInitialization() { return (!utilities.isIPControlEnabled()); }
See reinitialize()
for usage as well.
public boolean isDisposing()
public boolean isPolling()
public boolean isHeartbeating()
public boolean isQueing()
public java.lang.String getPropertyKey(java.lang.String key)
Example usage:
public String getProperty(String key) { key = utilities.getPropertyKey(key); return super.getProperty(key); }
key
- String used for matching.
public DeviceUtil.Property validateProperty(java.lang.String key, java.lang.String value)
Example usage:
public void setProperty(String key, String value) { DeviceUtil.Property prop = utilities.validateProperty(key, value); super.setProperty(prop.key, prop.value); }
key
- String to lookup.value
- String to validate and set.
public boolean isInDiagnosticMode()
SYSTEM_DIAGNOSTIC
module property to 1 (0 will turn it off).
public void refresh()
refresh
the client listeners with the module's cached state
of the physical device by callback notifications. This method will not
query the physical device for its current state, but should update the
client with the module's cached device state via callback notifications.
In this case, it will only update the device online and data initialized
states.
Example usage:
public void refresh() { utilities.refresh(); // TODO: User defined code goes here... super.refresh(); }
public void reinitialize()
Example usage:
public void reinitialize() { utilities.reinitialize(); // TODO: User defined code goes here... queue.clearQue(); sbRxMsg.clear(); // incoming message buffer for physical device sbLastMsg.clear(); // Call the base class method super.reinitialize(); // If this is not an IP connection treat it as if the serial device // was trying to come back online. Otherwise, attempt to reconnect // the disconnected socket. if (!utilities.isIPControlEnabled()) handleOnlineEvent(); else utilities.reconnect(); }
public void dispose()
Example usage:
public void dispose() { utilities.dispose(); // TODO: User defined code goes here... // Be sure to dispose all of the components you created that may // have their own threads and listeners going on. super.dispose(); }
public void lockQueue(boolean bLock)
Example usage:
public void deQueue() { try { if (utilities.isQueueLocked() || queue.getQueSize() == 0) return; // stop sending messages and queue them up until we're done if (isDeviceOnLine()) utilities.lockQueue(true); // Remove the command from the queue sbLastMsg.append((byte[])queue.doDeq()); if (sbLastMsg != null && sbLastMsg.length() > 0) { // TODO: User defined code goes here... // Send the command to the device log(DEBUG, "Comm ----------> device: BUFFER '" + sbLastMsg.toHex() + "'"); utilities.sendString(sbLastMsg.toByteArray()); // times out the heart beat message if a response is not received utilities.startResponseTimer(); } // Pause the dequeue timeline if there are no more items if (queue.getQueSize() == 0) utilities.pauseQueueTimeline(); } catch (Exception e) { if (this.getDebugState() == DEBUG) e.printStackTrace(); log(ERROR, "Exception in deQueue: " + e.toString()); } }
See killResponseTimer()
for usage as well.
bLock
- public boolean isQueueLocked()
Example usage:
public void deQueue() { try { if (utilities.isQueueLocked() || queue.getQueSize() == 0) return; // stop sending messages and queue them up until we're done if (isDeviceOnLine()) utilities.lockQueue(true); // Remove the command from the queue sbLastMsg.append((byte[])queue.doDeq()); if (sbLastMsg != null && sbLastMsg.length() > 0) { // TODO: User defined code goes here... // Send the command to the device log(DEBUG, "Comm ----------> device: BUFFER '" + sbLastMsg.toHex() + "'"); utilities.sendString(sbLastMsg.toByteArray()); // times out the heart beat message if a response is not received utilities.startResponseTimer(); } // Pause the dequeue timeline if there are no more items if (queue.getQueSize() == 0) utilities.pauseQueueTimeline(); } catch (Exception e) { if (this.getDebugState() == DEBUG) e.printStackTrace(); log(ERROR, "Exception in deQueue: " + e.toString()); } }
public boolean ipConnect()
public void ipClose()
public boolean isConnected()
public void reconnect()
public void intitializeConnection()
public void handleAdvancedEvent(com.amx.duet.core.master.netlinx.Event advancedEvent)
Example usage:
public void handleAdvancedEvent(Event evt) { utilities.handleAdvancedEvent(evt); }
advancedEvent
- an Event object containing all necessary event information.public void handleDataEvent(com.amx.duet.core.master.netlinx.Event evt)
Example usage:
public void handleDataEvent(Event evt) { utilities.handleDataEvent(evt); }
evt
- an Event object containing all necessary event information.public void handleOnlineEvent()
If the module is using a serial port to communicate with a device then this method will call back to the module so that the module can decide it's own port settings. If the module is connected via an IP socket then the timeline to reconnect the socket will be stopped here. The last thing this method does is start both the queue and heartbeat timelines.
Example usage:
public void handleOnlineEvent() { utilities.handleOnlineEvent(); }
public void handleOfflineEvent()
If the device online state is set to true, then the timeout count will be incremented until it reaches the max count. When it reaches its max it set the device online state to false. This gives the module enough time to try to reastablish communications with the device before (in the case of Device Discovery) completely shutting down. The data initialized state will be set to false as well as any connecting attempts. The last thing this methods does is to call reinitialize in order to clear out any erraneous data and try to reconnect to the device.
Example usage:
public void handleOfflineEvent() { utilities.handleOfflineEvent(); }
public void handleErrorEvent(int error)
This method will log error passed in to the telnet session. It will also close an IP socket if one is available or call the module's handleOfflineEvent() if available.
Example usage:
public void handleErrorEvent(int error) { utilities.handleErrorEvent(error); }
public void handleTimelineEvent(com.amx.duet.util.Timeline timeline)
handleTimelineEvent
in interface com.amx.duet.util.TimelineListener
public void handleTimerEvent(com.amx.duet.util.Timer timer)
handleTimerEvent
in interface com.amx.duet.util.TimerListener
public void handleReceive(int bytesReceived, byte[] data)
handleReceive
in interface SocketConnectionListener
bytesReceived
- data
- public void handleSocketStatus(int status)
handleSocketStatus
in interface SocketConnectionListener
status
- public void killResponseTimer()
Example usage:
// Handle a single response here after parsing it from your buffered // responses. In other words, don't parse the entire buffer in this // method. private void parseResponse(ByteBuffer data) { if (!this.isDeviceOnLine()) utilities.setOnlineState(true); try { // TODO: User defined code goes here... } catch (Exception e) { if (this.getDebugState() == DEBUG) e.printStackTrace(); log(ERROR, "Exception thrown in parseResponse: " + e.toString()); } finally { // Reset outgoing message states here... utilities.killResponseTimer(); utilities.setTimeoutCount(0); utilities.lockQueue(false); } }
public void startResponseTimer()
Example usage:
public void deQueue() { try { if (utilities.isQueueLocked() || queue.getQueSize() == 0) return; // stop sending messages and queue them up until we're done if (isDeviceOnLine()) utilities.lockQueue(true); // Remove the command from the queue sbLastMsg.append((byte[])queue.doDeq()); if (sbLastMsg != null && sbLastMsg.length() > 0) { // TODO: User defined code goes here... // Send the command to the device log(DEBUG, "Comm ----------> device: BUFFER '" + sbLastMsg.toHex() + "'"); utilities.sendString(sbLastMsg.toByteArray()); // times out the heart beat message if a response is not received utilities.startResponseTimer(); } // Pause the dequeue timeline if there are no more items if (queue.getQueSize() == 0) utilities.pauseQueueTimeline(); } catch (Exception e) { if (this.getDebugState() == DEBUG) e.printStackTrace(); log(ERROR, "Exception in deQueue: " + e.toString()); } }
public void startResponseTimer(long lTimeout)
lTimeout
- Amount of time before timer times out.public void setDeQueueTime(long lTime)
lTime
- longpublic long getDeQueueTime()
public void pauseQueueTimeline()
Example usage:
public void deQueue() { try { if (utilities.isQueueLocked() || queue.getQueSize() == 0) return; // stop sending messages and queue them up until we're done if (isDeviceOnLine()) utilities.lockQueue(true); // Remove the command from the queue sbLastMsg.append((byte[])queue.doDeq()); if (sbLastMsg != null && sbLastMsg.length() > 0) { // TODO: User defined code goes here... // Send the command to the device log(DEBUG, "Comm ----------> device: BUFFER '" + sbLastMsg.toHex() + "'"); utilities.sendString(sbLastMsg.toByteArray()); // times out the heart beat message if a response is not received utilities.startResponseTimer(); } // Pause the dequeue timeline if there are no more items if (queue.getQueSize() == 0) utilities.pauseQueueTimeline(); } catch (Exception e) { if (this.getDebugState() == DEBUG) e.printStackTrace(); log(ERROR, "Exception in deQueue: " + e.toString()); } }
public void restartQueueTimeline()
Example usage:
public void enQueue(byte msg[]) { synchronized (queue) { // Restart the dequeue timeline if it was paused utilities.restartQueueTimeline(); queue.doEnq(msg); } }
public void killQueueTimeline()
public void startQueueTimeline()
public void killHeartbeatTimeline()
public void startHeartbeatTimeline()
public void startPolling()
Example usage:
private void parseResponse(ByteBuffer data) ... if (!this.isDataInitialized()) { utilities.setDataInitializedState(true); refresh(); utilities.startPolling(); } ...
public void stopPolling()
public void fnSendStringFeedback(java.lang.String msg, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, java.lang.Object device)
msg
- is the response to return to the UIzone
- is the instantiation to which the response should be sentadvEv
- contains information for Java usersdevice
- is the virtual device to which the response should be sent
Note: device MUST BE A 'NETLINXDEVICE' TYPE OBJECT! 'THIS' WILL NOT WORK!{@link sendCommandFeedback(String, AdvancedEvent, int, NetLinxDevice)}
,
{@link sendCommandFeedback(String, AdvancedEvent, int, DPS)}
Send string feedback back thru the virtual device to the UI.
public void sendCommandFeedback(java.lang.String msg, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, com.amx.duet.da.NetLinxDevice device)
msg
- is the response to return to the UIzone
- is the instantiation to which the response should be sentadvEv
- contains information for Java usersdevice
- is the virtual device to which the response should be sentpublic void sendCommandFeedback(java.lang.String msg, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, com.amx.duet.core.master.netlinx.DPS dps)
msg
- is the response to return to the UIzone
- is the instantiation to which the response should be sentadvEv
- contains information for Java usersdps
- is the virtual device to which the response should be sentpublic void fnSendLevelFeedback(int levelID, int levelValue, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, java.lang.Object device)
levelID
- - level numberlevelValue
- - level valueadvEv
- - contains information for Java userszone
- - the instantiation to which the response should be sentdevice
- - the virtual device to which the response should be sent
Note: device MUST BE A 'NETLINXDEVICE' TYPE OBJECT! 'THIS' WILL NOT WORK!{@link sendLevelFeedback(int, int, AdvancedEvent, int, NetLinxDevice)}
,
{@link sendLevelFeedback(int, int, AdvancedEvent, int, DPS)}
Send level feedback back thru the virtual device to the UI.
public void sendLevelFeedback(int levelID, int levelValue, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, com.amx.duet.da.NetLinxDevice device)
levelID
- level numberlevelValue
- level valueadvEv
- contains information for Java userszone
- the instantiation to which the response should be sentdevice
- is the virtual device to which the response should be sentpublic void sendLevelFeedback(int levelID, int levelValue, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, com.amx.duet.core.master.netlinx.DPS dps)
levelID
- level numberlevelValue
- level valueadvEv
- contains information for Java userszone
- the instantiation to which the response should be sentdps
- is the virtual device to which the response should be sentpublic void fnSendChannelFeedback(int chanID, boolean chanValue, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, java.lang.Object device)
chanID
- - integer, channel numberchanValue
- - boolean, channel stateadvEv
- - AdvancedEvent Objectzone
- - integer, port to return the data ondevice
- - the virtual device to which the response should be sent
Note: device MUST BE A 'NETLINXDEVICE' TYPE OBJECT! 'THIS' WILL NOT WORK!{@link sendChannelFeedback(int, boolean, AdvancedEvent, int, NetLinxDevice)}
,
{@link sendChannelFeedback(int, boolean, AdvancedEvent, int, DPS)}
Sends feedback for the specified channel.
public void sendChannelFeedback(int chanID, boolean state, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, com.amx.duet.da.NetLinxDevice device)
chanID
- integer, channel numberstate
- boolean, channel stateadvEv
- AdvancedEvent Objectzone
- integer, port to return the data ondevice
- the virtual device to which the response should be sentpublic void sendChannelFeedback(int chanID, boolean state, com.amx.duet.devicesdk.base.AdvancedEvent advEv, int zone, com.amx.duet.core.master.netlinx.DPS dps)
chanID
- integer, channel numberstate
- boolean, channel stateadvEv
- AdvancedEvent Objectzone
- integer, port to return the data ondps
- the virtual device to which the response should be sentpublic java.lang.String fnGetBaudRate(java.lang.String sDefaultRate, java.lang.String[] sValidRates)
getPropertyKey(String)
and
validateProperty(String, String)
are in your module's overriden
getProperty and setProperty methods respectively.
Retrieve the baud rate from the properties bundle that is part of the
device that is set in setCommonDevice.
sDefaultRate
- - String containing the device's default baud ratesValidRates
- - an array of Strings containing all valid baud rates for the device
public byte fnGetDeviceID(java.lang.String sDefaultID, int nMinID, int nMaxID)
getPropertyKey(String)
and
validateProperty(String, String)
are in your module's overriden
getProperty and setProperty methods respectively.
Retrieve the default device ID from the properties bundle that is part of the
device that is set in setCommonDevice.
Note: This device ID is ONLY the device ID indicated in the physical device's protocol,
which may be necessary for correct command formatting. This is NOT the same as the device beacon ID.
sDefaultID
- - String containing the device's default IDnMinID
- - integer, represents the smallest valid IDnMaxID
- - integer, represents the largest valid ID
public boolean setOnlineState(boolean state)
state
- is the boolean value to be set
public boolean setDataInitializedState(boolean state)
state
- is the boolean value to be set
public java.lang.String getIPAddress(java.lang.String defaultIP)
getPropertyKey(String)
and
validateProperty(String, String)
are in your module's overriden
getProperty and setProperty methods respectively.
Get the currently stored IP address in properties. If one has not been set yet, store the
default IP address in properties and return it.
defaultIP
- String containing the default IP address
public int isIPControlled() throws java.lang.IllegalArgumentException, java.lang.NullPointerException
java.lang.IllegalArgumentException
- Occurs when the DEVICE_CATEGORY field is empty
java.lang.NullPointerException
- Occurs when the DEVICE_CATEGORY field returns nullpublic boolean isSerialControlled(com.amx.duet.da.NetLinxDevice nd) throws java.lang.NullPointerException
nd
-
java.lang.NullPointerException
- Occurs when the NetLinxDevice parameter is nullpublic boolean isDynamicDevice()
public com.amx.duet.core.master.netlinx.DPS getVirtualDPS()
public int getAdvancedIndex(com.amx.duet.core.master.netlinx.DPS eventDPS)
eventDPS
- Advance Event object's DPS
public boolean IsFileNameValid(java.lang.String strFileName)
strFileName
-
public com.amx.duet.util.Timer startTimer(java.lang.String name, long lTime)
name
- String name of the timer to start.lTime
- Timeout value.
public void restartTimeline(com.amx.duet.util.Timeline timeline, long[] alTimes)
timeline
- Timeline to restart.alTimes
- Times to reload.public com.amx.duet.util.Timer stopTimer(com.amx.duet.util.Timer timer, java.lang.String name)
timer
- The Timer object to stop and destroy.name
- String name of the timer to destroy.
public void setCTSEnable(boolean on)
on
- public void setBaud(java.lang.String baud)
baud
- public void setBaud(java.lang.String baud, boolean temporary)
baud
- temporary
- public void setCharDelay(int time)
time
- public void set9BitMode(boolean on)
on
- public void setReceiveEnable(boolean on)
on
- public void setHardwareHandshake(boolean on)
on
- public void setSoftwareHandshake(boolean on)
on
- public void sendString(java.lang.String msg)
msg
- Message to be sent to the device.public void sendString(byte[] msg)
msg
- Message to be sent to the device.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |