private void CommandCopy_Executed(object sender, ExecutedRoutedEventArgs e) { IntbusDevice intbusDevice = TreeView_IntbusDevices.SelectedItem as IntbusDevice; IntbusDeviceCloneBuffer = intbusDevice.Clone() as IntbusDevice; var a = IntbusDeviceCloneBuffer; }
public void AddIntbusDevice(IntbusDevice intbusDevice) { IntbusDevice clonedDevice = intbusDevice.Clone() as IntbusDevice; clonedDevice.MasterIntbusDevice = this; this.SlaveIntbusDevices.Add(clonedDevice); }
private void CommandPaste_Executed(object sender, ExecutedRoutedEventArgs e) { IntbusDevice intbusDevice = TreeView_IntbusDevices.SelectedItem as IntbusDevice; IntbusDevice copiedIntbusDevice = IntbusDeviceCloneBuffer; intbusDevice.AddIntbusDevice(copiedIntbusDevice); }
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); }
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); }
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; } } }
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); }
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; }
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); } }
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 } ); } }