Ejemplo n.º 1
0
        public static NextAddr ParseNextAddrResponse(DeviceResponse answer)
        {
            if (answer.Body.Length != 6)
            {
                throw new Exception("ответ не распознан (несовпадение по длине)");
            }
            byte[]   b     = answer.Body;
            NextAddr naddr = new NextAddr();

            naddr.hour     = BitConverter.ToUInt16(b, 0);
            naddr.day      = BitConverter.ToUInt16(b, 2);
            naddr.abnormal = BitConverter.ToUInt16(b, 4);
            return(naddr);
        }
Ejemplo n.º 2
0
        private DeviceResponse Send(byte[] data, int timeOut = 7500, int attemptsMaximum = 1)
        {
            DeviceResponse answer = new DeviceResponse();

            byte[] buffer = null;
            for (var attempts = 0; attempts < attemptsMaximum; attempts++)
            {
                buffer = SendSimple(data, timeOut);
                if (buffer.Length == 0)
                {
                    throw new Exception("Нет ответа");
                }
            }

            answer.Body = buffer;
            return(answer);
        }
Ejemplo n.º 3
0
        public static Status ParseDeviceSelectResponse(DeviceResponse answer, VersionHardware verHw)
        {
            if (answer.Body.Length != 1)
            {
                throw new Exception("ответ не распознан (несовпадение по длине)");
            }
            byte   b = answer.Body[0];
            Status s = new Status();

            s.b6_isQ2ComputeByT3 = (b & 0x40) > 0;
            s.b5_isNotSA94       = (b & 0x20) > 0;
            s.b4_isModeCount     = (b & 0x10) > 0;
            s.b3_isSA94          = (b & 0x08) > 0;
            s.b2_isTwoChannels   = (b & 0x04) > 0;

            if (s.b5_isNotSA94 || !s.b3_isSA94)
            {
                throw new Exception("SA-94 не обнаружен");
            }

            switch (verHw)
            {
            case VersionHardware.SA94_1:
                s.b1_SA94_1_isT2Programmed      = (b & 0x02) > 0;
                s.b0_SA94_1_2M_isPrn1OnBackTube = (b & 0x01) > 0;
                break;

            case VersionHardware.SA94_2:
                s.b1_SA94_2_2M_isT3Measured       = (b & 0x02) > 0;
                s.b0_SA94_2_isComputeT3Programmed = (b & 0x01) > 0;
                break;

            case VersionHardware.SA94_2M:
                s.b1_SA94_2_2M_isT3Measured     = (b & 0x02) > 0;
                s.b0_SA94_1_2M_isPrn1OnBackTube = (b & 0x01) > 0;
                break;
            }

            return(s);
        }