Esempio n. 1
0
        }//关闭设备

        private async void BtnAddZigBee_Click(object sender, RoutedEventArgs e)
        {
            #region 配置串口
            var selection = ConnectDevices.SelectedItems;
            if (selection.Count <= 0)
            {
                return;
            }

            DeviceInformation entry = (DeviceInformation)selection[0];

            try
            {
                serialPort = await SerialDevice.FromIdAsync(entry.Id);

                if (serialPort == null)
                {
                    return;
                }
                serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
                serialPort.ReadTimeout  = TimeSpan.FromMilliseconds(1000);
                serialPort.BaudRate     = 9600;
                serialPort.Parity       = SerialParity.None;
                serialPort.StopBits     = SerialStopBitCount.One;
                serialPort.DataBits     = 8;
                serialPort.Handshake    = SerialHandshake.None;
                // Create cancellation token object to close I/O operations when closing the device
                ReadCancellationTokenSource = new CancellationTokenSource();
                Listen();
            }
            catch (Exception)
            { }
            #endregion

            DeviceModel Device = new DeviceModel
            {
                NetPort   = await DevicesMethod.GetPortNum() + 1,
                Type      = "照明系统",
                IPAddress = "Zigbee设备"
            };
            ViewDevModel DevObj = ModelConverter.DataToView(Device);
            Obj.Add(Device);
            DevicesMethod.UpdateDevices(Obj);
            gridView.Items.Add(DevObj);
            CreateLine(Device.NetPort);//绑定新通道
            btnAddZigBee.IsEnabled = false;
        }
Esempio n. 2
0
        }//向云上传数据

        #endregion

        #region 设备模型相关

        private async void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            string[] data = cmbIp.SelectedItem.ToString().Trim().Split(Convert.ToChar("/"));

            DeviceModel Device = new DeviceModel {
                NetPort   = await DevicesMethod.GetPortNum() + 1,
                Type      = data[1],
                IPAddress = data[0]
            };
            ViewDevModel DevObj = ModelConverter.DataToView(Device);

            Obj.Add(Device);
            DevicesMethod.UpdateDevices(Obj);
            gridView.Items.Add(DevObj);
            CreateLine(Device.NetPort); //绑定新通道
            SendAllow(Device.NetPort);  //发送端口允许
        }