示例#1
0
 public static FaHDevice DeserializeFromFile(string fileName, bool CreateIfNotExist = false)
 {
     try
     {
         using (TextReader tr = new StreamReader(fileName))
         {
             var json = new JsonSerializer();
             json.Converters.Add(new BytesToHexConverter());
             //var sr = new StringReader(json);
             FaHDevice d = (FaHDevice)json.Deserialize(tr, typeof(FaHDevice));
             if (d.FahClassVersion != 2.0)
             {
                 throw new Exception("Config File version mismatch, expecting 2.0 got " + d.FahClassVersion);
             }
             if (d == null)
             {
                 throw new InvalidDataException();
             }
             return(d);
             //string strDevices = tr.ReadToEnd();
             //return JsonConvert.DeserializeObject<FreeAtHomeDevices>(strDevices);
         }
     }
     catch
     {
         if (CreateIfNotExist)
         {
             return(new FaHDevice());
         }
         else
         {
             throw;
         }
     }
 }
示例#2
0
        /*
         * //Payload
         * ID     0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15      16      17      18      19      20      21      22      23      24      25      26      28
         *      0x03	0x43	0x0E	0x00	0xAB	0xB7	0x00	0xC7	0x7F	0xC1	0xE6	0x58	0x10	0x19	0xC4	0xE4	0x15	0x56	0x05	0xEA	0x10	0x4A	0x10	0x68	0x06	0x0A	0x02	0x63
         * HEX    0x03    0x43	0x06	0x00	0xAB	0xB7	0x00	0xC7	0x30	0xA9	0xFF	0xFF	0x10	0x10	0x55	0xEA	0x08	0x00	0x10	0x80	0x10	0x40	0x10	0x60	0x11	0x40
         * DEC    3       67		6		0		171		183		0		199		48		169		255		255		16		16		85		234		8		0		16		128		16		64		16		96		17		64
         * VAL    APCI    Ap\Data ?	    ?       ADDR	ADDR	ADDR	ADDR    ADDR	ADDR    SYSID   SYSID	TYPE    TYPE    CONIST  CONSIST [CHAN_1.....]   [CHAN_2.....]   [CHAN_3.....]   [CHAN_4.....]   [CHAN_5.....]   [CHAN_6.....]
         */

        public override bool SaveToDevice(ref FreeAtHomeDevices.FaHDevice device, out bool moreIndices)
        {
            moreIndices = false;
            try
            {
                device.ChannelCount = ChannelCount;
                for (int i = 1; i <= ChannelCount; i++)
                {
                    device.WriteChannelIndentifier(i, GetDeviceChannel((uint)i));
                }
                device.DeviceType = faHDeviceType;
                device.FaHAddress = FahDeviceAddress;
                device.SetAddressInformation(this.payloadReference.OwnerOfPayload.SourceAddress, fahSystemID);
                device.ConsistancyValue = ConsistencyValue;
                return(true);
            }
            catch
            {
                return(false);
            }
        }