Exemple #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));
 }
Exemple #2
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);
        }
Exemple #3
0
 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);
         }
     }
 }
Exemple #4
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));
        }
Exemple #5
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);
        }