コード例 #1
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)
            {
            }
        }
コード例 #2
0
ファイル: SDOEditor.cs プロジェクト: lukegluke/CanOpenMonitor
        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;
            }
        }