Example #1
0
        public async Task SendCommandAsync()
        {
            string value;

            if (ProtocolCommand.Options is StringOptions options)
            {
                value = options.GetTermForValue(this.Value.ToString());
            }
            else if (Value is bool b)
            {
                value = b ? "1" : "0";
            }
            else
            {
                value = $"{Value}";
            }
            var path = ProtocolCommand.FormatPath();

            if (value.Length > 0)
            {
                await AppLocator.TelnetService.SendCommandAsync($"{path} {value}", false);
            }
            else
            {
                await AppLocator.TelnetService.SendCommandAsync(path, false);
            }
        }
        //切换信道
        void ThreadSwitch()
        {
            Thread.Sleep(3000);                                                                                                                                                                             //如果不延时,将占用CPU过高
            //设定延时任务 目的是避免在设置连续三次命令的时候插进去
            SerialSendMsg sendMsg = ProtocolCommand.TerminalSwitchCmdMsg(AppUtil.IntToBytes(ChangeNONewSerialNO_forChannal), AppUtil.IntToBytes(ChangeNONewSerialNO_forChannal), (byte)ChangeNONewChannal); //发送终端切换命令

            serialCom.SendQueue_Enqueue(sendMsg);                                                                                                                                                           //发送出去
        }
Example #3
0
        public string[] getCommandList()
        {
            string[] cmdList = new string[CommandList.Length];

            for (int i = 0; i < cmdList.Length; i++)
            {
                ProtocolCommand mycmd  = (ProtocolCommand)CommandList[i];
                string          comand = mycmd.ToString();
                string          temp   = string.Empty;
                for (int j = 0; j < comand.Length - 7; j++)
                {
                    temp += comand[j];
                }
                cmdList[i] = temp;
            }
            return(cmdList);
        }
Example #4
0
 public bool isNextStep(ProtocolCommand cmd)
 {
     if (currentStepNum + 1 < CommandList.Length)
     {
         if (CommandList[currentStepNum + 1] == (int)cmd || currentStepNum < 1)
         {
             return(true);
         }
         // if separated by a mix or transport command.  ignore trans or mix command
         else if (currentStepNum + 2 < CommandList.Length - 1)
         {
             if ((CommandList[currentStepNum + 1] == (int)ProtocolCommand.TransportCommand ||
                  CommandList[currentStepNum + 1] == (int)ProtocolCommand.TransportCommand) &&
                 CommandList[currentStepNum + 2] == (int)cmd)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        private void Form1_Load(object sender, EventArgs e)
        {
            // Prompt user for connection settings
            string        portName = GsmCommMain.DefaultPortName;
            int           baudRate = GsmCommMain.DefaultBaudRate;
            int           timeout  = GsmCommMain.DefaultTimeout;
            connectionFrm dlg      = new connectionFrm();

            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.SetData(portName, baudRate, timeout);
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                dlg.GetData(out portName, out baudRate, out timeout);
            }
            else
            {
                Close();
                return;
            }

            Cursor.Current          = Cursors.WaitCursor;
            comm                    = new GsmCommMain(portName, baudRate, timeout);
            Cursor.Current          = Cursors.Default;
            comm.PhoneConnected    += new EventHandler(comm_PhoneConnected);
            comm.PhoneDisconnected += new EventHandler(comm_PhoneDisconnected);

            bool retry;

            do
            {
                retry = false;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    comm.Open();
                    MessageRoutingON();
                    Cursor.Current = Cursors.Default;
                }
                catch (Exception)
                {
                    Cursor.Current = Cursors.Default;
                    if (MessageBox.Show(this, "Unable to open the port.", "Error",
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
                    {
                        retry = true;
                    }
                    else
                    {
                        Close();
                        return;
                    }
                }
            }while (retry);

            // Add custom commands
            ProtocolCommand[] commands = new ProtocolCommand[]
            {
                new ProtocolCommand("Send", true, false, false),                   // NeedsData
                new ProtocolCommand("Receive", false, false, false),
                new ProtocolCommand("ExecCommand", true, false, false),            // NeedsData
                new ProtocolCommand("ExecCommand2", true, false, true),            // NeedsData, NeedsError
                new ProtocolCommand("ExecAndReceiveMultiple", true, false, false), // NeedsData
                new ProtocolCommand("ExecAndReceiveAnything", true, true, false),  // NeedsData, NeedsPattern
                new ProtocolCommand("ReceiveMultiple", false, false, false),
                new ProtocolCommand("ReceiveAnyhing", false, true, false)          // NeedsPattern
            };
        }
Example #6
0
		public void Serialize (ProtocolCommand cmd)
		{
			Serialize ((byte) cmd);
		}
Example #7
0
        protected override void Seed(RepositoryDbContext dbContext)
        {
            var domain = new Domain
            {
                Id             = Guid.Parse("DB07AB5E-A23F-4238-94CE-D52411199C18"),
                DomainName     = "Root",
                DomianType     = DomainType.RootDomain,
                CreateDateTime = DateTime.Now,
                DomainStatus   = DomainStatus.Enabled,
                IsEnabled      = true
            };

            var user = new WdUser
            {
                Id             = Guid.Parse("77F05B52-AE62-4225-9F09-153C5634031F"),
                UserName       = "******",
                LoginName      = "Root",
                Password       = "******",
                Email          = "*****@*****.**",
                Telephone      = "18679361687",
                Status         = UserStatus.Enabled,
                CreateDateTime = DateTime.Now,
                DomainId       = domain.Id,
                Roles          = new List <WdRole>(),
                IsEnabled      = true
            };

            var commUser = new WdUser()
            {
                Id             = Guid.Parse("c8c95a88-5d5d-4e80-a2d6-3ff32d472bde"),
                UserName       = "******",
                LoginName      = "CommnicationServer",
                Password       = "******",
                Email          = "*****@*****.**",
                Telephone      = "18679361687",
                Status         = UserStatus.Enabled,
                CreateDateTime = DateTime.Now,
                DomainId       = domain.Id,
                Roles          = new List <WdRole>(),
                IsEnabled      = true
            };

            var role = new WdRole
            {
                Id             = Guid.Parse("650BFB4C-7277-484A-812E-6052F6DB71C7"),
                RoleName       = "Root",
                Users          = new List <WdUser>(),
                CreateDateTime = DateTime.Now,
                Status         = RoleStatus.Enabled,
                CreateUserId   = user.Id,
                DomainId       = domain.Id,
                IsEnabled      = true
            };

            var adminRole = new WdRole()
            {
                Id             = Guid.Parse("fce321ca-8761-44c4-8204-546dfa6134e1"),
                RoleName       = "Admin",
                Users          = new List <WdUser>(),
                CreateDateTime = DateTime.Now,
                Status         = RoleStatus.Enabled,
                CreateUserId   = user.Id,
                DomainId       = domain.Id,
                IsEnabled      = true
            };

            var serverRole = new WdRole()
            {
                Id             = Guid.Parse("a45ae4cd-d0ad-4cea-b666-6787a42b2b4d"),
                RoleName       = "Server",
                Users          = new List <WdUser>(),
                CreateDateTime = DateTime.Now,
                Status         = RoleStatus.Enabled,
                CreateUserId   = user.Id,
                DomainId       = domain.Id,
                IsEnabled      = true
            };

            user.CreateUserId             = user.Id;
            user.LastUpdateUserId         = user.Id;
            user.LastUpdateDateTime       = DateTime.Now;
            user.LastLoginDateTime        = DateTime.Now;
            commUser.CreateUserId         = user.Id;
            commUser.LastUpdateUserId     = user.Id;
            commUser.LastUpdateDateTime   = DateTime.Now;
            commUser.LastLoginDateTime    = DateTime.Now;
            domain.CreateUserId           = user.Id;
            domain.LastUpdateUserId       = user.Id;
            domain.LastUpdateDateTime     = DateTime.Now;
            role.CreateUserId             = user.Id;
            role.LastUpdateUserId         = user.Id;
            role.LastUpdateDateTime       = DateTime.Now;
            adminRole.CreateUserId        = user.Id;
            adminRole.LastUpdateUserId    = user.Id;
            adminRole.LastUpdateDateTime  = DateTime.Now;
            serverRole.CreateUserId       = user.Id;
            serverRole.LastUpdateUserId   = user.Id;
            serverRole.LastUpdateDateTime = DateTime.Now;
            user.Roles.Add(role);
            role.Users.Add(user);
            commUser.Roles.Add(serverRole);
            serverRole.Users.Add(commUser);

            dbContext.Users.Add(user);
            dbContext.Users.Add(commUser);
            dbContext.Roles.Add(role);
            dbContext.Roles.Add(adminRole);
            dbContext.Roles.Add(serverRole);
            dbContext.SysDomains.Add(domain);

            var field = new SysDictionary
            {
                Id                 = Guid.Parse("7402cdb5-1e1e-4633-a7e9-7d6d15634fc0"),
                ItemName           = "Field",
                ItemKey            = "7E0384B37CFJ",
                ItemValue          = "GpsCommunication",
                ItemLevel          = 1,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            var subfield = new SysDictionary
            {
                Id = Guid.Parse("24ae6ee7-a024-4052-a1de-3cc0d542d908"),
                ParentDictionaryId = field.Id,
                ItemName           = "Subield",
                ItemKey            = "7E0384B37CFL",
                ItemValue          = "GeneralFunction",
                ItemLevel          = 1,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            dbContext.SysDictionaries.Add(field);
            dbContext.SysDictionaries.Add(subfield);

            var deviceType = new DeviceType
            {
                Id                 = Guid.Parse("31b9ae77-6f5b-4c70-b180-d80ecb7df12b"),
                Field              = field,
                SubField           = subfield,
                Version            = "2016-03-17",
                ReleaseDateTime    = DateTime.Now,
                DeviceTypeCode     = "WD_YC_Classic",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            var firma = new Firmware
            {
                Id                 = Guid.Parse("648892a9-bf37-4490-a947-e1c0a529bba1"),
                FirmwareName       = "firma",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateUserId   = user.Id,
                LastUpdateDateTime = DateTime.Now,
                Protocols          = new List <Protocol>()
            };

            dbContext.Firmwares.Add(firma);

            var firmSet = new FirmwareSet
            {
                Id = Guid.Parse("6c36fddf-d3d9-416b-84df-cd849006eef1"),
                FirmwareSetName    = "扬尘第三版",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            firmSet.Firmwares.Add(firma);
            dbContext.FirmwareSets.Add(firmSet);

            dbContext.DeviceTypes.Add(deviceType);

            var nep = new Protocol
            {
                Id                 = Guid.Parse("f59022bc-6f8c-4ced-954f-3a6d7dd29335"),
                FieldId            = field.Id,
                SubFieldId         = subfield.Id,
                CustomerInfo       = "1",
                ProtocolName       = "Nep",
                ProtocolModule     = "Nep",
                Version            = "HT212",
                ReleaseDateTime    = DateTime.Now,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true,
                CheckType          = ProtocolCheckType.CrcModBus,
                Head               = new byte[] { 0x23, 0x23 },
                Tail               = new byte[] { 0x0D, 0x0A }
            };

            firma.Protocols.Add(nep);

            var head = new ProtocolStructure
            {
                Id                  = Guid.Parse("2bb54221-f036-48ff-babc-22358bdf50e2"),
                ProtocolId          = nep.Id,
                StructureName       = "Head",
                StructureIndex      = 0,
                StructureDataLength = 2,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[] { 0x23, 0x23 }
            };

            var contentLength = new ProtocolStructure
            {
                Id                  = Guid.Parse("277211ee-4ee9-4ef3-ab95-c43fce4c395b"),
                ProtocolId          = nep.Id,
                StructureName       = "ContentLength",
                StructureIndex      = 1,
                StructureDataLength = 4,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[0]
            };

            var requestNumber = new ProtocolStructure
            {
                Id                  = Guid.Parse("e64862bb-1427-45e6-9dda-ec7925963573"),
                ProtocolId          = nep.Id,
                StructureName       = "RequestNumber",
                StructureIndex      = 2,
                StructureDataLength = 21,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[0]
            };

            var cmdtype = new ProtocolStructure
            {
                Id                  = Guid.Parse("dcdb914f-62ec-42dc-bece-04124cfd61fa"),
                ProtocolId          = nep.Id,
                StructureName       = "CmdType",
                StructureIndex      = 3,
                StructureDataLength = 6,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[0]
            };

            var cmdbyte = new ProtocolStructure
            {
                Id                  = Guid.Parse("fa009ac1-8a08-4243-a143-eb7cb8942660"),
                ProtocolId          = nep.Id,
                StructureName       = "CmdByte",
                StructureIndex      = 4,
                StructureDataLength = 8,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[0]
            };

            var password = new ProtocolStructure()
            {
                Id                  = Guid.Parse("eddaa794-088a-4cc0-8c8e-b09635ba249a"),
                ProtocolId          = nep.Id,
                StructureName       = "Password",
                StructureIndex      = 5,
                StructureDataLength = 10,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[] { 0x50, 0x57, 0x3D, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x3B }
            };

            var nodeid = new ProtocolStructure()
            {
                Id                  = Guid.Parse("ff20af2c-8f93-4755-889f-e8943c023e7d"),
                ProtocolId          = nep.Id,
                StructureName       = "NodeId",
                StructureIndex      = 6,
                StructureDataLength = 18,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[0]
            };

            var data = new ProtocolStructure()
            {
                Id                  = Guid.Parse("4cde87be-468c-46cf-a1f9-0172f21761ca"),
                ProtocolId          = nep.Id,
                StructureName       = "Data",
                StructureIndex      = 7,
                StructureDataLength = 0,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.Data,
                DefaultBytes        = new byte[0]
            };

            var crcModBus = new ProtocolStructure()
            {
                Id                  = Guid.Parse("1bd5725a-0408-4c4a-b7ad-f2c92dd830e2"),
                ProtocolId          = nep.Id,
                StructureName       = "CrcModBus",
                StructureIndex      = 8,
                StructureDataLength = 4,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.CrcModBus,
                DefaultBytes        = new byte[] { 0x00, 0x00, 0x00, 0x00 }
            };

            var tail = new ProtocolStructure()
            {
                Id                  = Guid.Parse("6aea3080-bb97-4e50-8140-7c31728b1637"),
                ProtocolId          = nep.Id,
                StructureName       = "Tail",
                StructureIndex      = 9,
                StructureDataLength = 2,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.AsciiString,
                DefaultBytes        = new byte[] { 0x0D, 0x0A }
            };

            dbContext.ProtocolStructures.Add(head);
            dbContext.ProtocolStructures.Add(cmdtype);
            dbContext.ProtocolStructures.Add(cmdbyte);
            dbContext.ProtocolStructures.Add(password);
            dbContext.ProtocolStructures.Add(nodeid);
            dbContext.ProtocolStructures.Add(contentLength);
            dbContext.ProtocolStructures.Add(requestNumber);
            dbContext.ProtocolStructures.Add(data);
            dbContext.ProtocolStructures.Add(crcModBus);
            dbContext.ProtocolStructures.Add(tail);

            var commandReplyA = new SysConfig()
            {
                Id                 = Guid.Parse("b06c49c1-f9f7-4e69-92df-04fa55f95045"),
                SysConfigName      = ProtocolDeliveryParam.StoreData,
                SysConfigType      = SysConfigType.ProtocolDeliveryParam,
                SysConfigValue     = ProtocolDeliveryParam.StoreData,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            dbContext.SysConfigs.Add(commandReplyA);

            var command = new ProtocolCommand
            {
                Id = Guid.Parse("d2ccf8b0-ed68-48ef-b185-f94b504944ca"),
                CommandTypeCode            = new byte[] { 0x32, 0x32 },
                CommandCode                = new byte[] { 0x32, 0x30, 0x31, 0x31 },
                ReceiveBytesLength         = 0,
                CommandCategory            = CommandCategory.TimingAutoReport,
                DataOrderType              = DataOrderType.Random,
                ProtocolId                 = nep.Id,
                CommandDeliverParamConfigs = new List <SysConfig> {
                    commandReplyA
                },
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandA = new ProtocolCommand
            {
                Id = Guid.Parse("ec4260ba-b36d-40ab-b357-15345590f516"),
                CommandTypeCode            = new byte[] { 0x32, 0x32 },
                CommandCode                = new byte[] { 0x32, 0x30, 0x31, 0x31 },
                ReceiveBytesLength         = 0,
                CommandCategory            = CommandCategory.TimingAutoReport,
                DataOrderType              = DataOrderType.Random,
                ProtocolId                 = nep.Id,
                CommandDeliverParamConfigs = new List <SysConfig> {
                    commandReplyA
                },
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandB = new ProtocolCommand
            {
                Id = Guid.Parse("9fbc1163-abf1-4f49-9bb6-64bec7946670"),
                CommandTypeCode            = new byte[] { 0x32, 0x32 },
                CommandCode                = new byte[] { 0x32, 0x30, 0x31, 0x31 },
                ReceiveBytesLength         = 0,
                CommandCategory            = CommandCategory.TimingAutoReport,
                DataOrderType              = DataOrderType.Random,
                ProtocolId                 = nep.Id,
                CommandDeliverParamConfigs = new List <SysConfig> {
                    commandReplyA
                },
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var tsp = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a34001-Avg",
                DataDisplayName    = "粉尘",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var pm25 = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a34004-Avg",
                DataDisplayName    = "PM2.5",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var pm100 = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a34005-Avg",
                DataDisplayName    = "PM10",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var noise = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a50001-Avg",
                DataDisplayName    = "噪音",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var temp = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a01001-Avg",
                DataDisplayName    = "温度",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var huma = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a01002-Avg",
                DataDisplayName    = "湿度",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var windspeed = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a01007-Avg",
                DataDisplayName    = "风速",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var winddir = new CommandData
            {
                Id                 = Guid.NewGuid(),
                DataIndex          = 0,
                DataLength         = 0,
                DataName           = "a01008-Avg",
                DataDisplayName    = "风向",
                DataConvertType    = "DoubleString",
                DataValueType      = DataValueType.Double,
                DataFlag           = 0x00,
                ValidFlagIndex     = 0,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            command.CommandDatas = new List <CommandData> {
                tsp, pm25, pm100, noise, temp, huma, windspeed, winddir
            };
            commandA.CommandDatas = new List <CommandData> {
                tsp, pm25, pm100, noise, temp, huma, windspeed, winddir
            };
            commandB.CommandDatas = new List <CommandData> {
                tsp, pm25, pm100, noise, temp, huma, windspeed, winddir
            };
            dbContext.ProtocolCommands.Add(command);
            dbContext.ProtocolCommands.Add(commandA);
            dbContext.ProtocolCommands.Add(commandB);

            var dev = new Device()
            {
                Id               = Guid.NewGuid(),
                DeviceTypeId     = deviceType.Id,
                DeviceCode       = "扬尘硬件第三版测试一号",
                DevicePassword   = string.Empty,
                DeviceModuleGuid = Guid.NewGuid(),
                DeviceNodeId     = "KSHBZBWCOM0001",
                FirmwareSetId    = firmSet.Id,
                StartTime        = DateTime.Now,
                PreEndTime       = DateTime.Now,
                EndTime          = DateTime.Now,
                Status           = DeviceStatus.Enabled,
                DomainId         = domain.Id,
                CreateUserId     = user.Id,
                CreateDateTime   = DateTime.Now,
                IsEnabled        = true
            };

            dbContext.Devices.Add(dev);
        }
Example #8
0
 public void Serialize(ProtocolCommand cmd)
 {
     Serialize((byte)cmd);
 }
Example #9
0
 /// <summary>
 /// 对指定的指令进行编码
 /// </summary>
 /// <param name="command"></param>
 /// <param name="paramBytes"></param>
 /// <returns></returns>
 public byte[] Encode(ProtocolCommand command, Dictionary <string, byte[]> paramBytes = null)
 => EncodeProtocol(command, paramBytes);
Example #10
0
        //确认临时编组按钮点击事件
        void btnTempGroupOK_Click(object sender, EventArgs e)
        {
            //先判断用户输入的格式对不对
            //检查原组号是否是数字
            if (RegexUtil.RegexCheckNumber(richTextTempOldGrpNO.Text))
            {
                //检查原组号是否超出范围
                if (int.Parse(richTextTempOldGrpNO.Text) < 0xFFFFFF)
                {
                    //检查新组号是否是数字
                    if (RegexUtil.RegexCheckNumber(richTextTempNewGrpNO.Text))
                    {
                        //检查新组号是否超出范围
                        if (int.Parse(richTextTempNewGrpNO.Text) < 0xFFFFFF)
                        {
                            //检查原用户号是否是数字
                            if (RegexUtil.RegexCheckNumber(richTextTempOldDevNO.Text))
                            {
                                //检查原用户号是否超出范围
                                if (int.Parse(richTextTempOldDevNO.Text) < 33)
                                {
                                    //检查新用户号是否是数字
                                    if (RegexUtil.RegexCheckNumber(richTextTempNewDevNO.Text))
                                    {
                                        //检查新用户号是否超出范围
                                        if (int.Parse(richTextTempNewDevNO.Text) < 33)
                                        {
                                            //全部检查完毕没有问题
                                            richTextTempGroupStatus.Text = "";                                                          //状态栏清空
                                            TempGrpOldSerialNO           = (int.Parse(richTextTempOldGrpNO.Text) << 8) | (int.Parse(richTextTempOldDevNO.Text));
                                            TempGrpNewSerialNO           = (int.Parse(richTextTempNewGrpNO.Text) << 8) | (int.Parse(richTextTempNewDevNO.Text));

                                            //发送临时组队命令
                                            SerialSendMsg sendMsg = ProtocolCommand.BuildTeamCmdMsg(AppUtil.IntToBytes(TempGrpOldSerialNO),
                                                                                                    AppUtil.IntToBytes(TempGrpNewSerialNO),
                                                                                                    SysConfig.getSerialNOBytes());
                                            serialCom.SendQueue_Enqueue(sendMsg);                                               //发送出去
                                            //写入按钮点击记录
                                            worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.TempGrpPanel, (int)BtnOfTempGrpPanel.StartTempGrp, TempGrpOldSerialNO.ToString("X8") + " " + TempGrpNewSerialNO.ToString("X8")));
                                        }
                                        else
                                        {
                                            MessageBox.Show("新用户号必须小于33");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("新用户号必须为数字形式");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("原用户号必须小于33");
                                }
                            }
                            else
                            {
                                MessageBox.Show("原用户号必须为数字形式");
                            }
                        }
                        else
                        {
                            MessageBox.Show("新组号必须小于16777215");
                        }
                    }
                    else
                    {
                        MessageBox.Show("新组号必须为数字形式");
                    }
                }
                else
                {
                    MessageBox.Show("原组号必须小于16777215");
                }
            }
            else
            {
                MessageBox.Show("原组号必须为数字形式");
            }
        }
Example #11
0
 public void Send(ProtocolCommand command, Dictionary <string, byte[]> paramBytes = null)
 => Send(_protocolEncoder.Encode(command, paramBytes));
        protected override void Seed(RepositoryDbContext dbContext)
        {
            var domain = new Domain
            {
                Id             = Guid.Parse("DB07AB5E-A23F-4238-94CE-D52411199C18"),
                DomainName     = "Root",
                DomianType     = DomainType.RootDomain,
                CreateDateTime = DateTime.Now,
                DomainStatus   = DomainStatus.Enabled,
                IsEnabled      = true
            };

            var user = new WdUser
            {
                Id             = Guid.Parse("77F05B52-AE62-4225-9F09-153C5634031F"),
                UserName       = "******",
                LoginName      = "Root",
                Password       = "******",
                Email          = "*****@*****.**",
                Telephone      = "18679361687",
                Status         = UserStatus.Enabled,
                CreateDateTime = DateTime.Now,
                DomainId       = domain.Id,
                Roles          = new List <WdRole>(),
                IsEnabled      = true
            };

            var commUser = new WdUser()
            {
                Id             = Guid.Parse("c8c95a88-5d5d-4e80-a2d6-3ff32d472bde"),
                UserName       = "******",
                LoginName      = "CommnicationServer",
                Password       = "******",
                Email          = "*****@*****.**",
                Telephone      = "18679361687",
                Status         = UserStatus.Enabled,
                CreateDateTime = DateTime.Now,
                DomainId       = domain.Id,
                Roles          = new List <WdRole>(),
                IsEnabled      = true
            };

            var role = new WdRole
            {
                Id             = Guid.Parse("650BFB4C-7277-484A-812E-6052F6DB71C7"),
                RoleName       = "Root",
                Users          = new List <WdUser>(),
                CreateDateTime = DateTime.Now,
                Status         = RoleStatus.Enabled,
                CreateUserId   = user.Id,
                DomainId       = domain.Id,
                IsEnabled      = true
            };

            var adminRole = new WdRole()
            {
                Id             = Guid.Parse("fce321ca-8761-44c4-8204-546dfa6134e1"),
                RoleName       = "Admin",
                Users          = new List <WdUser>(),
                CreateDateTime = DateTime.Now,
                Status         = RoleStatus.Enabled,
                CreateUserId   = user.Id,
                DomainId       = domain.Id,
                IsEnabled      = true
            };

            var serverRole = new WdRole()
            {
                Id             = Guid.Parse("a45ae4cd-d0ad-4cea-b666-6787a42b2b4d"),
                RoleName       = "Server",
                Users          = new List <WdUser>(),
                CreateDateTime = DateTime.Now,
                Status         = RoleStatus.Enabled,
                CreateUserId   = user.Id,
                DomainId       = domain.Id,
                IsEnabled      = true
            };

            user.CreateUserId             = user.Id;
            user.LastUpdateUserId         = user.Id;
            user.LastUpdateDateTime       = DateTime.Now;
            user.LastLoginDateTime        = DateTime.Now;
            commUser.CreateUserId         = user.Id;
            commUser.LastUpdateUserId     = user.Id;
            commUser.LastUpdateDateTime   = DateTime.Now;
            commUser.LastLoginDateTime    = DateTime.Now;
            domain.CreateUserId           = user.Id;
            domain.LastUpdateUserId       = user.Id;
            domain.LastUpdateDateTime     = DateTime.Now;
            role.CreateUserId             = user.Id;
            role.LastUpdateUserId         = user.Id;
            role.LastUpdateDateTime       = DateTime.Now;
            adminRole.CreateUserId        = user.Id;
            adminRole.LastUpdateUserId    = user.Id;
            adminRole.LastUpdateDateTime  = DateTime.Now;
            serverRole.CreateUserId       = user.Id;
            serverRole.LastUpdateUserId   = user.Id;
            serverRole.LastUpdateDateTime = DateTime.Now;
            user.Roles.Add(role);
            role.Users.Add(user);
            commUser.Roles.Add(serverRole);
            serverRole.Users.Add(commUser);

            dbContext.Users.Add(user);
            dbContext.Users.Add(commUser);
            dbContext.Roles.Add(role);
            dbContext.Roles.Add(adminRole);
            dbContext.Roles.Add(serverRole);
            dbContext.SysDomains.Add(domain);

            var field = new SysDictionary
            {
                Id                 = Guid.Parse("7402cdb5-1e1e-4633-a7e9-7d6d15634fc0"),
                ItemName           = "Field",
                ItemKey            = "7E0384B37CFJ",
                ItemValue          = "GpsCommunication",
                ItemLevel          = 1,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            var subfield = new SysDictionary
            {
                Id = Guid.Parse("24ae6ee7-a024-4052-a1de-3cc0d542d908"),
                ParentDictionaryId = field.Id,
                ItemName           = "Subield",
                ItemKey            = "7E0384B37CFL",
                ItemValue          = "GeneralFunction",
                ItemLevel          = 1,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            dbContext.SysDictionaries.Add(field);
            dbContext.SysDictionaries.Add(subfield);

            var deviceType = new DeviceType
            {
                Id                 = Guid.Parse("31b9ae77-6f5b-4c70-b180-d80ecb7df12b"),
                Field              = field,
                SubField           = subfield,
                Version            = "2016-03-17",
                ReleaseDateTime    = DateTime.Now,
                DeviceTypeCode     = "WD_YC_Classic",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            var firma = new Firmware
            {
                Id                 = Guid.Parse("648892a9-bf37-4490-a947-e1c0a529bba1"),
                FirmwareName       = "firma",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateUserId   = user.Id,
                LastUpdateDateTime = DateTime.Now,
                Protocols          = new List <Protocol>()
            };

            dbContext.Firmwares.Add(firma);

            var firmSet = new FirmwareSet
            {
                Id = Guid.Parse("6c36fddf-d3d9-416b-84df-cd849006eef1"),
                FirmwareSetName    = "扬尘第三版",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true
            };

            firmSet.Firmwares.Add(firma);
            dbContext.FirmwareSets.Add(firmSet);

            dbContext.DeviceTypes.Add(deviceType);

            var classic = new Protocol
            {
                Id                 = Guid.Parse("f59022bc-6f8c-4ced-954f-3a6d7dd29335"),
                FieldId            = field.Id,
                SubFieldId         = subfield.Id,
                CustomerInfo       = "1",
                ProtocolName       = "Classic",
                ProtocolModule     = "Classic",
                Version            = "Dust Protocol Brief V0017",
                ReleaseDateTime    = DateTime.Now,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true,
                CheckType          = ProtocolCheckType.Crc16,
                Head               = new byte[] { 0xAA },
                Tail               = new byte[] { 0xDD }
            };

            firma.Protocols.Add(classic);

            var head = new ProtocolStructure
            {
                Id                  = Guid.Parse("2bb54221-f036-48ff-babc-22358bdf50e2"),
                ProtocolId          = classic.Id,
                StructureName       = "Head",
                StructureIndex      = 0,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.SingleByte,
                DefaultBytes        = new byte[] { 0xAA }
            };

            var cmdtype = new ProtocolStructure
            {
                Id                  = Guid.Parse("dcdb914f-62ec-42dc-bece-04124cfd61fa"),
                ProtocolId          = classic.Id,
                StructureName       = "CmdType",
                StructureIndex      = 1,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.SingleByte,
                DefaultBytes        = new byte[0]
            };

            var cmdbyte = new ProtocolStructure
            {
                Id                  = Guid.Parse("fa009ac1-8a08-4243-a143-eb7cb8942660"),
                ProtocolId          = classic.Id,
                StructureName       = "CmdByte",
                StructureIndex      = 2,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.SingleByte,
                DefaultBytes        = new byte[0]
            };

            var password = new ProtocolStructure()
            {
                Id                  = Guid.Parse("eddaa794-088a-4cc0-8c8e-b09635ba249a"),
                ProtocolId          = classic.Id,
                StructureName       = "Password",
                StructureIndex      = 3,
                StructureDataLength = 8,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.NumPassword,
                DefaultBytes        = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 }
            };

            var nodeid = new ProtocolStructure()
            {
                Id                  = Guid.Parse("ff20af2c-8f93-4755-889f-e8943c023e7d"),
                ProtocolId          = classic.Id,
                StructureName       = "NodeId",
                StructureIndex      = 4,
                StructureDataLength = 4,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.NodeId,
                DefaultBytes        = new byte[0]
            };

            var descrip = new ProtocolStructure()
            {
                Id                  = Guid.Parse("92006a07-3726-4cdc-99a4-7b3fdf7ef03d"),
                ProtocolId          = classic.Id,
                StructureName       = "Description",
                StructureIndex      = 5,
                StructureDataLength = 12,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.Description,
                DefaultBytes        = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
            };

            var sourceaddr = new ProtocolStructure()
            {
                Id                  = Guid.Parse("9ccdffd7-7d22-43d1-9185-a58541ce87f8"),
                ProtocolId          = classic.Id,
                StructureName       = "SourceAddr",
                StructureIndex      = 6,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.SourceAddr,
                DefaultBytes        = new byte[] { 0x01 }
            };

            var destination = new ProtocolStructure()
            {
                Id                  = Guid.Parse("20ddc634-6ce6-47cc-82e1-c3df8f68abaa"),
                ProtocolId          = classic.Id,
                StructureName       = "DestinationAddr",
                StructureIndex      = 7,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.Destination,
                DefaultBytes        = new byte[] { 0x01 }
            };

            var datalength = new ProtocolStructure()
            {
                Id                  = Guid.Parse("ad465018-24d3-400d-b7d5-712abf54ceeb"),
                ProtocolId          = classic.Id,
                StructureName       = "PayloadLength",
                StructureIndex      = 8,
                StructureDataLength = 2,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.DataLength,
                DefaultBytes        = new byte[] { 0x00, 0x00 }
            };

            var data = new ProtocolStructure()
            {
                Id                  = Guid.Parse("4cde87be-468c-46cf-a1f9-0172f21761ca"),
                ProtocolId          = classic.Id,
                StructureName       = "Data",
                StructureIndex      = 9,
                StructureDataLength = 0,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.Data,
                DefaultBytes        = new byte[0]
            };

            var crc = new ProtocolStructure()
            {
                Id                  = Guid.Parse("1bd5725a-0408-4c4a-b7ad-f2c92dd830e2"),
                ProtocolId          = classic.Id,
                StructureName       = "CRCValue",
                StructureIndex      = 10,
                StructureDataLength = 2,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.CRC,
                DefaultBytes        = new byte[] { 0x00, 0x00 }
            };

            var tail = new ProtocolStructure()
            {
                Id                  = Guid.Parse("6aea3080-bb97-4e50-8140-7c31728b1637"),
                ProtocolId          = classic.Id,
                StructureName       = "Tail",
                StructureIndex      = 11,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.SingleByte,
                DefaultBytes        = new byte[] { 0xDD }
            };

            dbContext.ProtocolStructures.Add(head);
            dbContext.ProtocolStructures.Add(cmdtype);
            dbContext.ProtocolStructures.Add(cmdbyte);
            dbContext.ProtocolStructures.Add(password);
            dbContext.ProtocolStructures.Add(nodeid);
            dbContext.ProtocolStructures.Add(descrip);
            dbContext.ProtocolStructures.Add(sourceaddr);
            dbContext.ProtocolStructures.Add(destination);
            dbContext.ProtocolStructures.Add(datalength);
            dbContext.ProtocolStructures.Add(data);
            dbContext.ProtocolStructures.Add(crc);
            dbContext.ProtocolStructures.Add(tail);

            var commandReply = new SysConfig()
            {
                Id                 = Guid.Parse("6ca98eba-47df-45c3-9bfb-1b56865b0a11"),
                SysConfigName      = ProtocolDeliveryParam.ReplyOriginal,
                SysConfigType      = SysConfigType.ProtocolDeliveryParam,
                SysConfigValue     = ProtocolDeliveryParam.ReplyOriginal,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };


            var commandReplyA = new SysConfig()
            {
                Id                 = Guid.Parse("b06c49c1-f9f7-4e69-92df-04fa55f95045"),
                SysConfigName      = ProtocolDeliveryParam.StoreData,
                SysConfigType      = SysConfigType.ProtocolDeliveryParam,
                SysConfigValue     = ProtocolDeliveryParam.StoreData,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var messageSource = new SysConfig
            {
                Id                 = Guid.Parse("34EDC4EC-F046-418E-A9DC-9EA3EA284F84"),
                SysConfigName      = "CommandMessageQueueName",
                SysConfigType      = SysConfigType.ProtocolAdminTools,
                SysConfigValue     = @"FormatName:Direct=TCP:121.40.49.97\private$\protocolcommand",
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            dbContext.SysConfigs.Add(commandReply);
            dbContext.SysConfigs.Add(commandReplyA);
            dbContext.SysConfigs.Add(messageSource);

            var commandDataA = new CommandData()
            {
                Id                 = Guid.Parse("46225dc9-ffe2-43af-bba4-7b45bbb55af2"),
                DataIndex          = 0,
                DataLength         = 2,
                DataName           = ProtocolDataName.DataValidFlag,
                DataConvertType    = ProtocolDataType.TwoBytesToUShort,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataB = new CommandData()
            {
                Id                 = Guid.Parse("489287c6-e179-4864-bd02-7f8962d5e81c"),
                DataIndex          = 1,
                DataLength         = 4,
                DataName           = "PM2.5",
                DataConvertType    = ProtocolDataType.FourBytesToUInt32,
                ValidFlagIndex     = 1,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataC = new CommandData()
            {
                Id                 = Guid.Parse("b69c75a5-c813-42a6-a3a6-5eeef561c068"),
                DataIndex          = 2,
                DataLength         = 4,
                DataName           = "PM10",
                DataConvertType    = ProtocolDataType.FourBytesToUInt32,
                ValidFlagIndex     = 1,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataD = new CommandData()
            {
                Id                 = Guid.Parse("36b4d5eb-b141-4cfd-9df5-d4508103fbbf"),
                DataIndex          = 3,
                DataLength         = 4,
                DataName           = "CPM",
                DataConvertType    = ProtocolDataType.FourBytesToUInt32,
                ValidFlagIndex     = 2,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataE = new CommandData()
            {
                Id                 = Guid.Parse("57874a4a-9a91-42dd-86de-e8940ad92c10"),
                DataIndex          = 4,
                DataLength         = 2,
                DataName           = "噪音值",
                DataConvertType    = ProtocolDataType.TwoBytesToDoubleSeparate,
                ValidFlagIndex     = 3,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataF = new CommandData()
            {
                Id                 = Guid.Parse("7e175d64-be72-48ed-baf2-549f80c27319"),
                DataIndex          = 5,
                DataLength         = 3,
                DataName           = "风向",
                DataConvertType    = ProtocolDataType.ThreeBytesToUShort,
                ValidFlagIndex     = 4,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataG = new CommandData()
            {
                Id                 = Guid.Parse("0c9124b1-168d-4510-bd8b-1acd183895a3"),
                DataIndex          = 6,
                DataLength         = 3,
                DataName           = "风速",
                DataConvertType    = ProtocolDataType.ThreeBytesToUShort,
                ValidFlagIndex     = 5,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataH = new CommandData()
            {
                Id                 = Guid.Parse("dc8815aa-0203-4c82-a09a-73521bcf208b"),
                DataIndex          = 7,
                DataLength         = 2,
                DataName           = "温度",
                DataConvertType    = ProtocolDataType.TwoBytesToDoubleSeparate,
                ValidFlagIndex     = 6,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataI = new CommandData()
            {
                Id                 = Guid.Parse("1ff2c99a-e0af-4419-80f6-53e69574d2c4"),
                DataIndex          = 8,
                DataLength         = 2,
                DataName           = "湿度",
                DataConvertType    = ProtocolDataType.TwoBytesToDoubleSeparate,
                ValidFlagIndex     = 6,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandDataJ = new CommandData()
            {
                Id                 = Guid.Parse("d24a7c0b-05f1-4a3f-b82c-6a5615ccdfc5"),
                DataIndex          = 9,
                DataLength         = 4,
                DataName           = "挥发性有机物",
                DataConvertType    = ProtocolDataType.FourBytesToUInt32,
                ValidFlagIndex     = 7,
                CreateDateTime     = DateTime.Now,
                CreateUserId       = user.Id,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var command = new ProtocolCommand
            {
                Id = Guid.Parse("d2ccf8b0-ed68-48ef-b185-f94b504944ca"),
                CommandTypeCode            = new byte[] { 0xF9 },
                CommandCode                = new byte[] { 0x1F },
                ReceiveBytesLength         = 0,
                CommandCategory            = CommandCategory.HeartBeat,
                ProtocolId                 = classic.Id,
                CommandDeliverParamConfigs = new List <SysConfig> {
                    commandReply
                },
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id
            };

            var commandA = new ProtocolCommand
            {
                Id = Guid.Parse("29b2f9c1-a79b-4598-bc33-2b4c20488159"),
                CommandTypeCode            = new byte[] { 0xFD },
                CommandCode                = new byte[] { 0x27 },
                ReceiveBytesLength         = 30,
                CommandCategory            = CommandCategory.TimingAutoReport,
                ProtocolId                 = classic.Id,
                CommandDeliverParamConfigs = new List <SysConfig> {
                    commandReplyA
                },
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                CommandDatas       = new List <CommandData>()
            };

            var commandB = new ProtocolCommand
            {
                Id = Guid.Parse("52FD2857-1607-4AD6-86C9-AC6B2B75BBB6"),
                CommandTypeCode            = new byte[] { 0xFC },
                CommandCode                = new byte[] { 0x1F },
                ReceiveBytesLength         = 0,
                CommandCategory            = CommandCategory.DeviceControl,
                ProtocolId                 = classic.Id,
                CommandDeliverParamConfigs = new List <SysConfig>(),
                CreateUserId               = user.Id,
                CreateDateTime             = DateTime.Now,
                LastUpdateDateTime         = DateTime.Now,
                LastUpdateUserId           = user.Id,
                CommandDatas               = new List <CommandData>()
            };

            commandA.CommandDatas.Add(commandDataA);
            commandA.CommandDatas.Add(commandDataB);
            commandA.CommandDatas.Add(commandDataC);
            commandA.CommandDatas.Add(commandDataD);
            commandA.CommandDatas.Add(commandDataE);
            commandA.CommandDatas.Add(commandDataF);
            commandA.CommandDatas.Add(commandDataG);
            commandA.CommandDatas.Add(commandDataH);
            commandA.CommandDatas.Add(commandDataI);
            commandA.CommandDatas.Add(commandDataJ);

            dbContext.ProtocolCommands.Add(command);
            dbContext.ProtocolCommands.Add(commandA);
            dbContext.ProtocolCommands.Add(commandB);

            var lampblack = new Protocol
            {
                Id                 = Guid.Parse("ea38e48c-1df2-4bfb-8917-7f736795bdc3"),
                FieldId            = field.Id,
                SubFieldId         = subfield.Id,
                CustomerInfo       = "1",
                ProtocolName       = "Lampblack",
                ProtocolModule     = "Lampblack",
                Version            = "Lampblack_Protocol_V0001",
                ReleaseDateTime    = DateTime.Now,
                CreateUserId       = user.Id,
                CreateDateTime     = DateTime.Now,
                LastUpdateDateTime = DateTime.Now,
                LastUpdateUserId   = user.Id,
                IsEnabled          = true,
                CheckType          = ProtocolCheckType.Lrc,
                Head               = new byte[] { 0x3A },
                Tail               = new byte[] { 0x0D, 0x0A }
            };

            dbContext.Protocols.Add(lampblack);

            var lbHead = new ProtocolStructure()
            {
                Id                  = Guid.Parse("a47ffc76-30ed-4d94-84d7-74540c51d9c4"),
                ProtocolId          = lampblack.Id,
                StructureName       = "Head",
                StructureIndex      = 0,
                StructureDataLength = 1,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.SingleByte,
                DefaultBytes        = new byte[] { 0x3A }
            };

            var lbFunctionCode = new ProtocolStructure()
            {
                Id                  = Guid.Parse("b9c7a5ef-d6ec-43e8-bdec-edcddbc8d4bb"),
                ProtocolId          = lampblack.Id,
                StructureName       = "FunctionCode",
                StructureIndex      = 1,
                StructureDataLength = 2,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.FunctionCode,
                DefaultBytes        = new byte[0]
            };

            var lbDeviceNodeId = new ProtocolStructure()
            {
                Id                  = Guid.Parse("a98f5e06-5093-4ab9-9762-5dacc4bdaf73"),
                ProtocolId          = lampblack.Id,
                StructureName       = "DeviceNodeId",
                StructureIndex      = 2,
                StructureDataLength = 7,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.NodeId,
                DefaultBytes        = new byte[0]
            };

            var lbData = new ProtocolStructure()
            {
                Id                  = Guid.Parse("c3ec8746-7c23-43bd-9cf8-a0db19c29655"),
                ProtocolId          = lampblack.Id,
                StructureName       = "Data",
                StructureIndex      = 3,
                StructureDataLength = 0,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.Data,
                DefaultBytes        = new byte[0]
            };

            var lbAscTime = new ProtocolStructure()
            {
                Id                  = Guid.Parse("d9c5172a-233b-4ea8-b064-297bc9c8fb75"),
                ProtocolId          = lampblack.Id,
                StructureName       = "ASCTime",
                StructureIndex      = 4,
                StructureDataLength = 14,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.ASCTime,
                DefaultBytes        = new byte[0]
            };

            var lbLrc = new ProtocolStructure()
            {
                Id                  = Guid.Parse("3e8b6176-19b0-4b0b-8635-a9a995799da4"),
                ProtocolId          = lampblack.Id,
                StructureName       = "LRCValue",
                StructureIndex      = 5,
                StructureDataLength = 3,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.LRC,
                DefaultBytes        = new byte[0]
            };

            var lbTail = new ProtocolStructure()
            {
                Id                  = Guid.Parse("56d4150a-7a22-4c74-8a22-9bc6b3bb70f7"),
                ProtocolId          = lampblack.Id,
                StructureName       = "Tail",
                StructureIndex      = 6,
                StructureDataLength = 2,
                CreateUserId        = user.Id,
                CreateDateTime      = DateTime.Now,
                LastUpdateDateTime  = DateTime.Now,
                LastUpdateUserId    = user.Id,
                IsEnabled           = true,
                DataType            = ProtocolDataType.Bytes,
                DefaultBytes        = new byte[] { 0x0D, 0x0A }
            };

            dbContext.ProtocolStructures.Add(lbHead);
            dbContext.ProtocolStructures.Add(lbFunctionCode);
            dbContext.ProtocolStructures.Add(lbDeviceNodeId);
            dbContext.ProtocolStructures.Add(lbData);
            dbContext.ProtocolStructures.Add(lbAscTime);
            dbContext.ProtocolStructures.Add(lbLrc);
            dbContext.ProtocolStructures.Add(lbTail);

            //var devices = new List<Device>();
            //for (var i = 0; i < 1000; i++)
            //{
            //    var dev = new Device()
            //    {
            //        Id = Guid.NewGuid(),
            //        DeviceTypeId = deviceType.Id,
            //        DeviceCode = "扬尘硬件第三版测试一号",
            //        DevicePassword = string.Empty,
            //        DeviceModuleGuid = Guid.NewGuid(),
            //        DeviceNodeId = (i + 1000).ToString("X8"),
            //        FirmwareSetId = firmSet.Id,
            //        StartTime = DateTime.Now,
            //        PreEndTime = DateTime.Now,
            //        EndTime = DateTime.Now,
            //        Status = DeviceStatus.Enabled,
            //        DomainId = domain.Id,
            //        CreateUserId = user.Id,
            //        CreateDateTime = DateTime.Now,
            //        IsEnabled = true
            //    };

            //    dbContext.Devices.Add(dev);
            //}
        }
Example #13
0
 //修改组号
 void btnSysSetGrpNOOK_Click(object sender, EventArgs e)
 {
     if (richTextSysSetGrpNO.Enabled == true)
     {
         //验证组号格式是否正确(即是否是小于16777215的纯数字)
         if (RegexUtil.RegexCheckNumber(richTextSysSetGrpNO.Text))
         {
             int GrpNO = int.Parse(richTextSysSetGrpNO.Text);
             if ((GrpNO > 0) && (GrpNO < 16777215))
             {
                 richTextSysSetGrpNO.Text      = GrpNO.ToString("D8");
                 richTextSysSetGrpNO.Enabled   = false;
                 SysConfig.Setting.groupNumber = GrpNO;
                 labelGrpNumber.Text           = "组号:" + SysConfig.Setting.groupNumber.ToString("D8");
                 SysConfig.SaveSystemSetting(SysConfig.Setting);
                 //写入组号修改记录
                 worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.ChangeGrpNO, richTextSysSetGrpNO.Text));
                 isSerialShouldOpen = true;
             }
             else
             {
                 MessageBox.Show("请输入小于16777215的组号");
             }
         }
         else
         {
             MessageBox.Show("请输入正确的组号格式");
         }
         //验证信道格式是否正确(即是否是小于30的纯数字)
         if (RegexUtil.RegexCheckNumber(richTextSysSetChannal.Text))
         {
             int Channal = int.Parse(richTextSysSetChannal.Text);
             if ((Channal > 0) && (Channal < 30) && (Channal < 23 || Channal > 25))
             {
                 richTextSysSetChannal.Text    = Channal.ToString("D8");
                 richTextSysSetChannal.Enabled = false;
                 SysConfig.Setting.channal     = Channal;
                 labelChannel.Text             = "信道:" + SysConfig.Setting.channal.ToString("D2");
                 SysConfig.SaveSystemSetting(SysConfig.Setting);
                 //写入组号修改记录
                 //worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.SysSettingPanel, (int)BtnOfSysSettingPanel.ChangeGrpNO, richTextSysSetGrpNO.Text));
                 isSerialShouldOpen = true;
                 //串口通信配置
                 //string comName = AppUtil.FindComByKeyStr(ComKeyStr);		//查找包含关键字的COM号
                 if (SysConfig.Setting.serialCom != null)
                 {
                     if (serialCom.ComOpen(SysConfig.Setting.serialCom, SerialBaudLUT[SysConfig.Setting.serialBaud]))//若打开串口成功
                     {
                         //写入串口连接记录到日志文件中
                         worklog.LogQueue_Enqueue(LogCommand.getSerialRecord(SerialRecordType.Connect, null));
                         serialCom.SendQueue_Enqueue(ProtocolCommand.SwitchChannelMsg((byte)(SysConfig.Setting.channal)));  //切换信道
                     }
                 }
                 else
                 {
                     MessageBox.Show("打开串口失败!");
                 }
             }
             else
             {
                 MessageBox.Show("请输入小于30的信道号 并且不为 23 24 25");
             }
         }
         else
         {
             MessageBox.Show("请输入正确的组号格式");
         }
     }
 }
 //确认改号按钮点击事件
 void btnUserChangeNOOK_Click(object sender, EventArgs e)
 {
     //先判断用户输入的格式对不对
     //检查原组号是否是数字
     if (RegexUtil.RegexCheckNumber(richTextOldGrpNO.Text))
     {
         //检查原组号是否超出范围
         if (int.Parse(richTextOldGrpNO.Text) < 0xFFFFFF)
         {
             //检查新组号是否是数字
             if (RegexUtil.RegexCheckNumber(richTextNewGrpNO.Text))
             {
                 //检查新组号是否超出范围
                 if (int.Parse(richTextNewGrpNO.Text) < 0xFFFFFF)
                 {
                     //检查原用户号是否是数字
                     if (RegexUtil.RegexCheckNumber(richTextOldDevNO.Text))
                     {
                         //检查原用户号是否超出范围
                         if (int.Parse(richTextOldDevNO.Text) < 33)
                         {
                             //检查新用户号是否是数字
                             if (RegexUtil.RegexCheckNumber(richTextNewDevNO.Text))
                             {
                                 //检查新用户号是否超出范围
                                 if (int.Parse(richTextNewDevNO.Text) < 33)
                                 {
                                     //检查信道号是否是数字
                                     if (RegexUtil.RegexCheckNumber(richTextNewChannal.Text))
                                     {
                                         ChangeNONewChannal = int.Parse(richTextNewChannal.Text);
                                         //检查信道号是否超出范围
                                         if (ChangeNONewChannal < 31 && (ChangeNONewChannal < 23 || ChangeNONewChannal > 25))
                                         {
                                             //全部检查完毕没有问题
                                             richTextUserChangeNOStatus.Text = "";       //状态栏清空
                                             ChangeNOOldSerialNO             = (int.Parse(richTextOldGrpNO.Text) << 8) | (int.Parse(richTextOldDevNO.Text));
                                             ChangeNONewSerialNO             = (int.Parse(richTextNewGrpNO.Text) << 8) | (int.Parse(richTextNewDevNO.Text));
                                             ChangeNONewSerialNO_forChannal  = ChangeNONewSerialNO;                                                //发送临时组队命令
                                             SerialSendMsg sendMsg = ProtocolCommand.ParaSetup1CmdMsg(AppUtil.IntToBytes(ChangeNOOldSerialNO), AppUtil.IntToBytes(ChangeNONewSerialNO));
                                             //发送切换信道命令
                                             serialCom.SendQueue_Enqueue(sendMsg);                  //发送出去
                                             ChangeNONewChannal = int.Parse(richTextNewChannal.Text);
                                             Thread th = new Thread(new ThreadStart(ThreadSwitch)); //创建线程
                                             th.Start();                                            //启动线程
                                             //写入按钮点击记录
                                             worklog.LogQueue_Enqueue(LogCommand.getButtonClickRecord(BTNPANEL.UserChangeNOPanel, (int)BtnOfUserChangeNOPanel.StartChangeNO, ChangeNOOldSerialNO.ToString("X8") + " " + ChangeNONewSerialNO.ToString("X8")));
                                         }
                                         else
                                         {
                                             MessageBox.Show("信道必须小于30,切不能为23 24 25");
                                         }
                                     }
                                     else
                                     {
                                         MessageBox.Show("信道必须是数字");
                                     }
                                 }
                                 else
                                 {
                                     MessageBox.Show("新用户号必须小于33");
                                 }
                             }
                             else
                             {
                                 MessageBox.Show("新用户号必须为数字形式");
                             }
                         }
                         else
                         {
                             MessageBox.Show("原用户号必须小于33");
                         }
                     }
                     else
                     {
                         MessageBox.Show("原用户号必须为数字形式");
                     }
                 }
                 else
                 {
                     MessageBox.Show("新组号必须小于16777215");
                 }
             }
             else
             {
                 MessageBox.Show("新组号必须为数字形式");
             }
         }
         else
         {
             MessageBox.Show("原组号必须小于16777215");
         }
     }
     else
     {
         MessageBox.Show("原组号必须为数字形式");
     }
 }
Example #15
0
 public ProtocolMessage(ProtocolCommand command)
 {
     Command = command;
 }
Example #16
0
        public async Task SendQueryAsync()
        {
            IsEnabled = false;
            var path    = ProtocolCommand.FormatPath();
            var command = $"{path}?";

            var result = "";

            if (App.Mock)
            {
                await Task.Delay(1);

                result = DefaultResponse;
            }
            else
            {
                var response = await AppLocator.TelnetService.SendCommandAsync(command, true);

                // remove line terminator
                result = response?.TrimEnd();
            }
            if (result.Length == 0)
            {
                return;
            }

            if (result == "Command error")
            {
                throw new InvalidOperationException($"Command error: {command}");
            }

            var propInfo = _propInfo ?? this.GetType().GetProperty(nameof(Value));

            if (_propInfo == null)
            {
                _propInfo = propInfo;
            }
            var type = typeof(T);

            if (type == typeof(string) || type == typeof(StringOption))
            {
                var value = StringOptions.GetByTerm(ProtocolCommand.Options, result);
                propInfo.SetValue(this, $"{value}");
            }
            else if (type == typeof(bool))
            {
                propInfo.SetValue(this, result == "1");
            }
            else if (type == typeof(int) || type == typeof(IntegerOption))
            {
                if (int.TryParse(result, out var val))
                {
                    propInfo.SetValue(this, val);
                }
            }
            else if (type == typeof(double) || type == typeof(RealOption))
            {
                if (double.TryParse(result, out var val))
                {
                    propInfo.SetValue(this, val);
                }
            }
            IsEnabled = true;
            if (!ProtocolCommand.Name.Contains("Status"))
            {
                System.Diagnostics.Debug.WriteLine($"{ProtocolCommand.Name}: {Value}");
            }
        }