Пример #1
0
        public static void delReg(reg_t regItem)
        {
            tRegLocation idx = findReg(regItem.GUID);

            if (idx.regIdx >= 0)
            {
                devices[idx.devIdx].packet[idx.pacIdx].regs.RemoveAt(idx.regIdx);
            }
        }
Пример #2
0
 public static bool IsArrayType(reg_t reg)
 {
     if (reg.dataType == eDataType.ShortArray ||
         reg.dataType == eDataType.UShortArray ||
         reg.dataType == eDataType.IntArray ||
         reg.dataType == eDataType.UIntArray ||
         reg.dataType == eDataType.FloatArray ||
         reg.dataType == eDataType.DoubleArray)
     {
         return(true);
     }
     return(false);
 }
Пример #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!sending)
            {
                sending = true;
                try
                {
                    List <packet_t> selectPackets = new List <packet_t>();
                    int             regI          = 0;
                    for (int i = 0; i < lvChart.Items.Count; i++)
                    {
                        while ((regI < regList.Count) && !regList[regI].showChart)
                        {
                            regI++;
                        }
                        if (lvChart.Items[i].Checked)
                        {
                            reg_t        regItem = regList[regI];
                            tRegLocation loc     = global.findReg(regItem.GUID);

                            bool isHere = false;
                            for (int j = 0; j < selectPackets.Count; j++)
                            {
                                if (selectPackets[j].GUID == global.devices[loc.devIdx].packet[loc.pacIdx].GUID)
                                {
                                    isHere = true;
                                    break;
                                }
                            }
                            if (!isHere)
                            {
                                selectPackets.Add(global.devices[loc.devIdx].packet[loc.pacIdx]);
                            }
                        }
                        regI++;
                    }

                    bool procOK = true;
                    foreach (packet_t item in selectPackets)
                    {
                        procOK = MB.GetPacketValue(item);
                        if (!procOK)
                        {
                            break;
                        }
                    }

                    showValues();

                    regI = 0;
                    for (int i = 0; i < lvChart.Items.Count; i++)
                    {
                        while ((regI < regList.Count) && !regList[regI].showChart)
                        {
                            regI++;
                        }
                        if (lvChart.Items[i].Checked)
                        {
                            if (procOK)
                            {
                                reg_t regItem = regList[regI];
                                lvChart.Items[i].SubItems[1].Text = regItem.value;
                                addChart(i, regItem.value);
                            }
                        }
                        regI++;
                    }
                }
                catch (Exception err)
                {
                    timer1.Enabled = false;
                    MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                sending = false;
            }
        }
Пример #4
0
        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);
            }
        }