Ejemplo n.º 1
0
        private void button_read_Click(object sender, EventArgs e)
        {
            if (!lco.isopen())
            {
                MessageBox.Show("CAN not open");
                return;
            }

            if (numericUpDown_node.Value == 0)
            {
                MessageBox.Show("You cannot read from Node 0, please select a node");
                return;
            }

            listView1.Invoke(new MethodInvoker(delegate
            {
                button_read.Enabled = false;
                foreach (ListViewItem lvi in listView1.Items)
                {
                    lvi.BackColor          = Color.White;
                    sdocallbackhelper help = (sdocallbackhelper)lvi.Tag;
                    SDO sdo  = lco.SDOread((byte)numericUpDown_node.Value, (UInt16)help.od.Index, (byte)help.od.Subindex, gotit);
                    help.sdo = sdo;
                    lvi.Tag  = help;
                }
            }));
        }
Ejemplo n.º 2
0
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            if (!lco.isopen())
            {
                MessageBox.Show("CAN not open");
                return;
            }



            sdocallbackhelper h  = (sdocallbackhelper)listView1.SelectedItems[0].Tag;
            ValueEditor       ve = new ValueEditor(h.od, listView1.SelectedItems[0].SubItems[5].Text);

            if (h.od.StorageLocation == "ROM")
            {
                MessageBox.Show("Should not edit ROM objects");
            }

            ve.UpdateValue += delegate(string s)
            {
                h.sdo = dovalueupdate(h, s);
                listView1.SelectedItems[0].Tag = h;
            };


            //SDO sdo = null;
            if (ve.ShowDialog() == DialogResult.OK)
            {
            }
        }
Ejemplo n.º 3
0
        void addtolist(ODentry od, bool dcf, bool isemptydcf)
        {
            if (!dcf || isemptydcf)
            {
                string[] items = new string[7];
                items[0] = string.Format("0x{0:x4}", od.Index);
                items[1] = string.Format("0x{0:x2}", od.Subindex);

                if (od.parent == null)
                {
                    items[2] = od.parameter_name;
                }
                else
                {
                    items[2] = od.parent.parameter_name + " -- " + od.parameter_name;
                }

                if (od.datatype == DataType.UNKNOWN && od.parent != null)
                {
                    items[3] = od.parent.datatype.ToString();
                }
                else
                {
                    items[3] = od.datatype.ToString();
                }


                items[4] = od.defaultvalue;



                items[5] = "";

                //  items[6] = od.actualvalue;


                ListViewItem lvi = new ListViewItem(items);



                // SDO sdo = lco.SDOread((byte)numericUpDown_node.Value, (UInt16)od.index, (byte)od.subindex, gotit);

                sdocallbackhelper help = new sdocallbackhelper();
                help.sdo = null;
                help.od  = od;
                lvi.Tag  = help;

                listView1.Items.Add(lvi);
            }

            if (dcf)
            {
                adddcfvalue(od);
            }
        }
Ejemplo n.º 4
0
        void adddcfvalue(ODentry od)
        {
            foreach (ListViewItem lvi in listView1.Items)
            {
                sdocallbackhelper help = (sdocallbackhelper)lvi.Tag;

                if ((help.od.Index == od.Index) && (help.od.Subindex == od.Subindex))
                {
                    lvi.SubItems[6].Text = od.actualvalue;
                }
            }
        }
Ejemplo n.º 5
0
        private void saveDifferenceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog odf = new SaveFileDialog();

            odf.Filter = "(*.dcf)|*.dcf";
            if (odf.ShowDialog() == DialogResult.OK)
            {
                //  System.IO.StreamWriter file = new System.IO.StreamWriter(odf.FileName);

                //file.WriteLine("Object\tSub Index\tName\tDefault\tCurrent\t");

                foreach (ListViewItem lvi in listView1.Items)
                {
                    string index = lvi.SubItems[0].Text;
                    string sub   = lvi.SubItems[1].Text;
                    string name  = lvi.SubItems[2].Text;


                    sdocallbackhelper help = (sdocallbackhelper)lvi.Tag;

                    string defaultstring = help.od.defaultvalue;
                    string currentstring = help.od.actualvalue;

                    UInt16 key  = Convert.ToUInt16(index, 16);
                    UInt16 subi = Convert.ToUInt16(sub, 16);

                    if (subi == 0)
                    {
                        eds.ods[key].actualvalue = currentstring;
                    }
                    else
                    {
                        ODentry subod = eds.ods[key].Getsubobject(subi);
                        if (subod != null)
                        {
                            subod.actualvalue = currentstring;
                        }
                    }

                    // file.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}",index,sub,name,defaultstring,currentstring));
                }

                eds.Savefile(odf.FileName, InfoSection.Filetype.File_DCF);

                //file.Close();
            }
        }
Ejemplo n.º 6
0
        private void button_writeDCF_Click(object sender, EventArgs e)
        {
            if (numericUpDown_node.Value == 0)
            {
                MessageBox.Show("Cannot write to node 0, please select a valid node");
                return;
            }

            foreach (ListViewItem lvi in listView1.Items)
            {
                string index = lvi.SubItems[0].Text;
                string sub   = lvi.SubItems[1].Text;
                string name  = lvi.SubItems[2].Text;

                UInt16 key  = Convert.ToUInt16(index, 16);
                byte   subi = Convert.ToByte(sub, 16);

                sdocallbackhelper help = (sdocallbackhelper)lvi.Tag;

                string edsstring    = help.od.defaultvalue; //the eds value
                string actualstring = lvi.SubItems[5].Text; // the dcf value
                string dcfstring    = lvi.SubItems[6].Text;

                if (actualstring != dcfstring)
                {
                    if (dcfstring != "")
                    {
                        sdocallbackhelper h = (sdocallbackhelper)lvi.Tag;
                        try
                        {
                            h.sdo = dovalueupdate(h, dcfstring);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format("Error writing to 0x{0:x4}/{1:x2} details :-\n{2}", h.od.Index, h.od.Subindex, ex.ToString()));
                        }

                        lvi.Tag = h;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        void upsucc(SDO sdo)
        {
            //button_read_Click(null, null);

            listView1.Invoke(new MethodInvoker(delegate
            {
                foreach (ListViewItem lvi in listView1.Items)
                {
                    sdocallbackhelper help = (sdocallbackhelper)lvi.Tag;

                    if (help.sdo != sdo)
                    {
                        continue;
                    }

                    sdo      = lco.SDOread((byte)numericUpDown_node.Value, (UInt16)help.od.Index, (byte)help.od.Subindex, gotit);
                    help.sdo = sdo;
                    lvi.Tag  = help;

                    break;
                }
            }));
        }
Ejemplo n.º 8
0
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            if (!lco.isopen())
            {
                MessageBox.Show("CAN not open");
                return;
            }



            sdocallbackhelper h  = (sdocallbackhelper)listView1.SelectedItems[0].Tag;
            ValueEditor       ve = new ValueEditor(h.od, listView1.SelectedItems[0].SubItems[5].Text);

            if (h.od.StorageLocation == "ROM")
            {
                MessageBox.Show("Should not edit ROM objects");
            }

            ve.UpdateValue += delegate(string s)
            {
                DataType dt = h.od.datatype;

                if (dt == DataType.UNKNOWN && h.od.parent != null)
                {
                    dt = h.od.parent.datatype;
                }

                SDO sdo = null;


                switch (dt)
                {
                case DataType.REAL32:
                {
                    float val = (float)new SingleConverter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }

                case DataType.REAL64:
                {
                    double val     = (double)new DoubleConverter().ConvertFromString(ve.newvalue);
                    byte[] payload = BitConverter.GetBytes(val);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                    break;
                }

                case DataType.INTEGER8:
                {
                    sbyte val = (sbyte)new SByteConverter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }

                case DataType.INTEGER16:
                {
                    Int16 val = (Int16) new Int16Converter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }


                case DataType.INTEGER32:
                {
                    Int32 val = (Int32) new Int32Converter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }

                case DataType.UNSIGNED8:
                {
                    byte val = (byte)new ByteConverter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }

                case DataType.UNSIGNED16:
                {
                    UInt16 val = (UInt16) new UInt16Converter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }

                case DataType.UNSIGNED32:
                {
                    UInt32 val = (UInt32) new UInt32Converter().ConvertFromString(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                    break;
                }

                case DataType.INTEGER64:
                {
                    Int64  val     = (Int64) new Int64Converter().ConvertFromString(ve.newvalue);
                    byte[] payload = BitConverter.GetBytes(val);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                    break;
                }

                case DataType.UNSIGNED64:
                {
                    UInt64 val     = (UInt64) new UInt64Converter().ConvertFromString(ve.newvalue);
                    byte[] payload = BitConverter.GetBytes(val);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                    break;
                }

                case DataType.VISIBLE_STRING:
                {
                    byte[] payload = Encoding.ASCII.GetBytes(ve.newvalue);
                    sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                    break;
                }



                default:

                    break;
                }

                h.sdo = sdo;
                listView1.SelectedItems[0].Tag = h;
            };


            //SDO sdo = null;
            if (ve.ShowDialog() == DialogResult.OK)
            {
                /*
                 * DataType dt = h.od.datatype;
                 *
                 * if (dt == DataType.UNKNOWN && h.od.parent != null)
                 *  dt = h.od.parent.datatype;
                 *
                 * switch (dt)
                 * {
                 *  case DataType.REAL32:
                 *      {
                 *
                 *          float val = (float)new SingleConverter().ConvertFromString(ve.newvalue);
                 *          sdo=lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.REAL64:
                 *      {
                 *
                 *          double val = (double)new DoubleConverter().ConvertFromString(ve.newvalue);
                 *          byte[] payload = BitConverter.GetBytes(val);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, payload, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.INTEGER8:
                 *      {
                 *          sbyte val = (sbyte)new SByteConverter().ConvertFromString(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.INTEGER16:
                 *      {
                 *          Int16 val = (Int16)new Int16Converter().ConvertFromString(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *
                 *
                 *  case DataType.INTEGER32:
                 *      {
                 *          Int32 val = (Int32)new Int32Converter().ConvertFromString(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *  case DataType.UNSIGNED8:
                 *      {
                 *          byte val = (byte)new ByteConverter().ConvertFromString(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *  case DataType.UNSIGNED16:
                 *      {
                 *          UInt16 val = (UInt16)new UInt16Converter().ConvertFromString(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.UNSIGNED32:
                 *      {
                 *          UInt32 val = (UInt32)new UInt32Converter().ConvertFromString(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, val, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.INTEGER64:
                 *      {
                 *
                 *          Int64 val = (Int64)new Int64Converter().ConvertFromString(ve.newvalue);
                 *          byte[] payload = BitConverter.GetBytes(val);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, payload, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.UNSIGNED64:                        {
                 *
                 *          UInt64 val = (UInt64)new UInt64Converter().ConvertFromString(ve.newvalue);
                 *          byte[] payload = BitConverter.GetBytes(val);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, payload, upsucc);
                 *          break;
                 *      }
                 *
                 *  case DataType.VISIBLE_STRING:
                 *      {
                 *
                 *          byte [] payload = Encoding.ASCII.GetBytes(ve.newvalue);
                 *          sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.index, (byte)h.od.subindex, payload, upsucc);
                 *          break;
                 *      }
                 *
                 *
                 *
                 *  default:
                 *
                 *      break;
                 * }
                 */

//                h.sdo = sdo;
//                listView1.SelectedItems[0].Tag = h;
            }
        }
Ejemplo n.º 9
0
        void gotit(SDO sdo)
        {
            try
            {
                listView1.Invoke(new MethodInvoker(delegate
                {
                    if (lco.getSDOQueueSize() == 0)
                    {
                        button_read.Enabled = true;
                    }

                    label_sdo_queue_size.Text = string.Format("SDO Queue Size: {0}", lco.getSDOQueueSize());

                    foreach (ListViewItem lvi in listView1.Items)
                    {
                        sdocallbackhelper h = (sdocallbackhelper)lvi.Tag;
                        if (h.sdo == sdo)
                        {
                            if (sdo.state == SDO.SDO_STATE.SDO_ERROR)
                            {
                                lvi.SubItems[5].Text = " **ERROR **";
                                return;
                            }

                            //if (sdo.exp == true)
                            {
                                DataType meh = h.od.datatype;
                                if (meh == DataType.UNKNOWN && h.od.parent != null)
                                {
                                    meh = h.od.parent.datatype;
                                }


                                //item 5 is the read value item 4 is the actual value

                                switch (meh)
                                {
                                case DataType.REAL32:

                                    float myFloat        = System.BitConverter.ToSingle(BitConverter.GetBytes(h.sdo.expitideddata), 0);
                                    lvi.SubItems[5].Text = myFloat.ToString();

                                    float fout;
                                    if (float.TryParse(lvi.SubItems[4].Text, out fout))
                                    {
                                        if (fout != myFloat)
                                        {
                                            lvi.BackColor = Color.Red;
                                        }
                                    }

                                    break;

                                case DataType.REAL64:

                                    double myDouble      = System.BitConverter.ToDouble(h.sdo.databuffer, 0);
                                    lvi.SubItems[5].Text = myDouble.ToString();
                                    break;

                                case DataType.INTEGER8:
                                case DataType.INTEGER16:
                                case DataType.INTEGER32:
                                case DataType.UNSIGNED8:
                                case DataType.UNSIGNED16:
                                case DataType.UNSIGNED32:


                                    int i1, i2;

                                    lvi.SubItems[5].Text = String.Format("{0}", h.sdo.expitideddata);

                                    if (int.TryParse(lvi.SubItems[5].Text, out i1) && int.TryParse(lvi.SubItems[4].Text, out i2))
                                    {
                                        if (i1 != i2)
                                        {
                                            lvi.BackColor = Color.Red;
                                        }
                                    }

                                    break;

                                case DataType.VISIBLE_STRING:

                                    lvi.SubItems[5].Text = System.Text.Encoding.UTF8.GetString(h.sdo.databuffer);

                                    break;

                                case DataType.OCTET_STRING:

                                    StringBuilder sb = new StringBuilder();

                                    foreach (byte b in h.sdo.databuffer)
                                    {
                                        sb.Append(string.Format("{0:x} ", b));
                                    }

                                    lvi.SubItems[5].Text = sb.ToString();

                                    break;


                                case DataType.UNSIGNED64:
                                    {
                                        UInt64 data          = (UInt64)System.BitConverter.ToUInt64(h.sdo.databuffer, 0);
                                        lvi.SubItems[5].Text = String.Format("{0:x}", data);
                                    }
                                    break;

                                case DataType.INTEGER64:
                                    {
                                        Int64 data           = (Int64)System.BitConverter.ToInt64(h.sdo.databuffer, 0);
                                        lvi.SubItems[5].Text = String.Format("{0:x}", data);
                                    }
                                    break;

                                default:
                                    lvi.SubItems[5].Text = " **UNSUPPORTED **";
                                    break;
                                }
                            }
                            break;
                        }

                        h.od.actualvalue = lvi.SubItems[5].Text;
                    }
                }));
            }
            catch (Exception e)
            {
            }

            return;
        }
Ejemplo n.º 10
0
        private SDO dovalueupdate(sdocallbackhelper h, string sval)
        {
            DataType dt = h.od.datatype;

            if (dt == DataType.UNKNOWN && h.od.parent != null)
            {
                dt = h.od.parent.datatype;
            }

            SDO sdo = null;

            switch (dt)
            {
            case DataType.REAL32:
            {
                float val = (float)new SingleConverter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }

            case DataType.REAL64:
            {
                double val     = (double)new DoubleConverter().ConvertFromString(sval);
                byte[] payload = BitConverter.GetBytes(val);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                break;
            }

            case DataType.INTEGER8:
            {
                sbyte val = (sbyte)new SByteConverter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }

            case DataType.INTEGER16:
            {
                Int16 val = (Int16) new Int16Converter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }


            case DataType.INTEGER32:
            {
                Int32 val = (Int32) new Int32Converter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }

            case DataType.UNSIGNED8:
            {
                byte val = (byte)new ByteConverter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }

            case DataType.UNSIGNED16:
            {
                UInt16 val = (UInt16) new UInt16Converter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }

            case DataType.UNSIGNED32:
            {
                UInt32 val = (UInt32) new UInt32Converter().ConvertFromString(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, val, upsucc);
                break;
            }

            case DataType.INTEGER64:
            {
                Int64  val     = (Int64) new Int64Converter().ConvertFromString(sval);
                byte[] payload = BitConverter.GetBytes(val);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                break;
            }

            case DataType.UNSIGNED64:
            {
                UInt64 val     = (UInt64) new UInt64Converter().ConvertFromString(sval);
                byte[] payload = BitConverter.GetBytes(val);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                break;
            }

            case DataType.VISIBLE_STRING:
            {
                byte[] payload = Encoding.ASCII.GetBytes(sval);
                sdo = lco.SDOwrite((byte)numericUpDown_node.Value, (UInt16)h.od.Index, (byte)h.od.Subindex, payload, upsucc);
                break;
            }


            default:

                break;
            }

            return(sdo);
        }