コード例 #1
0
 private int getBinaryLength(int aLength)
 {
     byte[] aBytes = new byte[aLength];
     Array.Copy(this.mDataItem, this.mReadIndex, aBytes, 0, aBytes.Length);
     this.mReadIndex += aLength;
     return((int)Byte2SecsValue.GetInt(aBytes));
 }
コード例 #2
0
        internal static long GetInt(byte[] aBytes)
        {
            long num = 0L;

            switch (aBytes.Length)
            {
            case 1:
            {
                int num2 = (int)(aBytes[0] & 255);
                return((long)num2);
            }

            case 2:
                return((long)Byte2SecsValue.GetI2(aBytes)[0]);

            case 3:
                return(num);

            case 4:
                return((long)Byte2SecsValue.GetI4(aBytes)[0]);

            case 5:
            case 6:
            case 7:
                return(num);

            case 8:
                return(Byte2SecsValue.GetI8(aBytes)[0]);

            default:
                return(num);
            }
        }
コード例 #3
0
        public SECSMessage Byte_TO_SecsMessage(byte[] aHeader)
        {
            SECSMessage message = new SECSMessage("", "");

            byte[] aBytes = new byte[]
            {
                aHeader[0],
                aHeader[1]
            };
            byte[] buffer2 = new byte[]
            {
                aHeader[6],
                aHeader[7],
                aHeader[8],
                aHeader[9]
            };
            message.SystemBytes = Byte2SecsValue.GetLong(buffer2);
            message.DeviceIdID  = Byte2SecsValue.AdjustDeviceID((short)Byte2SecsValue.GetInt(aBytes));
            message.Stream      = (int)(aHeader[2] & 255);
            int stream = message.Stream;

            if (stream > 128)
            {
                message.Stream = stream - 128;
                message.WBit   = true;
            }
            message.Function = (int)(aHeader[3] & 255);
            return(message);
        }
コード例 #4
0
 internal static byte[] GetI8Bytes(long[] data)
 {
     byte[] buffer = new byte[data.Length * 8];
     for (int i = 0; i < data.Length; i++)
     {
         byte[] aBytes = new byte[8];
         Array.Copy(BitConverter.GetBytes(data[i]), aBytes, 8);
         Array.Copy(Byte2SecsValue.Swap(aBytes), 0, buffer, 8 * i, 8);
     }
     return(buffer);
 }
コード例 #5
0
 internal static byte[] GetF4Bytes(float[] data)
 {
     byte[] buffer = new byte[data.Length * 4];
     for (int i = 0; i < data.Length; i++)
     {
         byte[] aBytes = new byte[4];
         Array.Copy(BitConverter.GetBytes(data[i]), aBytes, 4);
         Array.Copy(Byte2SecsValue.Swap(aBytes), 0, buffer, 4 * i, 4);
     }
     return(buffer);
 }
コード例 #6
0
ファイル: HSMSReader.cs プロジェクト: shawn582818273/CIM
 protected override void Run()
 {
     while (this.running)
     {
         byte[] bs = new byte[4];
         try
         {
             this.ReadLength(bs);
             int aLength = (int)Byte2SecsValue.GetInt(bs);
             if (aLength > 0)
             {
                 SECSBlock block = this.ByteToBlock(this.ReadBody(aLength));
                 if (this.OnReadCompleted != null)
                 {
                     this.OnReadCompleted(block);
                 }
             }
             else
             {
                 Thread.Sleep(50);
             }
         }
         catch (OutOfMemoryException exception)
         {
             GC.Collect();
             GC.WaitForPendingFinalizers();
             this.logger.Error("Reader#Run", exception);
             if (this.OnReadError != null)
             {
                 this.OnReadError(string.Format("{0}: Out Of Memory.", SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.ReadError)));
             }
             this.Disconnect(exception.Message);
         }
         catch (IOException exception2)
         {
             this.logger.Error("Reader#Run", exception2);
             if (this.OnReadError != null)
             {
                 this.OnReadError(string.Format("{0}: Socket Error.", SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.ReadError)));
             }
             this.Disconnect(exception2.Message);
         }
         catch (Exception exception3)
         {
             this.logger.Error("Reader#Run", exception3);
             if (this.OnReadError != null)
             {
                 this.OnReadError(string.Format("{0}: {1}.", SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.ReadError), exception3.Message));
             }
             this.Disconnect(exception3.Message);
         }
     }
 }
コード例 #7
0
 internal static double[] GetF8(byte[] aBytes)
 {
     byte[]   buffer   = new byte[8];
     double[] numArray = new double[aBytes.Length / 8];
     for (int i = 0; i < aBytes.Length; i += 8)
     {
         Array.Copy(aBytes, i, buffer, 0, buffer.Length);
         buffer = Byte2SecsValue.Swap(buffer);
         double num2 = BitConverter.ToDouble(buffer, 0);
         numArray[i / 8] = num2;
     }
     return(numArray);
 }
コード例 #8
0
        internal static short AdjustDeviceID(short aDeviceID)
        {
            if (aDeviceID >= 0)
            {
                return(aDeviceID);
            }
            byte[] intBytes = SecsValue2Byte.GetIntBytes((int)aDeviceID, 2);
            int    num      = (int)(intBytes[0] & 255);

            num        -= 128;
            intBytes[0] = (byte)num;
            return((short)Byte2SecsValue.GetInt(intBytes));
        }
コード例 #9
0
 internal static float[] GetF4(byte[] aBytes)
 {
     byte[]  buffer   = new byte[4];
     float[] numArray = new float[aBytes.Length / 4];
     for (int i = 0; i < aBytes.Length; i += 4)
     {
         Array.Copy(aBytes, i, buffer, 0, buffer.Length);
         buffer = Byte2SecsValue.Swap(buffer);
         float num2 = BitConverter.ToSingle(buffer, 0);
         numArray[i / 4] = num2;
     }
     return(numArray);
 }
コード例 #10
0
 private ulong[] ParseUInt8(int aLength)
 {
     ulong[] result;
     try
     {
         byte[] aBytes = new byte[aLength];
         Array.Copy(this.mDataItem, this.mReadIndex, aBytes, 0, aBytes.Length);
         this.mReadIndex += aLength;
         result           = Byte2SecsValue.GetU8(aBytes);
     }
     catch (Exception)
     {
         result = null;
     }
     return(result);
 }
コード例 #11
0
 private byte[] ParseBinary(int aLength)
 {
     byte[] binary;
     try
     {
         byte[] aBytes = new byte[aLength];
         Array.Copy(this.mDataItem, this.mReadIndex, aBytes, 0, aBytes.Length);
         this.mReadIndex += aLength;
         binary           = Byte2SecsValue.GetBinary(aBytes);
     }
     catch (Exception)
     {
         throw;
     }
     return(binary);
 }
コード例 #12
0
        private string ParseAscii(int aLength)
        {
            string result;

            try
            {
                byte[] aBytes = new byte[aLength];
                Array.Copy(this.mDataItem, this.mReadIndex, aBytes, 0, aBytes.Length);
                this.mReadIndex += aLength;
                result           = Byte2SecsValue.GetAscii(aBytes);
            }
            catch (Exception)
            {
                result = null;
            }
            return(result);
        }
コード例 #13
0
        private void OnReadHsms(SECSBlock aHSMSItem)
        {
            try
            {
                if (this.NowStatus == eHSMS_PORT_STATUS.TERMINATE)
                {
                    this.logger.Error("HSMSPort::OnReadHsms=> Port TERMINATE.");
                    return;
                }
            }
            catch (Exception exception)
            {
                this.logger.Error("HSMSPort::OnReadHsms", exception);
            }
            byte[] aBytes = new byte[4];
            Array.Copy(aHSMSItem.Header, 6, aBytes, 0, aBytes.Length);
            long mSystemBytes = Byte2SecsValue.GetLong(aBytes);
            byte num          = aHSMSItem.Header[5];

            if (num == 0)
            {
                this.logger.Debug("HSMSPort::OnReadHsms Not control message.");
                aHSMSItem.IsControlMsg = false;
                this.mHsmsParser.QueueEnque(aHSMSItem);
                return;
            }
            this.logger.Debug("HSMSPort::OnReadHsms control message.");
            lock (this.syncObject)
            {
                aHSMSItem.IsControlMsg = true;
                switch (num)
                {
                case 1:
                    this.mHsmsTimer.StopT7Timer();
                    if (this.NowStatus != eHSMS_PORT_STATUS.SELECT)
                    {
                        this.mHsmsWriter.WriteControlMessage(mSystemBytes, 0, eControlMessage.SELECT_RSP, 255, 255);
                        this.FireSelected();
                    }
                    else
                    {
                        this.mHsmsWriter.WriteControlMessage(mSystemBytes, 1, eControlMessage.SELECT_RSP, 255, 255);
                    }
                    break;

                case 2:
                    this.mHsmsTimer.StopT6Timer();
                    this.FireSelected(aHSMSItem.Header[3]);
                    break;

                case 3:
                    this.UpdateStatus(eHSMS_PORT_STATUS.CONNECT);
                    this.mHsmsWriter.WriteControlMessage(mSystemBytes, 0, eControlMessage.DESELECT_RSP, 255, 255);
                    break;

                case 5:
                    this.mHsmsWriter.WriteControlMessage(mSystemBytes, 0, eControlMessage.LINKTEST_RSP, 255, 255);
                    break;

                case 6:
                    this.mHsmsTimer.StopT6Timer();
                    break;

                case 7:
                    this.TraceRejectReqCode(aHSMSItem.Header[3]);
                    break;

                case 9:
                    this.OnDisconnect("Separate.");
                    break;
                }
            }
        }
コード例 #14
0
 internal static long GetLong(byte[] aBytes)
 {
     return((long)((ulong)Byte2SecsValue.GetU4(aBytes)[0]));
 }
コード例 #15
0
        private string ParseChar2(int aLength)
        {
            string str2;

            try
            {
                byte[] aBytes  = new byte[2];
                byte[] buffer2 = new byte[aLength - 2];
                Array.Copy(this.mDataItem, this.mReadIndex, aBytes, 0, 2);
                this.mReadIndex += 2;
                Array.Copy(this.mDataItem, this.mReadIndex, buffer2, 0, buffer2.Length);
                this.mReadIndex += buffer2.Length;
                aBytes[0]        = buffer2[0];
                aBytes[1]        = buffer2[1];
                int    @int = (int)Byte2SecsValue.GetInt(aBytes);
                string str  = null;
                switch (@int)
                {
                case 1:
                    str = Encoding.GetEncoding(1200).GetString(buffer2);
                    break;

                case 2:
                    str = Encoding.GetEncoding(65001).GetString(buffer2);
                    break;

                case 3:
                    str = Encoding.GetEncoding(20127).GetString(buffer2);
                    break;

                case 4:
                    str = Encoding.GetEncoding(28591).GetString(buffer2);
                    break;

                case 5:
                case 6:
                    str = Encoding.GetEncoding(874).GetString(buffer2);
                    break;

                case 7:
                    str = Encoding.GetEncoding(57002).GetString(buffer2);
                    break;

                case 8:
                    str = Encoding.GetEncoding(932).GetString(buffer2);
                    break;

                case 9:
                    str = Encoding.GetEncoding(20932).GetString(buffer2);
                    break;

                case 10:
                    str = Encoding.GetEncoding(51949).GetString(buffer2);
                    break;

                case 11:
                    str = Encoding.GetEncoding(936).GetString(buffer2);
                    break;

                case 12:
                    str = Encoding.GetEncoding(51936).GetString(buffer2);
                    break;

                case 13:
                    str = Encoding.GetEncoding(950).GetString(buffer2);
                    break;
                }
                str2 = str;
            }
            catch (Exception)
            {
                throw;
            }
            return(str2);
        }