Beispiel #1
0
 //写硬件配置参数到硬件
 public virtual void WriteModuleParam(TDataAreaType DataType)
 {
 }
Beispiel #2
0
 //设置硬件的相应区域的参数到默认设置
 public void RestoreDataToDefault(TDataAreaType DataType)
 {
 }
Beispiel #3
0
 //读取硬件的参数数据项
 public virtual void ReadModuleParam(TDataAreaType DataType)
 {
 }
Beispiel #4
0
 /// <summary>
 /// 异步从硬件中读取硬件设置参数
 /// </summary>
 /// <param name="DataType"></param>
 public void SyncReadDataFromEEPRom(TDataAreaType DataType)
 {
     ReadAr = ReadDlgt.BeginInvoke(DataType, ReadWriteCallBack, 1);
 }
Beispiel #5
0
        //从硬件的EEPROM中读取数据
        private bool ReadDataFromEEPRom(TDataAreaType DataType)
        {
            //_DataBuff.Clear();

            byte[] Cmd = new byte[4];

            string Msg = string.Empty;

            switch (DataType)
            {
            case TDataAreaType.drShare:
                Cmd[0] = (byte)TCommandCode.CMD_GET_SHARE_EEPROM;

                break;

            case TDataAreaType.drSwShare:
                Cmd[0] = (byte)TCommandCode.CMD_GET_SW_EEPROM;
                break;

            default:
                Cmd[0] = (byte)TCommandCode.CMD_GET_FW_EEPROM;
                break;
            }

            Cmd[1] = (byte)0x00;            //地址低
            Cmd[2] = (byte)0x00;            //地址高
            Cmd[3] = (byte)0x04;            //数据长度

            SendMsg(Cmd);

            if (!WaitReponse())
            {
                return(false);
            }

            if (_DataBuff.Length < 3)
            {
                return(false);
            }

            byte[] bytes = System.Text.Encoding.Unicode.GetBytes(_DataBuff.ToString());

            ushort DataLen = (ushort)(bytes[1] + (bytes[2] << 8));

            if (DataLen == 0xFFFF)
            {
                return(false);
            }


            ushort Address = 0x04;
            ushort I       = 0;

            _DataBuff.Clear();

            while (I < DataLen)
            {
                if ((DataLen - I) >= 6)
                {
                    Cmd[1] = (byte)(Address & 0xFF);
                    Cmd[2] = (byte)((Address & 0xFF00) >> 8);
                    Cmd[3] = (byte)0x06;            //数据长度
                }
                else
                {
                    Cmd[1] = (byte)(Address & 0xFF);
                    Cmd[2] = (byte)((Address & 0xFF00) >> 8);
                    Cmd[3] = (byte)(DataLen - I);  //数据长度
                }

                SendMsg(Cmd);
                if (!WaitReponse())
                {
                    return(false);
                }

                I += 6;

                Address += 6;
            }

            return(true);
        }
Beispiel #6
0
 //异步写数据到EEPROM中
 public void SyncWriteDataToEEPRom(byte[] Buff, TDataAreaType DataType)
 {
     WriteAr = WriteDlgt.BeginInvoke(Buff, DataType, ReadWriteCallBack, 0);
 }
Beispiel #7
0
        //写数据到硬件的EEPROM中
        private bool WriteDataToEEPRom(byte[] Buff, TDataAreaType DataType)
        {
            byte[] Cmd = new byte[8];

            string Msg = string.Empty;

            switch (DataType)
            {
            case TDataAreaType.drShare:
                Cmd[0] = (byte)TCommandCode.CMD_SET_SHARE_EEPROM;

                break;

            case TDataAreaType.drSwShare:
                Cmd[0] = (byte)TCommandCode.CMD_SET_SW_EEPROM;
                break;

            default:
                Cmd[0] = (byte)TCommandCode.CMD_SET_FW_EEPROM;
                break;
            }

            ushort Len = (ushort)Buff.Length;  //<65535

            byte CRC = Globals.CrcCheck(Buff, Len);

            Cmd[1] = (byte)0x00;            //地址低
            Cmd[2] = (byte)0x00;            //地址高
            Cmd[3] = (byte)0x04;            //数据长度

            Cmd[4] = (byte)CRC;
            Cmd[5] = (byte)(Len & 0xFF);
            Cmd[6] = (byte)((Len & 0xFF00) >> 8);
            Cmd[7] = (byte)0x85;

            SendMsg(Cmd);

            if (!WaitReponse())
            {
                return(false);
            }


            ushort I       = 0;
            ushort Address = 0x04;

            while (Len > 0)
            {
                for (int i = 1; i < 8; i++)
                {
                    Cmd[i] = 0x00;
                }


                Cmd[1] = (byte)(Address & 0xFF);
                Cmd[2] = (byte)((Address & 0xFF00) >> 8);

                switch (Len)
                {
                case 1:
                    Cmd[3] = (byte)0x01;                //数据长度
                    Cmd[4] = (byte)Buff[I];
                    break;

                case 2:
                    Cmd[3] = (byte)0x02;                //数据长度
                    Cmd[4] = (byte)Buff[I];
                    Cmd[5] = (byte)Buff[I + 1];
                    break;

                case 3:
                    Cmd[3] = (byte)0x03;                //数据长度
                    Cmd[4] = (byte)Buff[I];
                    Cmd[5] = (byte)Buff[I + 1];
                    Cmd[6] = (byte)Buff[I + 2];

                    break;

                default:
                    Cmd[3] = (byte)0x04;                //数据长度
                    Cmd[4] = (byte)Buff[I];
                    Cmd[5] = (byte)Buff[I + 1];
                    Cmd[6] = (byte)Buff[I + 2];
                    Cmd[7] = (byte)Buff[I + 3];
                    break;
                }

                SendMsg(Cmd);
                if (!WaitReponse())
                {
                    return(false);
                }


                if (Len >= 4)
                {
                    I       += 4;
                    Len     -= 4;
                    Address += 4;
                }
                else
                {
                    break;
                }
            }

            return(true);
        }