Ejemplo n.º 1
0
        // Update the printer with the value of an Extra control
        private void SetExtras_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            // Tag contains control number and attribute
            byte      n    = ((byte[])b.Tag)[0];
            ClassCode cc   = (ClassCode)((byte[])b.Tag)[1];
            byte      at   = ((byte[])b.Tag)[2];
            AttrData  attr = EIP.AttrDict[cc, at];

            // Only decimal values are allowed.  Set to Min if in error
            int len = attr.Set.Len;

            if (!int.TryParse(ExtraText[n].Text, out int val))
            {
                val = (int)attr.Set.Min;
            }

            // Write the value to the printer
            byte[] data = EIP.FormatOutput(attr.Set, val);
            if (EIP.SetAttribute(cc, attr.Val, data))
            {
                // It worked, set normal on the control and update the full display
                ExtraText[n].BackColor = Color.LightGreen;
                GetAll_Click(null, null);
            }
            SetButtonEnables();
        }
Ejemplo n.º 2
0
        private bool RefreshOneExtra(int i)
        {
            bool     reloadTab = false;
            int      at        = ((byte[])ExtraGet[i].Tag)[2];
            int      n         = EIP.GetIndexSetting((ccIDX)at);
            string   s         = n.ToString();
            AttrData attr      = EIP.GetAttrData((ccIDX)at);

            if (ExtraText[i].Text != s)
            {
                ExtraText[i].Text = s;
                reloadTab         = true;
            }
            ExtraText[i].Visible = true;
            if (attr.Data.DropDown != fmtDD.None)
            {
                n -= (int)attr.Data.Min;
                if (n >= 0 && n < ExtraDropdowns[i].Items.Count)
                {
                    ExtraDropdowns[i].SelectedIndex = n;
                    ExtraText[i].Visible            = false;
                    ExtraDropdowns[i].Visible       = true;
                    ExtraDropdowns[i].BackColor     = Color.LightGreen;
                }
                else
                {
                    ExtraDropdowns[i].Visible = false;
                }
            }
            ExtraText[i].BackColor = Color.LightGreen;
            return(reloadTab);
        }
 // Step thru all classes and attributes with classes to issue Get requests
 private void btnReadAll_Click(object sender, EventArgs e)
 {
     EIP_Log(null, "Read All Starting");
     // Get is assumed for read all request
     AllGood = true;
     if (EIP.StartSession())
     {
         if (EIP.ForwardOpen())
         {
             for (int i = 0; i < EIP.ClassCodeAttributes.Length && AllGood; i++)
             {
                 ClassAttr = (int[])EIP.ClassCodeAttributes[i].GetEnumValues();
                 // Issue commands for this group
                 for (int j = 0; j < ClassAttr.Length && AllGood; j++)
                 {
                     // Get attr for request
                     attr = EIP.AttrDict[EIP.ClassCodes[i], (byte)ClassAttr[j]];
                     if (attr.HasGet && !attr.Ignore)
                     {
                         byte[] data = EIP.FormatOutput(attr.Get, txtDataOut.Text);
                         EIP.GetAttribute(EIP.ClassCodes[i], (byte)ClassAttr[j], data);
                     }
                 }
             }
         }
         EIP.ForwardClose();
     }
     EIP.EndSession();
     EIP_Log(null, "Read All Complete");
 }
Ejemplo n.º 4
0
        // Respond to mouse wheel over a control
        private void Text_MouseWheel(object sender, MouseEventArgs e)
        {
            TextBox t = (TextBox)sender;

            // Tag contains control number and attribute
            byte      n    = ((byte[])t.Tag)[0];
            ClassCode cc   = (ClassCode)((byte[])t.Tag)[1];
            byte      at   = ((byte[])t.Tag)[2];
            AttrData  attr = EIP.AttrDict[cc, at];

            // Only decimal values are allowed.  Set to Min if in error
            int len = attr.Data.Len;

            if (!long.TryParse(t.Text, out long val))
            {
                val = attr.Set.Min;
            }

            if (e.Delta > 0)
            {
                val = Math.Min(val + 1, attr.Set.Max);
            }
            else
            {
                val = Math.Max(val - 1, attr.Set.Min);
            }
            t.Text      = val.ToString();
            t.BackColor = Color.LightYellow;
        }
Ejemplo n.º 5
0
        // Get characters from the printer
        private void UpGet_Click(object sender, EventArgs e)
        {
            bool Success;
            int  bytesPerCharacter = (charHeight + 7) / 8 * charWidth;

            CleanUpGrid();
            // Build the blank image
            stripes = new long[Count][];
            for (int i = 0; i < stripes.Length; i++)
            {
                stripes[i] = new long[charWidth];
            }
            bmGrid = StripesToBitMap(stripes);
            BitMapToImage();

            if (EIP.StartSession())
            {
                if (EIP.ForwardOpen())
                {
                    byte[] data;
                    for (int i = 0; i <= Count; i++)
                    {
                        if ((Layout)cbLayout.SelectedIndex == Layout.Fixed)
                        {
                            AttrData attr = EIP.GetAttrData(ccUP.User_Pattern_Fixed);
                            data    = EIP.FormatOutput(attr.Get, new int[] { dotMatrixCode, Registration + i });
                            Success = EIP.GetAttribute(ClassCode.User_pattern, (byte)ccUP.User_Pattern_Fixed, data);
                        }
                        else
                        {
                            AttrData attr = EIP.GetAttrData(ccUP.User_Pattern_Free);
                            data    = EIP.FormatOutput(attr.Get, new int[] { charHeight, charWidth, Registration + i });
                            Success = EIP.GetAttribute(ClassCode.User_pattern, (byte)ccUP.User_Pattern_Free, data);
                        }
                        if (Success)
                        {
                            int hdrLen = cbLayout.SelectedIndex == (int)Layout.Fixed ? 2 : 4;
                            if (EIP.GetDataLength == bytesPerCharacter + hdrLen)
                            {
                                stripes[i] = BytesToStripe(charHeight, EIP.GetData, hdrLen);
                                bmGrid     = StripesToBitMap(stripes);
                                BitMapToImage();
                                grpGrid.Invalidate();
                            }
                        }
                        else
                        {
                            EIP.LogIt("User Pattern Upload Failed.  Aborting Upload!");
                            break;
                        }
                    }
                }
                EIP.ForwardClose();
            }
            EIP.EndSession();
            // Build the real image
            bmGrid = StripesToBitMap(stripes);
            BitMapToImage();
            SetButtonEnables();
        }
Ejemplo n.º 6
0
        private void cmdSaveToPrinter_Click(object sender, EventArgs e)
        {
            // A single command, no need to open/close the connection here
            byte[]   data = EIP.Merge(EIP.ToBytes(4, 2), EIP.ToBytes(2, 1), EIP.ToBytes("AAA\x00"));
            AttrData attr = EIP.GetAttrData(ccPDM.Store_Print_Data);

            EIP.SetAttribute(attr.Class, attr.Val, data);
        }
Ejemplo n.º 7
0
        private void Attributes_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox dd = (ComboBox)sender;

            Byte[]   tag  = (byte[])dd.Tag;
            AttrData attr = EIP.AttrDict[(ClassCode)tag[1], tag[2]];

            texts[tag[0]].Text = (dd.SelectedIndex + attr.Set.Min).ToString();
        }
Ejemplo n.º 8
0
        // Keep ExtraText up to date if dropdown changes
        private void ExtraDropdownIndexChanged(object sender, EventArgs e)
        {
            ComboBox cb = (ComboBox)sender;

            byte[]   tag  = (byte[])cb.Tag;
            int      n    = tag[0];
            AttrData attr = EIP.GetAttrData((ccIDX)tag[2]);

            ExtraText[n].Text = (cb.SelectedIndex + attr.Data.Min).ToString();
        }
Ejemplo n.º 9
0
        // Get the contents of one attribute
        private int GetDecAttribute <T>(T Attribute) where T : Enum
        {
            int      val  = 0;
            AttrData attr = GetAttrData(Attribute);

            if (GetAttribute(attr.Class, attr.Val, Nodata))
            {
                val = GetDecValue;
            }
            return(val);
        }
Ejemplo n.º 10
0
        // Set enables on the extra buttons of the display
        public void SetExtraButtonEnables(object sender, EventArgs e)
        {
            bool enabled = parent.ComIsOn;

            for (int i = 0; i < extrasUsed; i++)
            {
                byte     at   = ((byte[])ExtraSet[i].Tag)[2];
                AttrData attr = EIP.AttrDict[ClassCode.Index, at];
                ExtraGet[i].Enabled = enabled;
                ExtraSet[i].Enabled = enabled && int.TryParse(ExtraText[i].Text, out int val) &&
                                      val >= attr.Data.Min && val <= attr.Data.Max;
            }
        }
Ejemplo n.º 11
0
        // Get the contents of one attribute
        private string GetAttribute <T>(T Attribute, int n) where T : Enum
        {
            string   val  = string.Empty;
            AttrData attr = GetAttrData(Attribute);

            if (GetAttribute(attr.Class, attr.Val, FormatOutput(attr.Get, n)))
            {
                val = GetDataValue;
                if (attr.Data.Fmt == DataFormats.UTF8 || attr.Data.Fmt == DataFormats.UTF8N)
                {
                    val = FromQuoted(val);
                }
            }
            return(val);
        }
 // The function drop changed.  Set the correct Get/Set/Service buttons visible
 private void cbFunction_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cbClassCode.SelectedIndex >= 0 && cbFunction.SelectedIndex >= 0)
     {
         attr = EIP.AttrDict[EIP.ClassCodes[cbClassCode.SelectedIndex], (byte)ClassAttr[cbFunction.SelectedIndex]];
         btnIssueGet.Visible     = attr.HasGet;
         btnIssueSet.Visible     = attr.HasSet;
         btnIssueService.Visible = attr.HasService;
     }
     else
     {
         btnIssueGet.Visible     = false;
         btnIssueSet.Visible     = false;
         btnIssueService.Visible = false;
     }
     SetButtonEnables();
 }
Ejemplo n.º 13
0
 // Get the names associated with the dropdown
 private string[] GetDropdownNames(AttrData attr)
 {
     if (attr.Data.DropDown == fmtDD.Decimal)
     {
         // For decimal, just get the integer values from Min to Max
         string[] names = new string[(int)(attr.Data.Max - attr.Data.Min + 1)];
         for (int i = 0; i < names.Length; i++)
         {
             names[i] = (i + attr.Data.Min).ToString();
         }
         return(names);
     }
     else
     {
         // Get the names from the translation table
         return(EIP.GetDropDownNames((int)attr.Data.DropDown));
     }
 }
Ejemplo n.º 14
0
        // Issue a single service request
        private void Service_Click(object sender, EventArgs e)
        {
            Button   b    = (Button)sender;
            int      tag  = ((byte[])b.Tag)[0];
            AttrData attr = EIP.AttrDict[cc, ccAttribute[tag]];

            if (attr.Ignore)
            {
                // Avoid a printer hang
                texts[tag].Text = "Ignored!";
            }
            else
            {
                // Build output string if needed and issue Service request
                byte[] data    = EIP.FormatOutput(attr.Service, texts[tag], dropdowns[tag], attr);
                bool   Success = EIP.ServiceAttribute(cc, attr.Val, data);
            }
            SetButtonEnables();
        }
        private void RetrieveSubstitution(List <SubstitutionRule> sr, ccSR rule)
        {
            AttrData attr = GetAttrData(rule);
            int      n    = (int)(attr.Get.Max - attr.Get.Min + 1);

            string[] subCode = new string[n];
            for (int i = 0; i < n; i++)
            {
                subCode[i] = GetAttribute(rule, i + (int)attr.Get.Min);
            }
            for (int i = 0; i < n; i += 10)
            {
                sr.Add(new SubstitutionRule()
                {
                    Type = rule.ToString().Replace("_", ""),
                    Base = (int)(i + attr.Get.Min),
                    Text = string.Join("/", subCode, i, Math.Min(10, n - i)),
                });
            }
        }
Ejemplo n.º 16
0
 // Send characters to the printer
 private void UpSet_Click(object sender, EventArgs e)
 {
     if (EIP.StartSession())
     {
         if (EIP.ForwardOpen())
         {
             byte[][] b = StripesToBytes(charHeight, BitMapToStripes(bmGrid, charWidth));
             byte[]   data;
             for (int i = 0; i < Count; i++)
             {
                 if ((Layout)cbLayout.SelectedIndex == Layout.Fixed)
                 {
                     AttrData attr = EIP.GetAttrData(ccUP.User_Pattern_Fixed);
                     // Font ID, Position, and Bit Map
                     data = EIP.FormatOutput(attr.Set, new int[] { dotMatrixCode, Registration + i }, b[i]);
                     if (!EIP.SetAttribute(ClassCode.User_pattern, (byte)ccUP.User_Pattern_Fixed, data))
                     {
                         EIP.LogIt("Fixed Pattern Download Failed.  Aborting Download!");
                         break;
                     }
                 }
                 else
                 {
                     AttrData attr = EIP.GetAttrData(ccUP.User_Pattern_Free);
                     // Vertical Size (charHeigth), Horizontol Size (charWidth), Position, Bit Map
                     data = EIP.FormatOutput(attr.Set, new int[] { charHeight, charWidth, Registration + i }, b[i]);
                     if (!EIP.SetAttribute(ClassCode.User_pattern, (byte)ccUP.User_Pattern_Free, data))
                     {
                         EIP.LogIt("Free Pattern Download Failed.  Aborting Download!");
                         break;
                     }
                 }
             }
         }
         EIP.ForwardClose();
     }
     EIP.EndSession();
     SetButtonEnables();
 }
Ejemplo n.º 17
0
        // Add a single extra control
        private void AddExtras(ref byte n, ccIDX function)
        {
            byte[] tag = new byte[] { n, (byte)ClassCode.Index, (byte)function };
            ExtraLabel[n] = new Label()
            {
                TextAlign = ContentAlignment.TopRight, Text = function.ToString().Replace('_', ' ')
            };
            ExtraText[n] = new TextBox()
            {
                Tag = tag, TextAlign = HorizontalAlignment.Center, Font = courier
            };
            ExtraGet[n] = new Button()
            {
                Text = "Get", Tag = tag
            };
            ExtraSet[n] = new Button()
            {
                Text = "Set", Tag = tag
            };
            ExtraText[n].Enter      += Text_Enter;
            ExtraText[n].Leave      += SetExtraButtonEnables;
            ExtraGet[n].Click       += GetExtras_Click;
            ExtraSet[n].Click       += SetExtras_Click;
            ExtraText[n].KeyPress   += Text_KeyPress;
            ExtraText[n].MouseWheel += Text_MouseWheel;
            AttrData attr = EIP.GetAttrData(function);

            if (attr.Data.DropDown != fmtDD.None)
            {
                ExtraDropdowns[n] = new ComboBox()
                {
                    Tag = tag, FlatStyle = FlatStyle.Flat, DropDownStyle = ComboBoxStyle.DropDownList, Visible = false
                };
                ExtraDropdowns[n].Items.AddRange(GetDropdownNames(attr));
                ExtraDropdowns[n].SelectedIndexChanged += ExtraDropdownIndexChanged;
            }
            n++;
        }
Ejemplo n.º 18
0
        // Get the contents of one attribute
        private string GetAttribute <T>(T Attribute) where T : Enum
        {
            string   val  = string.Empty;
            AttrData attr = GetAttrData(Attribute);

            if (GetAttribute(attr.Class, attr.Val, Nodata))
            {
                val = GetDataValue;
                if (attr.Data.Fmt == DataFormats.UTF8 || attr.Data.Fmt == DataFormats.UTF8N)
                {
                    val = FromQuoted(val);
                }
                else if (attr.Data.DropDown != fmtDD.None)
                {
                    string[] dd = GetDropDownNames((int)attr.Data.DropDown);
                    long     n  = GetDecValue - attr.Data.Min;
                    if (n >= 0 && n < dd.Length)
                    {
                        val = dd[n];
                    }
                }
            }
            return(val);
        }
Ejemplo n.º 19
0
        // Issue a single Get request
        private void Get_Click(object sender, EventArgs e)
        {
            Button   b    = (Button)sender;
            int      tag  = ((byte[])b.Tag)[0];
            AttrData attr = EIP.AttrDict[cc, ccAttribute[tag]];

            if (attr.Ignore)
            {
                // Avoid a printer hang
                texts[tag].Text       = "Ignored!";
                texts[tag].BackColor  = Color.Pink;
                counts[tag].BackColor = Color.LightGreen;
            }
            else
            {
                // Build and issue the request
                byte[] data = EIP.FormatOutput(attr.Get, texts[tag], dropdowns[tag], attr);
                texts[tag].Text = "Loading";
                parent.AllGood  = EIP.GetAttribute(cc, attr.Val, data);
                // Process the data returned
                EIP.SetBackColor(attr.Data, attr, counts[tag], texts[tag], dropdowns[tag]);
            }
            SetButtonEnables();
        }
Ejemplo n.º 20
0
        // Issue a single Set request
        private void Set_Click(object sender, EventArgs e)
        {
            Button   b    = (Button)sender;
            int      tag  = ((byte[])b.Tag)[0];
            AttrData attr = EIP.AttrDict[cc, ccAttribute[tag]];

            if (attr.Ignore)
            {
                // Avoid a printer hang
                texts[tag].Text = "Ignored!";
            }
            else
            {
                // Build output string if needed and issue Set request
                byte[] data    = EIP.FormatOutput(attr.Set, texts[tag], dropdowns[tag], attr);
                bool   Success = EIP.SetAttribute(cc, attr.Val, data);
                if (Success)
                {
                    // In case the control was yellow
                    texts[tag].BackColor = Color.LightGreen;
                }
            }
            SetButtonEnables();
        }
        // A Get/Set/Service request has completed
        private void EIP_IO_Complete(EIP sender, EIPEventArg e)
        {
            // Record status and color it
            txtStatus.Text = EIP.GetStatus;
            if (e.Successful)
            {
                txtStatus.BackColor = Color.LightGreen;
                switch (e.Class)
                {
                case ClassCode.Index:
                    switch (e.Access)
                    {
                    case AccessCode.Set:
                        // reflect any changes back to the Index Function
                        int n = Array.FindIndex(indexAttr.ccAttribute, x => x == e.Attribute);
                        indexAttr.texts[n].Text    = EIP.SetDataValue;
                        indexAttr.texts[n].Visible = true;
                        AttrData attr = EIP.GetAttrData((ccIDX)e.Attribute);
                        if (attr.Data.DropDown != fmtDD.None)
                        {
                            int i = EIP.SetDecValue - (int)attr.Data.Min;
                            if (i >= 0 && i < indexAttr.dropdowns[n].Items.Count)
                            {
                                indexAttr.dropdowns[n].SelectedIndex = i;
                                indexAttr.texts[n].Visible           = false;
                                indexAttr.dropdowns[n].Visible       = true;
                            }
                            else
                            {
                                indexAttr.dropdowns[n].Visible = false;
                            }
                        }
                        break;
                    }
                    break;

                case ClassCode.IJP_operation:
                    if ((ccIJP)e.Attribute == ccIJP.Online_Offline)
                    {
                        switch (e.Access)
                        {
                        case AccessCode.Set:
                            break;

                        case AccessCode.Get:
                            break;
                        }
                    }
                    break;
                }
            }
            else
            {
                txtStatus.BackColor = Color.Pink;
            }

            // Display the data sent to the printer
            txtCountOut.Text     = EIP.SetDataLength.ToString();
            txtDataOut.Text      = EIP.SetDataValue;
            txtDataBytesOut.Text = EIP.GetBytes(EIP.SetData, 0, EIP.SetDataLength);

            // Display the printer's response
            txtCountIn.Text     = EIP.GetDataLength.ToString();
            txtDataIn.Text      = EIP.GetDataValue;
            txtDataBytesIn.Text = EIP.GetBytes(EIP.GetData, 0, EIP.GetDataLength);

            // Record the operation in the log
            lstErrors.Items.Add($"{EIP.LastIO} -- {e.Access}/{e.Class}/{EIP.GetAttributeName(e.Class, e.Attribute)} Complete");
            lstErrors.SelectedIndex = lstErrors.Items.Count - 1;
        }
Ejemplo n.º 22
0
        // Build all the controls for this attribute tab
        private void BuildControls()
        {
            bool twoCols = ccAttribute.Length > Half;

            // build headers for one or two columns of attributes
            if (twoCols)
            {
                hdrs = new Label[8];
            }
            else
            {
                hdrs = new Label[4];
            }
            // Need to bold them all
            Font bolded = new Font(tab.Font, FontStyle.Underline | FontStyle.Bold);

            // Build all the headers
            for (int i = 0; i < (twoCols ? 2 : 1); i++)
            {
                hdrs[i * 4 + 0] = new Label()
                {
                    Text = "Attributes", Font = bolded, TextAlign = ContentAlignment.TopRight
                };
                hdrs[i * 4 + 1] = new Label()
                {
                    Text = "#", Font = bolded, TextAlign = ContentAlignment.TopCenter
                };
                hdrs[i * 4 + 2] = new Label()
                {
                    Text = "Data", Font = bolded, TextAlign = ContentAlignment.TopCenter
                };
                hdrs[i * 4 + 3] = new Label()
                {
                    Text = "Control", Font = bolded, TextAlign = ContentAlignment.TopCenter
                };
            }
            tab.Controls.AddRange(hdrs);

            // Allocate the arrays to hold the controls
            labels    = new Label[ccAttribute.Length];
            texts     = new TextBox[ccAttribute.Length];
            dropdowns = new ComboBox[ccAttribute.Length];
            counts    = new TextBox[ccAttribute.Length];
            gets      = new Button[ccAttribute.Length];
            sets      = new Button[ccAttribute.Length];
            services  = new Button[ccAttribute.Length];

            // Build the controls
            for (int i = 0; i < ccAttribute.Length; i++)
            {
                AttrData attr = EIP.AttrDict[cc, ccAttribute[i]];
                string   s    = Enum.GetName(typeof(t1), ccAttribute[i]);
                byte[]   tag  = new byte[] { (byte)i, (byte)cc, ccAttribute[i] };
                labels[i] = new Label()
                {
                    Tag       = tag,
                    TextAlign = System.Drawing.ContentAlignment.TopRight,
                    Text      = $"{Enum.GetName(typeof(t1), ccAttribute[i]).Replace('_', ' ')} (0x{attr.Val:X2})"
                };

                counts[i] = new TextBox()
                {
                    Tag = tag, ReadOnly = true, TextAlign = HorizontalAlignment.Center, Font = courier
                };
                if (attr.HasService)
                {
                    counts[i].Text = attr.Service.Len.ToString();
                }
                else if (attr.HasSet)
                {
                    counts[i].Text = attr.Set.Len.ToString();
                }
                else
                {
                    counts[i].Text = attr.Get.Len.ToString();
                }

                texts[i] = new TextBox()
                {
                    Tag = tag, TextAlign = HorizontalAlignment.Center, Font = courier
                };
                texts[i].Enter += Text_Enter;
                tab.Controls.Add(texts[i]);
                texts[i].ReadOnly = !(attr.HasSet || attr.HasGet && attr.Get.Len > 0 || attr.HasService && attr.Service.Len > 0);
                if (attr.HasSet && attr.Data.DropDown == fmtDD.None &&
                    (attr.Data.Fmt == DataFormats.Decimal || attr.Data.Fmt == DataFormats.DecimalLE ||
                     attr.Data.Fmt == DataFormats.SDecimal || attr.Data.Fmt == DataFormats.SDecimalLE))
                {
                    texts[i].MouseWheel += Text_MouseWheel;
                }

                if (attr.Data.DropDown != fmtDD.None)
                {
                    dropdowns[i] = new ComboBox()
                    {
                        Tag = tag, FlatStyle = FlatStyle.Flat, DropDownStyle = ComboBoxStyle.DropDownList, Visible = !attr.HasGet
                    };
                    dropdowns[i].Items.AddRange(GetDropdownNames(attr));
                    if (dropdowns[i].Visible)
                    {
                        texts[i].Visible           = false;
                        dropdowns[i].BackColor     = Color.LightGreen;
                        dropdowns[i].SelectedIndex = 0;
                        texts[i].Text = attr.Set.Min.ToString();
                        dropdowns[i].SelectedIndexChanged += Attributes_SelectedIndexChanged;
                    }
                    tab.Controls.Add(dropdowns[i]);
                }
                else if (attr.HasSet && !attr.HasGet && attr.Set.Fmt == DataFormats.Decimal)
                {
                    texts[i].Text      = attr.Set.Min.ToString();
                    texts[i].BackColor = Color.LightGreen;
                }

                if (attr.HasGet)
                {
                    gets[i] = new Button()
                    {
                        Tag = tag, Text = "Get"
                    };
                    gets[i].Click += Get_Click;
                    tab.Controls.Add(gets[i]);
                }
                if (attr.HasSet)
                {
                    sets[i] = new Button()
                    {
                        Tag = tag, Text = "Set"
                    };
                    sets[i].Click += Set_Click;
                    tab.Controls.Add(sets[i]);
                    if (attr.Set.Fmt == DataFormats.Decimal || attr.Set.Fmt == DataFormats.DecimalLE)
                    {
                        texts[i].KeyPress += NumbersOnly_KeyPress;
                    }
                    else if (attr.Set.Fmt == DataFormats.SDecimal || attr.Set.Fmt == DataFormats.SDecimalLE)
                    {
                        texts[i].KeyPress += SignedNumbersOnly_KeyPress;
                    }
                    else
                    {
                        texts[i].KeyPress += Text_KeyPress;
                    }
                }
                if (attr.HasService)
                {
                    services[i] = new Button()
                    {
                        Tag = tag, Text = "Service"
                    };
                    services[i].Click += Service_Click;
                    tab.Controls.Add(services[i]);
                }
                if (attr.HasSet || attr.HasGet && attr.Get.Len > 0 || attr.HasService && attr.Service.Len > 0)
                {
                    texts[i].Leave += Text_Leave;
                }
            }
            tab.Controls.AddRange(labels);
            tab.Controls.AddRange(counts);

            getAll = new Button()
            {
                Text = "Get All"
            };
            getAll.Click += GetAll_Click;
            tab.Controls.Add(getAll);
            setAll = new Button()
            {
                Text = "Set All"
            };
            tab.Controls.Add(setAll);
            setAll.Click += SetAll_Click;
        }
Ejemplo n.º 23
0
        // Enable appropriate buttons based on conditions
        public void SetButtonEnables()
        {
            bool enable  = parent.ComIsOn;
            bool anySets = false;
            bool anyGets = false;

            for (int i = 0; i < ccAttribute.Length; i++)
            {
                AttrData attr = EIP.AttrDict[cc, ccAttribute[i]];
                bool     allow;
                if (cc == ClassCode.Index &&
                    ((ccIDX)attr.Val == ccIDX.Automatic_reflection || (ccIDX)attr.Val == ccIDX.Start_Stop_Management_Flag) ||
                    cc == ClassCode.IJP_operation && (ccIJP)attr.Val == ccIJP.Online_Offline)
                {
                    allow = true;
                }
                else
                {
                    allow = parent.ComIsOn;
                }

                if (attr.HasSet)
                {
                    if (EIP.TextIsValid(attr.Set, texts[i].Text))
                    {
                        sets[i].Enabled = allow;
                        anySets        |= enable;
                    }
                    else
                    {
                        sets[i].Enabled = false;
                    }
                }
                if (attr.HasGet)
                {
                    if (attr.Get.Len == 0 || EIP.TextIsValid(attr.Get, texts[i].Text))
                    {
                        gets[i].Enabled = allow;
                        anyGets        |= enable;
                    }
                    else
                    {
                        gets[i].Enabled = false;
                    }
                }
                if (attr.HasService)
                {
                    if (attr.Service.Len == 0 || EIP.TextIsValid(attr.Service, texts[i].Text))
                    {
                        services[i].Enabled = parent.ComIsOn;
                    }
                    else
                    {
                        services[i].Enabled = false;
                    }
                }
            }
            setAll.Enabled = anySets;
            getAll.Enabled = anyGets;

            SetExtraButtonEnables(null, null);

            // Substitution and User Pattern have extra controls
            Substitution?.SetButtonEnables();
            UserPattern?.SetButtonEnables();
        }