IComComponent

From AdvancedHMI
Jump to: navigation, search

IComComponent Interface

AdvancedHMI's controls work by requesting or sending data to a driver. In order for a single control to work with any driver, the driver's must implement a common interface. This interface is defined as the IComComponent. All AdvancedHMI drivers implement the methods and properties defined by this interface.

Properties

DisableSubscriptions - Pauses updating of subscriptions. This is useful in cases such as when hiding a form and there is no longer a need to refresh the values. Or when used with a Trend Chart, it can pause the charting.


Methods

Function Subscribe(ByVal plcAddress As String, ByVal numberOfElements As Int16, ByVal pollRate As Integer, ByVal callback As EventHandler(Of Common.PlcComEventArgs)) As Integer
Subscriptions are used by the majority of the AdvancedHMI controls to receive their data from the PLC. Once a subscription is created, the driver will read the value at a r ate defined by the PollRateOverride property and return it to the subscriber. Most drivers optimize their subscription list in as few reads as possible. For values that need continuous updates, subscriptions will be the most efficient method.

When using this function, it is important to store the SubscriptionID result for unsubscribing when no longer needed.


Function Unsubscribe(ByVal id As Integer) As Integer
Calling this method and passing the SubscriptionID that was return from the subscribe call will remove the item from the subscription list and the driver will stop updating the value.

Function BeginRead(ByVal startAddress As String, ByVal numberOfElements As Integer) As Integer
Function Read(ByVal startAddress As String, ByVal numberOfElements As Integer) As String()
Function BeginWrite(ByVal startAddress As String, ByVal numberOfElements As Integer, ByVal dataToWrite() As String) As Integer
Function Write(ByVal startAddress As String, ByVal dataToWrite As String) As String



,
Pro and Cons of the Different Read Methods
Read (Synchronous reading)
Pro - Minimal code required making it very easy to implement.
Con - It is a blocking operation. If called from the UI thread, the UI will be unresponsive until data is returned from the PLC


BeginRead (Asynchronous reading)
Pro - Non-blocking operation that returns immediately after queueing the request, therefore will not freeze the UI thread
Con - Requires more code to implement. Since requests are queued, it is the developer's responsibility to throttle the rate of calling, otherwise a "send que full" exception can occur if requests are sent too fast

Subscription (Continuous refresh at a rate set by PollRateOverride)
Pro - Simplifies the code needed to receive values at a regular interval. The driver will optimize communications by grouping multiple subscriptions into a single packet when possible.
Con - Code can be complex to implement. A large number of subscriptions can put excessive load on the communication link. It is the developers responsibilty to maintain subscription IDs in order to unsubscribe when finished.