示例#1
0
        private void CommandCopy_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            IntbusDevice intbusDevice = TreeView_IntbusDevices.SelectedItem as IntbusDevice;

            IntbusDeviceCloneBuffer = intbusDevice.Clone() as IntbusDevice;
            var a = IntbusDeviceCloneBuffer;
        }
示例#2
0
        public void AddIntbusDevice(IntbusDevice intbusDevice)
        {
            IntbusDevice clonedDevice = intbusDevice.Clone() as IntbusDevice;

            clonedDevice.MasterIntbusDevice = this;
            this.SlaveIntbusDevices.Add(clonedDevice);
        }
示例#3
0
        private void CommandPaste_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            IntbusDevice intbusDevice = TreeView_IntbusDevices.SelectedItem as IntbusDevice;

            IntbusDevice copiedIntbusDevice = IntbusDeviceCloneBuffer;

            intbusDevice.AddIntbusDevice(copiedIntbusDevice);
        }
示例#4
0
        public object Clone()
        {
            IntbusDevice intbusDevice = new IntbusDevice(this.IntbusInterface, this.address)
            {
                Name = this.name,
                MasterIntbusDevice = this.MasterIntbusDevice,
            };

            foreach (var slaveDevice in this.SlaveIntbusDevices)
            {
                intbusDevice.AddIntbusDevice(slaveDevice.Clone() as IntbusDevice);
            }
            return(intbusDevice);
        }
示例#5
0
 private bool TryRemoveRecursive(IntbusDevice device, IntbusDevice removingDevice)
 {
     if (device.SlaveIntbusDevices.Contains(removingDevice))
     {
         device.SlaveIntbusDevices.Remove(removingDevice);
         return(true);
     }
     foreach (IntbusDevice dev in device.SlaveIntbusDevices)
     {
         if (TryRemoveRecursive(dev, removingDevice) == true)
         {
             return(true);
         }
     }
     return(false);
 }
示例#6
0
        private void CommandDelete_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            IntbusDevice removingDevice = (TreeView_IntbusDevices.SelectedItem as IntbusDevice);

            if (IntbusDevices.Contains(removingDevice))
            {
                IntbusDevices.Remove(removingDevice);
                return;
            }
            foreach (IntbusDevice device in IntbusDevices)
            {
                if (TryRemoveRecursive(device, removingDevice))
                {
                    return;
                }
            }
        }
示例#7
0
        public List <byte> ConvertToIntbusFrame(List <byte> modbusFrame)
        {
            IntbusDevice intbusDevice = this;

            do
            {
                modbusFrame.Insert(0, intbusDevice.AddressWithInterface);
                modbusFrame.InsertRange(0, intbusDevice.PrefixBytes);
                modbusFrame.AddRange(intbusDevice.PostfixBytes);
                intbusDevice = intbusDevice.MasterIntbusDevice;
            } while (intbusDevice != null);
            modbusFrame.RemoveRange(modbusFrame.Count - 2, 2);
            byte[] crc = ModbusUtility.CalculateCrc(modbusFrame.ToArray());
            modbusFrame.AddRange(crc.ToList());

            return(modbusFrame);
        }
示例#8
0
        public IntbusConfigurator()
        {
            InitializeComponent();
            this.DataContext = this;
            IntbusDevices    = new ObservableCollection <IntbusDevice>();
            IntbusDevice     = IntbusDevices.FirstOrDefault();
            IntbusInterfaces = new ObservableCollection <IntbusInterface>
            {
                new UART0(),
                new FM(),
                new I2C(),
                new OWI(),
                new SPI()
            };
            IntbusInterface = IntbusInterfaces.First();
            IntbusDevice A = new IntbusDevice(new OWI(), 1)
            {
                Name = "Датчик давления"
            };
            IntbusDevice B = new IntbusDevice(new SPI(), 26)
            {
                Name = "БП"
            };

            B.AddIntbusDevice(A);
            IntbusDevice C = new IntbusDevice(new FM(), 1)
            {
                Name = "О-модем"
            };
            IntbusDevice D = new IntbusDevice(new UART0(), 1)
            {
                Name = "Клапан"
            };

            C.AddIntbusDevice(B);
            C.AddIntbusDevice(A);
            C.AddIntbusDevice(D);
            IntbusDevices = new ObservableCollection <IntbusDevice>
            {
                C
            };
            C.SlaveIntbusDevices.First(x => x.Name == "Датчик давления").ModbusDeviceAddress = 2;
            C.SlaveIntbusDevices.First(x => x.Name == "Клапан").ModbusDeviceAddress          = 1;
            C.ModbusDeviceAddress = 3;
        }
示例#9
0
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext   = this;
            intbusConfigurator = new IntbusConfigurator();
            rootIntbusDevice   = intbusConfigurator.IntbusDevice;

            SerialPortModbus = new SerialPort();
            SerialPortModbus.DataReceived += new SerialDataReceivedEventHandler(SerialDataModbusReceived);
            SerialPortIntBUS = new SerialPort();

            IntBusAddedData = new List <byte>();
            Preambula       = new List <byte>();
            SerialPortNames = new ObservableCollection <string>();
            Parities        = new ObservableCollection <string>();
            StopBites       = new ObservableCollection <string>();
            Bits            = new ObservableCollection <int>()
            {
                5, 6, 7, 8
            };
            BaudRates = new ObservableCollection <int>()
            {
                50, 1200, 2400, 4800, 9600, 19200, 38400,
                56000, 57600, 76800, 115200, 230400, 460800
            };
            expectByteCount = 1;
            foreach (string name in SerialPort.GetPortNames())
            {
                SerialPortNames.Add(name);
            }

            foreach (string parityName in Enum.GetNames(typeof(Parity)))
            {
                Parities.Add(parityName);
            }

            foreach (string stopBitsName in Enum.GetNames(typeof(StopBits)))
            {
                StopBites.Add(stopBitsName);
            }
        }
示例#10
0
 private void CommandNew_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (TreeView_IntbusDevices.SelectedItem == null)
     {
         IntbusDevices.Add(new IntbusDevice(IntbusInterface, IntbusAddress)
         {
             Name = IntbusName
         });
     }
     else
     {
         IntbusDevice intbusDevice = TreeView_IntbusDevices.SelectedItem as IntbusDevice;
         intbusDevice.AddIntbusDevice(
             new IntbusDevice(
                 IntbusInterface.Clone() as IntbusInterface,
                 IntbusAddress)
         {
             Name = IntbusName
         }
             );
     }
 }