Пример #1
0
        public static tRegLocation findReg(Guid GUID)
        {
            tRegLocation res = new tRegLocation();

            res.devIdx = -1;
            res.pacIdx = -1;
            res.regIdx = -1;

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].packet != null)
                {
                    for (int j = 0; j < devices[i].packet.Count; j++)
                    {
                        if (devices[i].packet[j].regs != null)
                        {
                            for (int k = 0; k < devices[i].packet[j].regs.Count; k++)
                            {
                                if (devices[i].packet[j].regs[k].GUID == GUID)
                                {
                                    res.devIdx = i;
                                    res.pacIdx = j;
                                    res.regIdx = k;
                                    return(res);
                                }
                            }
                        }
                    }
                }
            }
            return(res);
        }
Пример #2
0
        public static tRegLocation findPacket(int index)
        {
            tRegLocation res = new tRegLocation();

            res.devIdx = -1;
            res.pacIdx = -1;
            res.regIdx = -1;

            int pos = -1;

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].packet != null)
                {
                    for (int j = 0; j < devices[i].packet.Count; j++)
                    {
                        pos++;
                        if (index == pos)
                        {
                            res.devIdx = i;
                            res.pacIdx = j;
                            return(res);
                        }
                    }
                }
            }
            return(res);
        }
Пример #3
0
        public static tRegLocation findPacket(string name)
        {
            tRegLocation res = new tRegLocation();

            res.devIdx = -1;
            res.pacIdx = -1;
            res.regIdx = -1;

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].packet != null)
                {
                    for (int j = 0; j < devices[i].packet.Count; j++)
                    {
                        if (devices[i].packet[j].name == name)
                        {
                            res.devIdx = i;
                            res.pacIdx = j;
                            return(res);
                        }
                    }
                }
            }
            return(res);
        }
Пример #4
0
        public static void delPacket(packet_t packetItem)
        {
            tRegLocation idx = findPacket(packetItem.GUID);

            if (idx.pacIdx >= 0)
            {
                devices[idx.devIdx].packet.RemoveAt(idx.pacIdx);
            }
        }
Пример #5
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);
            }
        }
Пример #6
0
        private void mnuPacDuplicate_Click(object sender, EventArgs e)
        {
            global.devItem.edit = false;
            tRegLocation index = global.findPacket(((packet_t)olvPacket.SelectedItem.RowObject).GUID);

            global.devItem.devIdx    = index.devIdx;
            global.devItem.packetIdx = index.pacIdx;
            global.devItem.regIdx    = index.regIdx;

            formPacket = new frmPacket();
            if (formPacket.ShowDialog() == DialogResult.OK)
            {
                showDev();
            }
        }
Пример #7
0
        private void cbPacket_SelectedIndexChanged(object sender, EventArgs e)
        {
            tRegLocation index = global.findPacket(cbPacket.SelectedIndex);

            if (global.devices[index.devIdx].packet[index.pacIdx].type == eMBRegType.Coil || global.devices[index.devIdx].packet[index.pacIdx].type == eMBRegType.DiscreteInput)
            {
                cbType.Visible  = false;
                lblType.Visible = false;
                txtLen.Visible  = true;
                lblLen.Visible  = true;
            }
            else
            {
                cbType.Visible  = true;
                lblType.Visible = true;
                cbType_SelectedIndexChanged(null, null);
            }
        }
Пример #8
0
        private void mnuRegCopy_Click(object sender, EventArgs e)
        {
            try
            {
                global.devItem.edit = false;
                tRegLocation index = global.findReg(((reg_t)olvRegisters.SelectedItem.RowObject).GUID);
                global.devItem.devIdx    = index.devIdx;
                global.devItem.packetIdx = index.pacIdx;
                global.devItem.regIdx    = index.regIdx;

                formReg = new frmReg();
                if (formReg.ShowDialog() == DialogResult.OK)
                {
                    showDev();
                }
            }
            catch (Exception) { }
        }
Пример #9
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            reg_t regItem;

            regItem.name     = txtName.Text;
            regItem.dataType = (eDataType)cbType.SelectedIndex;
            regItem.address  = (ushort)Conv.ToShortDef(txtAddress.Text, 0);
            if (functions.IsInteger(txtLen.Text))
            {
                regItem.len = Convert.ToUInt16(txtLen.Text);
            }
            else
            {
                regItem.len = 1;
            }
            regItem.value     = "";
            regItem.group     = txtGroup.Text;
            regItem.showChart = chbShowChart.Checked;
            regItem.GUID      = GUID;

            tRegLocation index = global.findPacket(cbPacket.SelectedIndex);

            //if (index.devIdx >= 0) regItem.group = global.devices[index.devIdx].packet[index.pacIdx].name;


            if (global.devItem.edit)
            {
                if (global.devItem.devIdx == index.devIdx && global.devItem.packetIdx == index.pacIdx)
                {
                    eMBRegType pType = global.devices[global.devItem.devIdx].packet[global.devItem.packetIdx].type;
                    if (pType == eMBRegType.Coil || pType == eMBRegType.HoldingRegister)
                    {
                        regItem.RW = true;
                    }
                    else
                    {
                        regItem.RW = false;
                    }

                    global.devices[global.devItem.devIdx].packet[global.devItem.packetIdx].regs.RemoveAt(global.devItem.regIdx);
                    global.devices[global.devItem.devIdx].packet[global.devItem.packetIdx].regs.Insert(global.devItem.regIdx, regItem);
                }
                else
                {
                    if (index.devIdx < 0 || index.pacIdx < 0)
                    {
                        Dialogs.ShowErr("Selected device not exist!", "");
                        return;
                    }
                    else
                    {
                        eMBRegType pType = global.devices[index.devIdx].packet[index.pacIdx].type;
                        if (pType == eMBRegType.Coil || pType == eMBRegType.HoldingRegister)
                        {
                            regItem.RW = true;
                        }
                        else
                        {
                            regItem.RW = false;
                        }
                        global.devices[global.devItem.devIdx].packet[global.devItem.packetIdx].regs.RemoveAt(global.devItem.regIdx);
                        global.devices[index.devIdx].packet[index.pacIdx].regs.Add(regItem);
                    }
                }
            }
            else
            {
                if (index.devIdx < 0 || index.pacIdx < 0)
                {
                    Dialogs.ShowErr("Selected packet not exist!", "");
                    return;
                }
                else
                {
                    eMBRegType pType = global.devices[index.devIdx].packet[index.pacIdx].type;
                    if (pType == eMBRegType.Coil || pType == eMBRegType.HoldingRegister)
                    {
                        regItem.RW = true;
                    }
                    else
                    {
                        regItem.RW = false;
                    }
                    global.devices[index.devIdx].packet[index.pacIdx].regs.Add(regItem);
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #10
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;
            }
        }