示例#1
0
        // 添加
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            byte          addr   = list == null ? (byte)0 : list.LastOrDefault().Address;
            AddDeviceForm addfff = new AddDeviceForm(addr);

            if (addfff.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (!EquipmentDal.AddOne(addfff.mEquipment))
                {
                    LogLib.Log.GetLogger(this).Warn("插入失败");
                    XtraMessageBox.Show("添加设备失败");
                }
                else
                {
                    InitList();
                }
            }
        }
示例#2
0
        // 添加默认设备
        private void addDefultList()
        {
            try
            {
                using (WaitDialogForm wdf = new WaitDialogForm("正在读取数据 ...", "请耐心等待", new Size(200, 50), ParentForm))
                {
                    for (byte i = 1; i <= 29; i++)
                    {
                        Equipment ept = new Equipment();
                        ept.Name        = "VOC监控系统";
                        ept.Address     = i;
                        ept.SensorTypeB = "通道" + i;
                        ept.GasName     = "VOC";
                        ept.biNnum      = 1;
                        ept.UnitType    = 0;
                        ept.A1          = 200;
                        ept.A2          = 500;
                        ept.Max         = 30;
                        ept.Point       = 2;
                        ept.IsRegister  = true;

                        if (!EquipmentDal.AddOne(ept))
                        {
                            LogLib.Log.GetLogger(this).Warn("插入失败");
                            continue;
                        }
                    }
                    InitList();
                }
            }
            catch (Exception ex)
            {
                LogLib.Log.GetLogger(this).Warn(ex);
                XtraMessageBox.Show("添加失败");
                return;
            }
        }
示例#3
0
        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="name">设备名称</param>
        /// <param name="address">设备地址</param>
        private void Register(string name)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                for (byte i = 1; i < 21; i++)
                {
                    Command cd = new Command(i, (byte)EM_AdrType.气体浓度, 12);
                    if (CommandResult.GetResult(cd))
                    {
                        Equipment ept = new Equipment();
                        ept.Name        = name;
                        ept.Address     = i;
                        ept.SensorTypeB = "通道名称" + i;

                        byte[] temp1 = new byte[4];
                        Array.Copy(cd.ResultByte, 3, temp1, 0, 4);
                        ept.Chroma = ((temp1[0] << 24) | (temp1[1] << 16) | (temp1[2] << 8) | temp1[3]);



                        //int iValue;
                        byte[] bs = new byte[6];
                        Array.Copy(cd.ResultByte, 9, bs, 0, 6);
                        //string sValue;
                        //iValue = Convert.ToInt32("0C", 16); // 16进制->10进制
                        //bs = System.BitConverter.GetBytes(iValue); //int->byte[]
                        ept.GasName = (System.Text.Encoding.ASCII.GetString(bs)).Replace("\0", "");

                        Array.Reverse(cd.ResultByte, 15, 2);
                        ept.biNnum = BitConverter.ToUInt16(cd.ResultByte, 15);

                        Array.Reverse(cd.ResultByte, 17, 2);
                        ept.UnitType = BitConverter.ToUInt16(cd.ResultByte, 17);

                        byte[] temp = new byte[4];
                        Array.Copy(cd.ResultByte, 19, temp, 0, 4);
                        ept.A1 = ((temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3]) / ept.BigNum;

                        byte[] temp2 = new byte[4];
                        Array.Copy(cd.ResultByte, 23, temp2, 0, 4);
                        ept.A2 = ((temp2[0] << 24) | (temp2[1] << 16) | (temp2[2] << 8) | temp2[3]) / ept.BigNum;

                        //Array.Reverse(cd.ResultByte, 19, 2);
                        //Array.Reverse(cd.ResultByte, 21, 2);
                        //ept.A1 = BitConverter.ToSingle(cd.ResultByte, 19);

                        //Array.Reverse(cd.ResultByte, 23, 2);
                        //Array.Reverse(cd.ResultByte, 25, 2);
                        //ept.A2 = BitConverter.ToSingle(cd.ResultByte, 23);

                        ept.IsRegister = true;
                        if (!EquipmentDal.AddOne(ept))
                        {
                            Trace.WriteLine("插入失败");
                            LogLib.Log.GetLogger(this).Warn("插入失败");
                            continue;
                        }
                        sb.Append(ept.GasName + "\r\n");
                        Thread.Sleep(3000);
                    }

                    //// 有N个开着的传感器,就要往数据库里面插入N条记录
                    //foreach (EM_HighType sensor in Parse.GetSensorNum(rcd.ResultByte))
                    //{
                    //    Equipment ept = new Equipment();
                    //    ept.Name = name;
                    //    ept.Address = address;
                    //    ept.SensorType = sensor;

                    //    Command cd = new Command(address, (byte)sensor, (byte)EM_LowType_U.气体类型及单位, 1);
                    //    // 说明注册成功,存入数据库
                    //    if (!CommandResult.GetResult(cd))
                    //    {
                    //        Trace.WriteLine("添加失败");
                    //        LogLib.Log.GetLogger(this).Warn("添加失败");
                    //        continue;
                    //    }
                    //    ept.GasType = cd.ResultByte[3];
                    //    ept.UnitType = Parse.GetUnitType(cd.ResultByte);
                    //    ept.IsRegister = true;
                    //    if (!EquipmentDal.AddOne(ept))
                    //    {
                    //        Trace.WriteLine("插入失败");
                    //        LogLib.Log.GetLogger(this).Warn("插入失败");
                    //        continue;
                    //    }
                    //    sb.Append(ept.GasName + "\r\n");
                    //}
                }
                if (sb != null)
                {
                    XtraMessageBox.Show("添加成功:\r\n" + sb.ToString());
                }
                else
                {
                    XtraMessageBox.Show("添加失败");
                }
            }
            catch (Exception ex)
            {
                LogLib.Log.GetLogger(this).Warn(ex);
                XtraMessageBox.Show("添加失败");
                return;
            }
            // }
        }