99namespace EssentialsPluginTemplate
1010{
1111 /// <summary>
12- /// Plugin device
12+ /// Plugin device template for third party devices that use IBasicCommunication
1313 /// </summary>
1414 /// <remarks>
1515 /// Rename the class to match the device plugin being developed.
1616 /// </remarks>
1717 /// <example>
1818 /// "EssentialsPluginDeviceTemplate" renamed to "SamsungMdcDevice"
1919 /// </example>
20- public class EssentialsPluginDeviceTemplate : EssentialsBridgeableDevice
21- {
22- // TODO [ ] Add, modify, remove properties and fields as needed for the plugin being developed
20+ public class EssentialsPluginTemplateDevice : EssentialsBridgeableDevice
21+ {
22+ /// <summary>
23+ /// It is often desirable to store the config
24+ /// </summary>
25+ private EssentialsPluginConfigObjectTemplate _config ;
26+
27+ #region IBasicCommunication Properties and Constructor. Remove if not needed.
28+
29+ // TODO [ ] Add, modify, remove properties and fields as needed for the plugin being developed
2330 private readonly IBasicCommunication _comms ;
2431 private readonly GenericCommunicationMonitor _commsMonitor ;
2532
2633 // _comms gather for ASCII based API's
2734 // TODO [ ] If not using an ASCII based API, delete the properties below
2835 private readonly CommunicationGather _commsGather ;
36+
37+ /// <summary>
38+ /// Set this value to that of the delimiter used by the API (if applicable)
39+ /// </summary>
2940 private const string CommsDelimiter = "\r " ;
3041
3142 // _comms byte buffer for HEX/byte based API's
3243 // TODO [ ] If not using an HEX/byte based API, delete the properties below
3344 private byte [ ] _commsByteBuffer = { } ;
3445
3546
36- private EssentialsPluginConfigObjectTemplate _config ;
3747
3848 /// <summary>
3949 /// Connects/disconnects the comms of the plugin device
@@ -75,13 +85,13 @@ public bool Connect
7585 public IntFeedback StatusFeedback { get ; private set ; }
7686
7787 /// <summary>
78- /// Plugin device constructor
88+ /// Plugin device constructor for devices that need IBasicCommunication
7989 /// </summary>
8090 /// <param name="key"></param>
8191 /// <param name="name"></param>
8292 /// <param name="config"></param>
8393 /// <param name="comms"></param>
84- public EssentialsPluginDeviceTemplate ( string key , string name , EssentialsPluginConfigObjectTemplate config , IBasicCommunication comms )
94+ public EssentialsPluginTemplateDevice ( string key , string name , EssentialsPluginConfigObjectTemplate config , IBasicCommunication comms )
8595 : base ( key , name )
8696 {
8797 Debug . Console ( 0 , this , "Constructing new {0} instance" , name ) ;
@@ -103,79 +113,28 @@ public EssentialsPluginDeviceTemplate(string key, string name, EssentialsPluginC
103113 // device comms is IP **ELSE** device comms is RS232
104114 socket . ConnectionChange += socket_ConnectionChange ;
105115 Connect = true ;
106- }
107-
108- // _comms gather for ASCII based API's
109- // TODO [ ] If not using an ASCII based API, delete the properties below
110- _commsGather = new CommunicationGather ( _comms , CommsDelimiter ) ;
111- AddPostActivationAction ( ( ) => _commsGather . LineReceived += Handle_LineRecieved ) ;
112-
113- // _comms byte buffer for HEX/byte based API's
114- // TODO [ ] If not using an HEX/byte based API, delete the properties below
115- _comms . BytesReceived += Handle_BytesReceived ;
116- AddPostActivationAction ( ( ) => _comms . BytesReceived += Handle_BytesReceived ) ;
117- }
116+ }
118117
119- #region Overrides of EssentialsBridgeableDevice
118+ #region Communication data event handlers. Comment out any that don't apply to the API type
120119
121- /// <summary>
122- /// Links the plugin device to the EISC bridge
123- /// </summary>
124- /// <param name="trilist"></param>
125- /// <param name="joinStart"></param>
126- /// <param name="joinMapKey"></param>
127- /// <param name="bridge"></param>
128- public override void LinkToApi ( BasicTriList trilist , uint joinStart , string joinMapKey , EiscApiAdvanced bridge )
129- {
130- var joinMap = new EssentialsPluginBridgeJoinMapTemplate ( joinStart ) ;
120+ // Only one of the below handlers should be necessary.
131121
132- // This adds the join map to the collection on the bridge
133- if ( bridge != null )
134- {
135- bridge . AddJoinMap ( Key , joinMap ) ;
136- }
137-
138- var customJoins = JoinMapHelper . TryGetJoinMapAdvancedForDevice ( joinMapKey ) ;
139-
140- if ( customJoins != null )
141- {
142- joinMap . SetCustomJoinData ( customJoins ) ;
143- }
144-
145- Debug . Console ( 1 , "Linking to Trilist '{0}'" , trilist . ID . ToString ( "X" ) ) ;
146- Debug . Console ( 0 , "Linking to Bridge Type {0}" , GetType ( ) . Name ) ;
147-
148- // TODO [ ] Implement bridge links as needed
149-
150- // links to bridge
151- trilist . SetString ( joinMap . DeviceName . JoinNumber , Name ) ;
152-
153- trilist . SetBoolSigAction ( joinMap . Connect . JoinNumber , sig => Connect = sig ) ;
154- ConnectFeedback . LinkInputSig ( trilist . BooleanInput [ joinMap . Connect . JoinNumber ] ) ;
122+ // _comms gather for any API that has a defined delimiter
123+ // TODO [ ] If not using an ASCII based API, remove the line below
124+ _commsGather = new CommunicationGather ( _comms , CommsDelimiter ) ;
125+ _commsGather . LineReceived += Handle_LineRecieved ;
155126
156- StatusFeedback . LinkInputSig ( trilist . UShortInput [ joinMap . Status . JoinNumber ] ) ;
157- OnlineFeedback . LinkInputSig ( trilist . BooleanInput [ joinMap . IsOnline . JoinNumber ] ) ;
127+ // _comms byte buffer for HEX/byte based API's with no delimiter
128+ // TODO [ ] If not using an HEX/byte based API, remove the line below
129+ _comms . BytesReceived += Handle_BytesReceived ;
158130
159- UpdateFeedbacks ( ) ;
131+ // _comms byte buffer for HEX/byte based API's with no delimiter
132+ // TODO [ ] If not using an HEX/byte based API, remove the line below
133+ _comms . TextReceived += Handle_TextReceived ;
160134
161- trilist . OnlineStatusChange += ( o , a ) =>
162- {
163- if ( ! a . DeviceOnLine ) return ;
135+ #endregion
136+ }
164137
165- trilist . SetString ( joinMap . DeviceName . JoinNumber , Name ) ;
166- UpdateFeedbacks ( ) ;
167- } ;
168- }
169-
170- private void UpdateFeedbacks ( )
171- {
172- // TODO [ ] Update as needed for the plugin being developed
173- ConnectFeedback . FireUpdate ( ) ;
174- OnlineFeedback . FireUpdate ( ) ;
175- StatusFeedback . FireUpdate ( ) ;
176- }
177-
178- #endregion
179138
180139 private void socket_ConnectionChange ( object sender , GenericSocketStatusChageEventArgs args )
181140 {
@@ -186,20 +145,28 @@ private void socket_ConnectionChange(object sender, GenericSocketStatusChageEven
186145 StatusFeedback . FireUpdate ( ) ;
187146 }
188147
189- // TODO [ ] If not using an ASCII based API , delete the properties below
148+ // TODO [ ] If not using an API with a delimeter , delete the method below
190149 private void Handle_LineRecieved ( object sender , GenericCommMethodReceiveTextArgs args )
191150 {
192151 // TODO [ ] Implement method
193152 throw new System . NotImplementedException ( ) ;
194153 }
195154
196- // TODO [ ] If not using an HEX/byte based API, delete the properties below
155+ // TODO [ ] If not using an HEX/byte based API with no delimeter, delete the method below
197156 private void Handle_BytesReceived ( object sender , GenericCommMethodReceiveBytesArgs args )
198157 {
199158 // TODO [ ] Implement method
200159 throw new System . NotImplementedException ( ) ;
201160 }
202161
162+ // TODO [ ] If not using an ASCII based API with no delimeter, delete the method below
163+ void Handle_TextReceived ( object sender , GenericCommMethodReceiveTextArgs e )
164+ {
165+ // TODO [ ] Implement method
166+ throw new System . NotImplementedException ( ) ;
167+ }
168+
169+
203170 // TODO [ ] If not using an ACII based API, delete the properties below
204171 /// <summary>
205172 /// Sends text to the device plugin comms
@@ -239,8 +206,74 @@ public void SendBytes(byte[] bytes)
239206 public void Poll ( )
240207 {
241208 // TODO [ ] Update Poll method as needed for the plugin being developed
209+ // Example: SendText("getstatus");
242210 throw new System . NotImplementedException ( ) ;
243- }
244- }
211+ }
212+
213+ #endregion
214+
215+
216+ #region Overrides of EssentialsBridgeableDevice
217+
218+ /// <summary>
219+ /// Links the plugin device to the EISC bridge
220+ /// </summary>
221+ /// <param name="trilist"></param>
222+ /// <param name="joinStart"></param>
223+ /// <param name="joinMapKey"></param>
224+ /// <param name="bridge"></param>
225+ public override void LinkToApi ( BasicTriList trilist , uint joinStart , string joinMapKey , EiscApiAdvanced bridge )
226+ {
227+ var joinMap = new EssentialsPluginBridgeJoinMapTemplate ( joinStart ) ;
228+
229+ // This adds the join map to the collection on the bridge
230+ if ( bridge != null )
231+ {
232+ bridge . AddJoinMap ( Key , joinMap ) ;
233+ }
234+
235+ var customJoins = JoinMapHelper . TryGetJoinMapAdvancedForDevice ( joinMapKey ) ;
236+
237+ if ( customJoins != null )
238+ {
239+ joinMap . SetCustomJoinData ( customJoins ) ;
240+ }
241+
242+ Debug . Console ( 1 , "Linking to Trilist '{0}'" , trilist . ID . ToString ( "X" ) ) ;
243+ Debug . Console ( 0 , "Linking to Bridge Type {0}" , GetType ( ) . Name ) ;
244+
245+ // TODO [ ] Implement bridge links as needed
246+
247+ // links to bridge
248+ trilist . SetString ( joinMap . DeviceName . JoinNumber , Name ) ;
249+
250+ trilist . SetBoolSigAction ( joinMap . Connect . JoinNumber , sig => Connect = sig ) ;
251+ ConnectFeedback . LinkInputSig ( trilist . BooleanInput [ joinMap . Connect . JoinNumber ] ) ;
252+
253+ StatusFeedback . LinkInputSig ( trilist . UShortInput [ joinMap . Status . JoinNumber ] ) ;
254+ OnlineFeedback . LinkInputSig ( trilist . BooleanInput [ joinMap . IsOnline . JoinNumber ] ) ;
255+
256+ UpdateFeedbacks ( ) ;
257+
258+ trilist . OnlineStatusChange += ( o , a ) =>
259+ {
260+ if ( ! a . DeviceOnLine ) return ;
261+
262+ trilist . SetString ( joinMap . DeviceName . JoinNumber , Name ) ;
263+ UpdateFeedbacks ( ) ;
264+ } ;
265+ }
266+
267+ private void UpdateFeedbacks ( )
268+ {
269+ // TODO [ ] Update as needed for the plugin being developed
270+ ConnectFeedback . FireUpdate ( ) ;
271+ OnlineFeedback . FireUpdate ( ) ;
272+ StatusFeedback . FireUpdate ( ) ;
273+ }
274+
275+ #endregion
276+
277+ }
245278}
246279
0 commit comments