Пример #1
0
 private void MakeMsgHeader(int device, bool wbit, long systembytes)
 {
     byte[] data     = new byte[10];
     byte[] intBytes = SecsValue2Byte.GetIntBytes(device, 2);
     data[0] = intBytes[0];
     data[1] = intBytes[1];
     try
     {
         if (wbit)
         {
             data[2] = (byte)(this.mMsg.Stream - 128);
         }
         else
         {
             data[2] = (byte)this.mMsg.Stream;
         }
         data[3] = (byte)this.mMsg.Function;
     }
     catch (Exception)
     {
     }
     intBytes         = SecsValue2Byte.GetIntBytes((int)systembytes, 4);
     data[6]          = intBytes[0];
     data[7]          = intBytes[1];
     data[8]          = intBytes[2];
     data[9]          = intBytes[3];
     this.mMsg.Header = data;
     this.AppendBytes(data);
 }
Пример #2
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));
        }
Пример #3
0
 public void WriteControlMessage(long mSystemBytes, byte rspcode, eControlMessage stype, byte high, byte low)
 {
     try
     {
         byte[] bs = new byte[14];
         bs[0] = 0;
         bs[1] = 0;
         bs[2] = 0;
         bs[3] = 10;
         byte[] intBytes = SecsValue2Byte.GetIntBytes((int)mSystemBytes, 4);
         bs[10] = intBytes[0];
         bs[11] = intBytes[1];
         bs[12] = intBytes[2];
         bs[13] = intBytes[3];
         bs[4]  = high;
         bs[5]  = low;
         bs[7]  = rspcode;
         bs[9]  = (byte)stype;
         if (stype == eControlMessage.SELECT_REQ)
         {
             this.mHsmsTimer.StartT6Timer();
         }
         else if (stype == eControlMessage.LINKTEST_REQ)
         {
             this.mHsmsTimer.StartT6Timer();
         }
         this.logger.Debug(string.Format("[WriteControlMessage] [{0}-{2}] -- {1}", mSystemBytes, ByteStringBuilder.ToLogString(bs), stype));
         this.writer.Write(bs);
         this.writer.Flush();
     }
     catch (Exception exception)
     {
         this.logger.Error("WriteControlMessage", exception);
         if (this.OnWriteError != null)
         {
             this.OnWriteError(SECSEventType.Error, null, string.Format("{0}: Socket Error.", SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.WriteError)));
         }
     }
 }
Пример #4
0
 private void SetToU8(object obj)
 {
     if (obj.GetType().IsArray)
     {
         this.isArray = true;
         Array   array = (Array)obj;
         int     num   = array.Length;
         ulong[] data  = new ulong[num];
         for (int i = 0; i < num; i++)
         {
             data[i] = Convert.ToUInt64(array.GetValue(i));
         }
         this.itemValue   = data;
         this.binaryValue = SecsValue2Byte.GetU8Bytes(data);
         return;
     }
     this.isArray   = false;
     this.itemValue = Convert.ToUInt64(obj);
     ulong[] numArray2 = new ulong[]
     {
         (ulong)this.itemValue
     };
     this.binaryValue = SecsValue2Byte.GetU8Bytes(numArray2);
 }
Пример #5
0
 private void SetToI2(object obj)
 {
     if (obj.GetType().IsArray)
     {
         this.isArray = true;
         Array   array = (Array)obj;
         int     num   = array.Length;
         short[] data  = new short[num];
         for (int i = 0; i < num; i++)
         {
             data[i] = Convert.ToInt16(array.GetValue(i));
         }
         this.itemValue   = data;
         this.binaryValue = SecsValue2Byte.GetI2Bytes(data);
         return;
     }
     this.isArray   = false;
     this.itemValue = Convert.ToInt16(obj);
     short[] numArray2 = new short[]
     {
         (short)this.itemValue
     };
     this.binaryValue = SecsValue2Byte.GetI2Bytes(numArray2);
 }
Пример #6
0
 private void SetToF8(object obj)
 {
     if (obj.GetType().IsArray)
     {
         this.isArray = true;
         Array    array = (Array)obj;
         int      num   = array.Length;
         double[] data  = new double[num];
         for (int i = 0; i < num; i++)
         {
             data[i] = Convert.ToDouble(array.GetValue(i));
         }
         this.itemValue   = data;
         this.binaryValue = SecsValue2Byte.GetF8Bytes(data);
         return;
     }
     this.isArray   = false;
     this.itemValue = Convert.ToDouble(obj);
     double[] numArray2 = new double[]
     {
         (double)this.itemValue
     };
     this.binaryValue = SecsValue2Byte.GetF8Bytes(numArray2);
 }
Пример #7
0
 private void SetToBoolean(object obj)
 {
     if (obj.GetType().IsArray)
     {
         this.isArray = true;
         Array  array = (Array)obj;
         int    num   = array.Length;
         bool[] data  = new bool[num];
         for (int i = 0; i < num; i++)
         {
             data[i] = Convert.ToBoolean(array.GetValue(i));
         }
         this.itemValue   = data;
         this.binaryValue = SecsValue2Byte.GetBooleanBytes(data);
         return;
     }
     this.isArray   = false;
     this.itemValue = Convert.ToBoolean(obj);
     bool[] flagArray2 = new bool[]
     {
         (bool)this.itemValue
     };
     this.binaryValue = SecsValue2Byte.GetBooleanBytes(flagArray2);
 }
Пример #8
0
 private void MakeMsgLengthBytes(long aLength)
 {
     byte[] intBytes = SecsValue2Byte.GetIntBytes((int)aLength, 4);
     this.AppendBytes(intBytes);
 }
Пример #9
0
        private Queue <SECSBlock> GetSECS1Bytes(byte[] encodingBytes)
        {
            Queue <SECSBlock> queue = new Queue <SECSBlock>();
            int num2 = (encodingBytes.Length - 14) / 244;
            int data;

            for (int i = 0; i < num2; i = i++)
            {
                data = 0;
                SECSBlock block = new SECSBlock
                {
                    Length       = 254,
                    IsControlMsg = false
                };
                byte[] buffer = new byte[10];
                Array.Copy(encodingBytes, 4, buffer, 0, 10);
                byte[] buffer2 = new byte[254];
                Array.Copy(encodingBytes, 10 + i * 244, buffer2, 0, 254);
                buffer[5]      = (byte)(i + 1);
                block.Header   = buffer;
                block.DataItem = buffer2;
                for (int j = 0; j < buffer.Length; j++)
                {
                    data += (int)(buffer[j] & 255);
                }
                for (int k = 0; k < buffer2.Length; k++)
                {
                    data += (int)(buffer2[k] & 255);
                }
                byte[] buffer3 = SecsValue2Byte.GetIntBytes(data, 4);
                block.CheckSum = new byte[4];
                Array.Copy(buffer3, 2, block.CheckSum, 0, 2);
                queue.Enqueue(block);
            }
            data = 0;
            int       num3   = encodingBytes.Length - 14 - num2 * 244;
            SECSBlock block2 = new SECSBlock();

            byte[] buffer4 = new byte[10];
            Array.Copy(encodingBytes, 4, buffer4, 0, 10);
            buffer4[4] = 128;
            buffer4[5] = (byte)(num2 + 1);
            byte[] buffer5 = new byte[encodingBytes.Length - 14 - num2 * 244];
            Array.Copy(encodingBytes, 14 + num2 * 244, buffer5, 0, buffer5.Length);
            block2.Length       = num3 + 10;
            block2.IsControlMsg = false;
            block2.Header       = buffer4;
            block2.DataItem     = buffer5;
            for (int l = 0; l < buffer4.Length; l++)
            {
                data += (int)(buffer4[l] & 255);
            }
            for (int m = 0; m < buffer5.Length; m++)
            {
                data += (int)(buffer5[m] & 255);
            }
            byte[] intBytes = SecsValue2Byte.GetIntBytes(data, 4);
            block2.CheckSum = new byte[2];
            Array.Copy(intBytes, 2, block2.CheckSum, 0, 2);
            queue.Enqueue(block2);
            return(queue);
        }
Пример #10
0
        private void SetToCHAR2(object obj)
        {
            if (!(obj is string))
            {
                throw new ArgumentException("Only support convert string to CHAR2");
            }
            this.isArray   = false;
            this.itemValue = obj;
            List <byte> list = new List <byte>();

            byte[] bytes;
            switch (this.EncodingCode)
            {
            case LCEncodingCode.UTF8:
                list.AddRange(SecsValue2Byte.GetIntBytes(2, 2));
                bytes = Encoding.GetEncoding(65001).GetBytes((string)obj);
                break;

            case LCEncodingCode.ISO646:
                list.AddRange(SecsValue2Byte.GetIntBytes(3, 2));
                bytes = Encoding.GetEncoding(20127).GetBytes((string)obj);
                break;

            case LCEncodingCode.ISO88591:
                list.AddRange(SecsValue2Byte.GetIntBytes(4, 2));
                bytes = Encoding.GetEncoding(28591).GetBytes((string)obj);
                break;

            case LCEncodingCode.ISO885911:
                list.AddRange(SecsValue2Byte.GetIntBytes(5, 2));
                bytes = Encoding.GetEncoding(874).GetBytes((string)obj);
                break;

            case LCEncodingCode.TIS620:
                list.AddRange(SecsValue2Byte.GetIntBytes(6, 2));
                bytes = Encoding.GetEncoding(874).GetBytes((string)obj);
                break;

            case LCEncodingCode.IS13194:
                list.AddRange(SecsValue2Byte.GetIntBytes(7, 2));
                bytes = Encoding.GetEncoding(57002).GetBytes((string)obj);
                break;

            case LCEncodingCode.SHIFT_JIS:
                list.AddRange(SecsValue2Byte.GetIntBytes(8, 2));
                bytes = Encoding.GetEncoding(932).GetBytes((string)obj);
                break;

            case LCEncodingCode.JAPANESE:
                list.AddRange(SecsValue2Byte.GetIntBytes(9, 2));
                bytes = Encoding.GetEncoding(20932).GetBytes((string)obj);
                break;

            case LCEncodingCode.KOREAN:
                list.AddRange(SecsValue2Byte.GetIntBytes(10, 2));
                bytes = Encoding.GetEncoding(51949).GetBytes((string)obj);
                break;

            case LCEncodingCode.CHINESE_GB2312:
                list.AddRange(SecsValue2Byte.GetIntBytes(11, 2));
                bytes = Encoding.GetEncoding(936).GetBytes((string)obj);
                break;

            case LCEncodingCode.CHINESE_EUC_CN:
                list.AddRange(SecsValue2Byte.GetIntBytes(12, 2));
                bytes = Encoding.GetEncoding(51936).GetBytes((string)obj);
                break;

            case LCEncodingCode.CHINESE_BIG5:
                list.AddRange(SecsValue2Byte.GetIntBytes(13, 2));
                bytes = Encoding.GetEncoding(950).GetBytes((string)obj);
                break;

            default:
                list.AddRange(SecsValue2Byte.GetIntBytes(1, 2));
                bytes = Encoding.GetEncoding(1200).GetBytes((string)obj);
                break;
            }
            list.AddRange(bytes);
            this.binaryValue = list.ToArray();
        }