static Command CreateReadCommand(ParsingInfo info)
        {
            ReadCmd cmd = new ReadCmd();

            cmd.varName = info.MandatoryToken <IdToken>("varName").Value;

            return(cmd);
        }
        static void ExecuteRead(ReadCmd cmd)
        {
            string input = Console.ReadLine();

            if (float.TryParse(input, out float value))
            {
                Memory.Save(cmd.varName, value);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 读取数据方法,返回数据为处理之后的数据,为双精度浮点数组
        /// </summary>
        /// <param name="dataIdentification">对应数据的标识码</param>
        /// <returns></returns>
        public double[] Read(DataIdentification dataIdentification)   //读取方法负责(状态指令1,电流指令)
        {
            communicationOK = false;
            List <int> list = new List <int>();

            double[] result  = new double[6];
            ReadCmd  readCmd = new ReadCmd();

            readCmd.start       = Start;
            readCmd.address0    = Address.a0;
            readCmd.address1    = Address.a1;
            readCmd.address2    = Address.a2;
            readCmd.address3    = Address.a3;
            readCmd.address4    = Address.a4;
            readCmd.address5    = Address.a5;;
            readCmd.datastart   = Start;
            readCmd.controlCode = (byte)ControlCode.Read;
            readCmd.dataLength  = 0x04;
            readCmd.di0         = (byte)(dic[dataIdentification].di0 + Mask);
            readCmd.di1         = (byte)(dic[dataIdentification].di1 + Mask);
            readCmd.di2         = (byte)(dic[dataIdentification].di2 + Mask);
            readCmd.di3         = (byte)(dic[dataIdentification].di3 + Mask);
            readCmd.cs          = GetCS(new byte[] { readCmd.start, readCmd.address0, readCmd.address1, readCmd.address2, readCmd.address3, readCmd.address4, readCmd.address5
                                                     , readCmd.datastart, readCmd.controlCode, readCmd.dataLength, readCmd.di0, readCmd.di1, readCmd.di2, readCmd.di3 }, 14);
            readCmd.end = End;
            byte[] bytes = { readCmd.start, readCmd.address0,  readCmd.address1,    readCmd.address2,   readCmd.address3, readCmd.address4, readCmd.address5
                             ,              readCmd.datastart, readCmd.controlCode, readCmd.dataLength, readCmd.di0,      readCmd.di1,      readCmd.di2,readCmd.di3, readCmd.cs, readCmd.end };
            byte[] ByteBack = SendData(bytes);
            if ((ByteBack[0] == Start) && (ByteBack[8] == 0x91)) //返回数据的判断
            {
                switch (dataIdentification)
                {
                case DataIdentification.ReadCurrent:        //get three phase current
                    result = GetThreePhaseCurrent(ByteBack);
                    break;

                case DataIdentification.ReadVoltage:       //get three phase voltage
                    result = GetThreePhaseVoltage(ByteBack);
                    break;

                case DataIdentification.ReadResidualCurrent:
                    result = GetResidualCurrent(ByteBack);
                    break;

                case DataIdentification.GetSwitchProtect:
                    result = GetProtectData(ByteBack);
                    break;
                }
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 读取分合闸状态 返回1为合闸,返回2为分闸
        /// </summary>
        /// <returns></returns>
        public int ReadSwitchState()
        {
            communicationOK = false;
            ReadCmd readCmd = new ReadCmd();
            int     state1  = 0;

            readCmd.start       = Start;
            readCmd.address0    = Address.a0;
            readCmd.address1    = Address.a1;
            readCmd.address2    = Address.a2;
            readCmd.address3    = Address.a3;
            readCmd.address4    = Address.a4;
            readCmd.address5    = Address.a5;;
            readCmd.datastart   = Start;
            readCmd.controlCode = (byte)ControlCode.Read;
            readCmd.dataLength  = 0x04;
            readCmd.di0         = (byte)(dic[DataIdentification.ReadStateWord1].di0 + Mask);
            readCmd.di1         = (byte)(dic[DataIdentification.ReadStateWord1].di1 + Mask);
            readCmd.di2         = (byte)(dic[DataIdentification.ReadStateWord1].di2 + Mask);
            readCmd.di3         = (byte)(dic[DataIdentification.ReadStateWord1].di3 + Mask);
            readCmd.cs          = GetCS(new byte[] { readCmd.start, readCmd.address0, readCmd.address1, readCmd.address2, readCmd.address3, readCmd.address4, readCmd.address5
                                                     , readCmd.datastart, readCmd.controlCode, readCmd.dataLength, readCmd.di0, readCmd.di1, readCmd.di2, readCmd.di3 }, 14);
            readCmd.end = End;
            byte[] bytes = { readCmd.start, readCmd.address0,  readCmd.address1,    readCmd.address2,   readCmd.address3, readCmd.address4, readCmd.address5
                             ,              readCmd.datastart, readCmd.controlCode, readCmd.dataLength, readCmd.di0,      readCmd.di1,      readCmd.di2,readCmd.di3, readCmd.cs, readCmd.end };
            byte[] ByteBack = SendData(bytes);
            if ((ByteBack[0] == Start) && (ByteBack[8] == 0x91)) //返回数据的判断
            {
                state1 = ByteBack[14];                           //获取状态字
            }
            if (((state1 - Mask) & 0x60) == 0x20)                //如果为合闸位为1
            {
                return(1);                                       //1为合闸
            }
            else if (((state1 - Mask) & 0x60) == 0x00)
            {
                return(2);
            }
            return(0);
        }
Beispiel #5
0
        /// <summary>
        ///  测试通信的方法,通信成功返回true,失败返回false;
        /// </summary>
        /// <returns></returns>
        public bool CommunicationTest() //测试通信
        {
            communicationOK = false;
            ReadCmd readCmd = new ReadCmd();

            readCmd.start       = Start;
            readCmd.address0    = Address.a0;
            readCmd.address1    = Address.a1;
            readCmd.address2    = Address.a2;
            readCmd.address3    = Address.a3;
            readCmd.address4    = Address.a4;
            readCmd.address5    = Address.a5;;
            readCmd.datastart   = Start;
            readCmd.controlCode = (byte)ControlCode.Read;
            readCmd.dataLength  = 0x04;
            readCmd.di0         = (byte)(dic[DataIdentification.CommunicationTest].di0 + Mask);
            readCmd.di1         = (byte)(dic[DataIdentification.CommunicationTest].di1 + Mask);
            readCmd.di2         = (byte)(dic[DataIdentification.CommunicationTest].di2 + Mask);
            readCmd.di3         = (byte)(dic[DataIdentification.CommunicationTest].di3 + Mask);
            readCmd.cs          = GetCS(new byte[] { readCmd.start, readCmd.address0, readCmd.address1, readCmd.address2, readCmd.address3, readCmd.address4, readCmd.address5
                                                     , readCmd.datastart, readCmd.controlCode, readCmd.dataLength, readCmd.di0, readCmd.di1, readCmd.di2, readCmd.di3 }, 14);
            readCmd.end = End;
            byte[] bytes = { readCmd.start, readCmd.address0,  readCmd.address1,    readCmd.address2,   readCmd.address3, readCmd.address4, readCmd.address5
                             ,              readCmd.datastart, readCmd.controlCode, readCmd.dataLength, readCmd.di0,      readCmd.di1,      readCmd.di2,readCmd.di3, readCmd.cs, readCmd.end };
            SendData(bytes);
            if (communicationOK)
            {
                CommunicationState = true;
                communicationOK    = false;
            }
            else
            {
                CommunicationState = false;
            }
            return(CommunicationState);
        }
Beispiel #6
0
 public IdcardReaderViewModel(int readInverval = 5)
 {
     SetInterval(readInverval);
     timerRead.Tick += (o, e) => { ReadCmd.Execute(null); };
 }