Exemple #1
0
        public byte[] ToBytes()
        {
            byte[] buffer = new byte[11];
            int    index  = 0;

            buffer[index] = (byte)def.Fzh;                             //分站号
            index++;
            buffer[index] = (byte)(((buffer.Length - 3) >> 8) & 0xFF); //长度高
            index++;
            buffer[index] = (byte)((buffer.Length - 3) & 0xFF);        //长度低
            index++;
            buffer[index] = 0x44;                                      //D命令
            index++;
            buffer[index] = 0x07;                                      //标志位4、3、2、1位 =3表示分站远程升级相关命令;第0位=1表示接收正确
            index++;
            buffer[index] = 0x05;                                      //状态标志位
            index++;
            //buffer[index] = DeviceId;  //设备编码
            //index++;
            //buffer[index] = HardVersion;  //硬件版本号
            //index++;
            //buffer[index] = FileVersion;   //升级文件版本号
            buffer[index] = 0;                                   //设备编码
            index++;
            buffer[index] = 0;                                   //硬件版本号
            index++;
            buffer[index] = 0;                                   //升级文件版本号

            CommandUtil.AddSumToBytes(buffer, 0, buffer.Length); //累加和

            return(buffer);
        }
Exemple #2
0
 public byte[] ToBytes()
 {
     byte[] bytes = null;
     bytes = GetControlBufferCapacity();
     CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
     return(bytes);
 }
        public byte[] ToBytes()
        {
            byte[] bytes = new byte[19];
            int    j     = 0;

            bytes[0] = 0x3E;
            bytes[1] = 0xE3;
            bytes[2] = 0x80;
            bytes[3] = 0x08;
            bytes[4] = (byte)def.Fzh;
            bytes[5] = 0x50;
            CommandUtil.ConvertInt16ToByte(15, bytes, 6, false);//长度,6,7
            bytes[8] = LastAcceptFlag;

            j          = (ushort)(this.SyncTime.Year - 2000);
            bytes[9]   = (byte)j;
            bytes[10]  = (byte)(this.SyncTime.Month);
            bytes[10] += (Byte)(((byte)this.SyncTime.DayOfWeek) << 5);
            bytes[11]  = (byte)this.SyncTime.Day;
            bytes[12]  = (byte)this.SyncTime.Hour;
            bytes[13]  = (byte)this.SyncTime.Minute;
            bytes[14]  = (byte)this.SyncTime.Second;
            CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
            return(bytes);
        }
Exemple #4
0
        public byte[] ToBytes()
        {
            byte[] bytes = null;
            byte   startindex;

            bytes    = new byte[14 + GradingAlarmItems.Count];
            bytes[0] = 0x3E;
            bytes[1] = 0xE3;
            bytes[2] = 0x80;
            bytes[3] = 0x08;
            bytes[4] = (byte)def.Fzh;
            bytes[5] = 0x56;
            CommandUtil.ConvertInt16ToByte((ushort)(bytes.Length - 4), bytes, 6, false);//长度,6,7
            bytes[8]   = (byte)(this.LastAcceptFlag);
            bytes[9]   = (byte)GradingAlarmItems.Count;
            startindex = 10;
            if (GradingAlarmItems != null)
            {
                for (int i = 0; i < GradingAlarmItems.Count; i++)
                {
                    bytes[startindex++] = (byte)(byte.Parse(GradingAlarmItems[i].Channel) + (GradingAlarmItems[i].AlarmStep << 5));
                }
            }
            CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
            return(bytes);
        }
 public byte[] ToBytes()
 {
     byte[] bytes = new byte[13];
     bytes[0] = 0x3E;
     bytes[1] = 0xE3;
     bytes[2] = 0x80;
     bytes[3] = 0x08;
     bytes[4] = (byte)def.Fzh;
     bytes[5] = 0x52;
     CommandUtil.ConvertInt16ToByte((ushort)(13 - 4), bytes, 6, false); //长度,6,7
     bytes[8] = (byte)(this.LastAcceptFlag);
     CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);                 //累加和
     return(bytes);
 }
Exemple #6
0
 public byte[] ToBytes()
 {
     byte[] bytes = null;
     try
     {
         bytes = GetInitializeCapacity();
         CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
     }
     catch (Exception ex)
     {
         Basic.Framework.Logging.LogHelper.Error(ex.Message + ex.StackTrace);
     }
     return(bytes);
 }
Exemple #7
0
 private byte[] GetBatteryBuffer()
 {
     byte[] bytes = new byte[14];
     bytes[0] = 0x3E;
     bytes[1] = 0xE3;
     bytes[2] = 0x80;
     bytes[3] = 0x08;
     bytes[4] = (byte)def.Fzh;
     bytes[5] = 0x55;
     CommandUtil.ConvertInt16ToByte((ushort)(bytes.Length - 4), bytes, 6, false);//长度,6,7
     bytes[8]  = (byte)(this.LastAcceptFlag);
     bytes[9]  = (byte)(BatteryControl);
     bytes[9] += (byte)((PowerPercentum / 2) << 2);
     CommandUtil.AddSumToBytes(bytes, 4, bytes.Length);//累加和
     return(bytes);
 }
        public byte[] ToBytes()
        {
            byte[] buffer = new byte[19];
            int    index  = 0;

            buffer[index] = (byte)def.Fzh;                             //分站号
            index++;
            buffer[index] = (byte)(((buffer.Length - 3) >> 8) & 0xFF); //长度高
            index++;
            buffer[index] = (byte)((buffer.Length - 3) & 0xFF);        //长度低
            index++;
            buffer[index] = 0x44;                                      //D命令
            index++;
            buffer[index] = 0x07;                                      //标志位4、3、2、1位 =3表示分站远程升级相关命令;第0位=1表示接收正确
            index++;
            buffer[index] = 0x01;                                      //状态标志位
            index++;
            buffer[index] = DeviceId;                                  //设备编码	1 Byte
            index++;
            buffer[index] = HardVersion;                               //硬件版本号	1 Byte
            index++;
            buffer[index] = FileVersion;                               //升级文件版本号	1 Byte
            //升级版本控制	2 Byte
            index++;
            buffer[index] = maxVersion;
            index++;
            buffer[index] = minVersion;
            //升级文件总片数	2 Byte
            index++;
            buffer[index] = (byte)((FileCount >> 8) & 0xFF);
            index++;
            buffer[index] = (byte)(FileCount & 0xFF);
            //文件校验	4 Byte
            index++;
            buffer[index] = (byte)((Crc >> 24) & 0xFF);
            index++;
            buffer[index] = (byte)((Crc >> 16) & 0xFF);
            index++;
            buffer[index] = (byte)((Crc >> 8) & 0xFF);
            index++;
            buffer[index] = (byte)((Crc >> 0) & 0xFF);

            CommandUtil.AddSumToBytes(buffer, 0, buffer.Length);//累加和

            return(buffer);
        }
        public byte[] ToBytes()
        {
            byte[] buffer = new byte[13 + 256];
            if (LostFileNum == 0)
            {
                buffer = new byte[13];
            }
            int index = 0;

            buffer[index] = (byte)def.Fzh;                             //分站号
            index++;
            buffer[index] = (byte)(((buffer.Length - 3) >> 8) & 0xFF); //长度高
            index++;
            buffer[index] = (byte)((buffer.Length - 3) & 0xFF);        //长度低
            index++;
            buffer[index] = 0x44;                                      //D命令
            index++;
            buffer[index] = 0x07;                                      //标志位4、3、2、1位 =3表示分站远程升级相关命令;第0位=1表示接收正确
            index++;
            buffer[index] = 0x04;                                      //状态标志位4中心站巡检分站的文件接收情况
            index++;
            buffer[index] = DeviceId;                                  //设备编码
            index++;
            buffer[index] = HardVersion;                               //硬件版本号
            index++;
            buffer[index] = FileVersion;                               //升级文件版本号
            index++;
            buffer[index] = (byte)((LostFileNum >> 8) & 0xFF);         //缺失文件编号 高
            index++;
            buffer[index] = (byte)(LostFileNum & 0xFF);                //缺失文件编号 低
            if (LostFileNum > 0)
            {
                for (int i = 0; i < FileBuffer.Length; i++) //文件数据体
                {
                    index++;
                    buffer[index] = FileBuffer[i];
                }
            }

            CommandUtil.AddSumToBytes(buffer, 0, buffer.Length);//累加和

            return(buffer);
        }
        public byte[] ToBytes()
        {
            byte[] buffer = new byte[269];
            int    index  = 0;

            buffer[index] = 0x7E;                                      //引导符
            index++;
            buffer[index] = 0xFC;                                      //带地址传输
            index++;
            buffer[index] = (byte)(((buffer.Length - 4) >> 8) & 0xFF); //长度高
            index++;
            buffer[index] = (byte)((buffer.Length - 4) & 0xFF);        //长度低
            index++;
            buffer[index] = 0x55;                                      //U命令;通用广播命令
            index++;
            buffer[index] = 0x00;                                      //标志位
            index++;
            buffer[index] = DeviceId;                                  //设备编码
            //硬件版本号	1 Byte
            index++;
            buffer[index] = HardVersion;
            //升级文件版本号	1 Byte
            index++;
            buffer[index] = FileVersion;
            //分片序号	2 Byte 高在前,低在后
            index++;
            buffer[index] = (byte)((NowBufferIndex >> 8) & 0xFF);
            index++;
            buffer[index] = (byte)(NowBufferIndex & 0xFF);
            //数据体	256Byte
            for (int i = 0; i < Buffer.Length; i++)
            {
                index++;
                buffer[index] = Buffer[i];
            }

            CommandUtil.AddSumToBytes(buffer, 1, buffer.Length - 1, false);//累加和

            return(buffer);
        }
        public byte[] ToBytes()
        {
            byte[] buffer = new byte[9];
            int    index  = 0;

            buffer[index] = (byte)def.Fzh;                                                                              //分站号
            index++;
            buffer[index] = (byte)(((buffer.Length - 3) >> 8) & 0xFF);                                                  //长度高
            index++;
            buffer[index] = (byte)((buffer.Length - 3) & 0xFF);                                                         //长度低
            index++;
            buffer[index] = 0x44;                                                                                       //D命令
            index++;
            buffer[index] = 0x07;                                                                                       //标志位4、3、2、1位 =3表示分站远程升级相关命令;第0位=1表示接收正确
            index++;
            buffer[index] = 0x08;                                                                                       //状态标志位
            index++;
            buffer[index] = (byte)(GetSoftVersion + (GetUpdateState << 1) + (GetDevType << 2) + (GetHardVersion << 3)); //数据域标记字1

            CommandUtil.AddSumToBytes(buffer, 0, buffer.Length);                                                        //累加和

            return(buffer);
        }
        public byte[] ToBytes()
        {
            byte[] bytes = new byte[31];
            int    i = 0;
            ushort ljh = 0, kh = 0, Cur;

            bytes[0] = 0xFE;                           //广播用254站号
            bytes[1] = CommandCodes.CallPersonCommand; //H命令
            bytes[2] = 0;
            bytes[3] = 0;
            if (HJ_State == 0)
            {
                bytes[4] = 1;//解除呼叫 0->1
                for (i = 0; i < 24; i++)
                {
                    bytes[5 + i] = 0x00;
                }
            }
            else
            {
                if (HJ_Type == 0)
                {
                    bytes[4] = 3;//全员呼叫
                    for (i = 0; i < 24; i++)
                    {
                        bytes[5 + i] = 0x00;
                    }
                }
                else if (HJ_Type == 1)
                {                 //区段
                    bytes[4] = 1; //指定人员呼叫
                    for (i = 0; i < 24; i++)
                    {
                        bytes[5 + i] = 0x0;
                    }
                    kh  = HJ_KH[0]; //开始卡号
                    ljh = HJ_KH[1]; //结束卡号
                    for (i = 0; i < 12; i++)
                    {
                        if (kh > 0 && kh <= ljh)
                        {
                            Cur = kh;
                            bytes[5 + i * 2 + 1] = (Byte)Cur;
                            Cur >>= 8;
                            bytes[5 + i * 2] = (Byte)Cur;
                            kh++;
                        }
                    }
                }
                else if (HJ_Type == 2)
                {
                    bytes[4] = 1;//指定人员呼叫
                    for (i = 0; i < 24; i++)
                    {
                        bytes[5 + i] = 0x0;
                    }
                    for (i = 0; i < 12; i++)
                    {
                        if (HJ_KH[i] > 0)
                        {
                            Cur = HJ_KH[i];
                            bytes[5 + i * 2 + 1] = (Byte)Cur;
                            Cur >>= 8;
                            bytes[5 + i * 2] = (Byte)Cur;
                        }
                    }
                }
                else if (HJ_Type == 4)
                {                 //呼叫的是井下设备
                    bytes[4] = 4; //指定井下设备
                    for (i = 0; i < 24; i++)
                    {
                        bytes[5 + i] = 0x0;
                    }
                    for (i = 0; i < 12; i++)
                    {
                        if (HJ_KH[i] > 0)
                        {
                            Cur = HJ_KH[i];
                            bytes[5 + i * 2 + 1] = (Byte)Cur; //要控制的识别器号
                            Cur >>= 8;
                            bytes[5 + i * 2] = (Byte)Cur;     //要控制的分站号
                        }
                    }
                }
            }
            CommandUtil.AddSumToBytes(bytes, 0, bytes.Length);//累加和
            return(bytes);
        }
        /// <summary>
        /// 数据包命令判断---监控系统
        /// </summary>
        /// <param name="data">数据包体</param>
        /// <param name="protocol">应回发的对象</param>
        /// <param name="newsType">信息类别=1表示网口,=2表示串口</param>
        /// <param name="orderVersion">分类的驱动类型</param>
        private void DataControlByMonitor(byte[] data, MasProtocol protocol, byte orderVersion)
        {
            ushort startindex = 32760;         //数据开始位置
            int    receivelength = 0;          //下标|接收数据长度
            ushort crcvalue = 0, receivevalue; //crc累加和 回发累加和
            byte   commandtype;                //接受命令

            if (data[0] == def.Fzh)
            {
                startindex = 0;
            }
            if (startindex == 32760)
            {
                RealDataCreateByState(protocol, ItemState.EquipmentInterrupted);
                LogHelper.Error("【DataControlByMonitor】" + "没有长到分站地址引导符【" + def.Fzh + "】");
                return;
            }
            receivelength = CommandUtil.ConvertByteToInt16(data, startindex + 2, false);
            if (receivelength > data.Length)
            {
                RealDataCreateByState(protocol, ItemState.EquipmentInterrupted);
                LogHelper.Error("【DataControlByMonitor】" + "回发长度不足【" + startindex + receivelength + 3 + "】" + "【" + data.Length + "】");
                return;
            }
            receivevalue = CommandUtil.ConvertByteToInt16(data, startindex + receivelength - 2, false);
            crcvalue     = CommandUtil.AddSumToBytes(data, startindex, startindex + receivelength);
            if (crcvalue != receivevalue)
            {
                RealDataCreateByState(protocol, ItemState.EquipmentBiterror);
                LogHelper.Error("【DataControlByMonitor】" + "通讯误码【" + crcvalue + "】" + "【" + receivevalue + "】");
                return;
            }
            commandtype = data[startindex + 1];//StartIndex当前为分站的下标索引
            switch (commandtype)
            {
            case CommandCodes.InitializeCommand:    //I初始化命令
                InitializeResponseCommand InitCommandObject = new Commands.InitializeResponseCommand();
                crcvalue = CommandUtil.ConvertByteToInt16(data, startindex + 5, false);
                InitCommandObject.SendInitializeAffirmToCenter(protocol, def.Point, crcvalue);
                break;

            case 0x46:    //F取数命令
                RealDataResponseCommand RealCommandObject = new Commands.RealDataResponseCommand();
                RealCommandObject.def = def;
                RealCommandObject.HandleRealData(data, protocol, startindex, orderVersion);
                break;

            case 0x41:    //A请求初始化命令
                InitializeResponseCommand InitRequstCommandObject = new Commands.InitializeResponseCommand();
                InitRequstCommandObject.SendInitializeRequestToCenter(protocol, def.Point);
                break;

            case 0x55:
                BatteryRealDataResponseCommand batterycommand = new BatteryRealDataResponseCommand();
                batterycommand.HandleBatteryRealData(data, protocol, startindex, 0x00, def.Point);
                break;

            case 0x58:    //X命令
                ControlExtendCommand(data[startindex + 5], data, protocol, startindex, data[startindex + 5]);
                break;

            case 0x45:    //分站回发接收错误,后续修改为,错误不回发
            case 0x50:    //分站回发接收错误,后续修改为,错误不回发
                break;

            case 0x52:    //复位
                ResetDeviceResponseCommand ResetDeviceCommandObject = new Commands.ResetDeviceResponseCommand();
                ResetDeviceCommandObject.SendResetDeviceAffirmToCenter(protocol, def.Point);
                break;

            case 0x5A:    //分站中断
                LogHelper.Info("【DataControlByMonitor】" + "监控分站数据回发5A分站中断【" + def.Point + "】");
                break;

            default:
                LogHelper.Info("【DataControlByMonitor】" + "非法命令【" + commandtype + "】");
                break;
            }
        }