/// <summary> /// load all devices in data folder /// </summary> /// <returns></returns> public bool Load() { try { DeviceConfig config = new DeviceConfig(); config.Load("Temp.xml"); config.Commands = new DeviceCommandsGroup(); config.Commands.Name = "Init"; config.Commands.Description = "Initial device"; config.Commands.Commands = new DeviceCommand[1]; DeviceCommand cmd = new DeviceCommand(); config.Commands.Commands[0] = cmd; config.Commands.Commands[0].Name = "test"; config.Commands.Commands[0].Description = "test des"; cmd.Data = new byte[] { 22, 33 }; cmd.ReadDataLength = 2; config.Save("test.xml"); //DeviceConfig.SaveAsTemp(); } catch (Exception e) { Debug.Print("Fail to load configure file."); } return false; }
/// <summary> /// fill device's properties /// </summary> /// <param name="dev"></param> private void FillProperties(DeviceConfig dev) { lbManufactory.Text = string.Format("Manufactory: {0} ", dev.Manufactory); lbType.Text = string.Format("Device Type: {0} ", dev.Type); StringBuilder sb = new StringBuilder(); for (int i = 0; i < dev.AddressCollection.Length; i++) { sb.AppendFormat("{0} (0x{0:X2}) ", dev.AddressCollection[i]); } lbAddress.Text = string.Format("Address Collection: {0} ", sb.ToString()); lbGeneralCall.Text = dev.GeneralCall ? "Support General Call" : "Do NOT support General Call"; lbGeneralCall.ForeColor = dev.GeneralCall ? Color.Black : Color.Red; }
/// <summary> /// Fill Commands tree with /// </summary> private void FillCommandsTree(DeviceConfig dev) { tvCommands.Nodes.Clear(); DeviceCommandsGroup cmds = dev.Commands; if (cmds.Commands != null) { foreach (DeviceCommandBase cmd in cmds.Commands) { TreeNode node = FillCommandsTreeSubNode(cmd); tvCommands.Nodes.Add(node); } } ctlI2CAddress1.Addr7 = dev.Address; }
/// <summary> /// search and load devices configure /// </summary> public void LoadAllDevices() { ArrayList devices = new ArrayList(); if (Directory.Exists(DataPath)) { var files = Directory.EnumerateFiles(DataPath, "*.xml"); foreach (var d in files) { Debug.Print(d.ToString()); DeviceConfig dev = new DeviceConfig(); dev.Load(d.ToString()); devices.Add(dev); } } Devices = (DeviceConfig[])devices.ToArray(typeof(DeviceConfig)); }
public bool Load(string filename) { try { XmlReader reader = XmlReader.Create(filename); XmlSerializer serializer = new XmlSerializer(typeof(DeviceConfig)); DeviceConfig temp = (DeviceConfig)serializer.Deserialize(reader); Type = temp.Type; path = filename; Name = temp.Name; Manufactory = temp.Manufactory; GeneralCall = temp.GeneralCall; Address = temp.Address; AddressCollection = temp.AddressCollection; Commands = temp.Commands; reader.Close(); } catch (Exception e) { Debug.Print("Fail to load configure file."); } return(false); }
static public void SaveAsTemp(string filename) { DeviceConfig config = new DeviceConfig(); config.Name = "DemoI2C"; config.path = filename; config.Type = "AD"; config.Manufactory = "HoneyWell"; config.Address = 22; config.AddressCollection = new byte[] { 22, 33 }; config.Commands = new DeviceCommandsGroup(); config.Save(filename); }