diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs
index 45657e3e..83861dc8 100644
--- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs
+++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs
@@ -2,11 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using Crestron.SimplSharp;
-
+using Crestron.SimplSharp.CrestronSockets;
+using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
+using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Config;
@@ -16,7 +17,7 @@ namespace PepperDash.Essentials.Core
///
/// Serves as a generic wrapper class for all styles of IBasicCommuncation ports
///
- public class GenericComm : ReconfigurableDevice
+ public class GenericComm : ReconfigurableBridgableDevice
{
EssentialsControlPropertiesConfig PropertiesConfig;
@@ -43,7 +44,7 @@ namespace PepperDash.Essentials.Core
try
{
PropertiesConfig = JsonConvert.DeserializeObject
- (portConfig.ToString());
+ (portConfig);
}
catch (Exception e)
{
@@ -57,9 +58,59 @@ namespace PepperDash.Essentials.Core
ConfigWriter.UpdateDeviceConfig(config);
}
+
+ public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApi bridge)
+ {
+ var joinMap = new IBasicCommunicationJoinMap();
+
+ var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
+
+ if (!string.IsNullOrEmpty(joinMapSerialized))
+ joinMap = JsonConvert.DeserializeObject(joinMapSerialized);
+ joinMap.OffsetJoinNumbers(joinStart);
+
+ if (CommPort == null)
+ {
+ Debug.Console(1, this, "Unable to link device '{0}'. CommPort is null", Key);
+ return;
+ }
+
+ Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
+
+ // this is a permanent event handler. This cannot be -= from event
+ CommPort.TextReceived += (s, a) =>
+ {
+ Debug.Console(2, this, "RX: {0}", a.Text);
+ trilist.SetString(joinMap.TextReceived, a.Text);
+ };
+ trilist.SetStringSigAction(joinMap.SendText, s => CommPort.SendText(s));
+ trilist.SetStringSigAction(joinMap.SetPortConfig, SetPortConfig);
+
+
+ var sComm = this as ISocketStatus;
+ if (sComm == null) return;
+ sComm.ConnectionChange += (s, a) =>
+ {
+ trilist.SetUshort(joinMap.Status, (ushort)(a.Client.ClientStatus));
+ trilist.SetBool(joinMap.Connected, a.Client.ClientStatus ==
+ SocketStatus.SOCKET_STATUS_CONNECTED);
+ };
+
+ trilist.SetBoolSigAction(joinMap.Connect, b =>
+ {
+ if (b)
+ {
+ sComm.Connect();
+ }
+ else
+ {
+ sComm.Disconnect();
+ }
+ });
+ }
}
- public class GenericCommFactory : Essentials.Core.EssentialsDeviceFactory
+ public class GenericCommFactory : EssentialsDeviceFactory
{
public GenericCommFactory()
{