public static void delPacket(packet_t packetItem) { tRegLocation idx = findPacket(packetItem.GUID); if (idx.pacIdx >= 0) { devices[idx.devIdx].packet.RemoveAt(idx.pacIdx); } }
public static bool LoadDevices(string filename, bool append = false) { string x = Path.GetExtension(filename); if (Path.GetExtension(filename) == ".ini") { /*IniFile ini; * ini = new IniFile(filename); * int devCount = ini.ReadInt("Dev", "Count", 0); * int regsCount = ini.ReadInt("Regs", "Count", 0); * * global.devices = new List<device_t>(); * * for (int i = 0; i < devCount; i++) * { * device_t devItem = new device_t(); * devItem.name = ini.Read("dev" + i.ToString(), "Name", "dev" + i.ToString()); * devItem.baudrate = ini.ReadInt("dev" + i.ToString(), "Baud", 9600); * devItem.bits = ini.ReadInt("dev" + i.ToString(), "Bits", 8); * devItem.parity = ini.Read("dev" + i.ToString(), "Parity", "Even"); * devItem.port = ini.Read("dev" + i.ToString(), "Port", "COM1"); * devItem.stopbits = ini.Read("dev" + i.ToString(), "StopBits", "One"); * devItem.address = ini.ReadByte("dev" + i.ToString(), "Address", 1); * * global.devices.Add(devItem); * } * * for (int i = 0; i < regsCount; i++) * { * reg_t regItem = new reg_t(); * regItem.name = ini.Read("reg" + i.ToString(), "Name", "reg" + i.ToString()); * regItem.type = ini.ReadInt("reg" + i.ToString(), "Type", 0); * regItem.reg = ini.ReadInt("reg" + i.ToString(), "Reg", 0); * regItem.device = ini.Read("reg" + i.ToString(), "Device", ""); * regItem.address = (ushort)ini.ReadInt("reg" + i.ToString(), "Address", 0); * regItem.len = (ushort)ini.ReadInt("reg" + i.ToString(), "Length", 1); * regItem.value = ""; * regItem.GUID = ini.ReadGUID("reg" + i.ToString(), "GUID", Guid.NewGuid()); * global.registers.Add(regItem); * }*/ return(true); } else { DevData data = new DevData(); try { data = (DevData)Files.ImportXml(filename, data); // ----- Clear last values & generate new Guid ----- for (int j = 0; j < data.devices.Count; j++) { if (data.devices[j].packet != null) { for (int k = 0; k < data.devices[j].packet.Count; k++) { packet_t pItem = data.devices[j].packet[k]; pItem.GUID = Guid.NewGuid(); data.devices[j].packet.RemoveAt(k); data.devices[j].packet.Insert(k, pItem); if (data.devices[j].packet[k].regs != null) { for (int i = 0; i < data.devices[j].packet[k].regs.Count; i++) { reg_t item = data.devices[j].packet[k].regs[i]; item.value = ""; item.GUID = Guid.NewGuid(); data.devices[j].packet[k].regs.RemoveAt(i); data.devices[j].packet[k].regs.Insert(i, item); } } } } } }catch (Exception) { return(false); } if (append) { foreach (var devItem in data.devices) { devices.Add(devItem); } } else { devices = data.devices; } RefreshGroupList(); return(true); } }