Example #1
0
        public static byte[] CmdAskStartCounting(uint commandNumber, double Ts_double, double tz_double, double tq_double, decimal cth_double, double Vq_double, int cmd_length = 13)
        {
            //===================================
            //
            /*Prašymas pradėti skaičiavimą*/
            /*Esc s nr Ts Tz Tq(2 baitai) Cth Vq CRC32*/
            byte esc = 0x1b; //Esc
            byte s   = 0x73; //s(tart)
            byte nr  = (byte)commandNumber;
            byte Ts  = ExternalFunctions.getTs(Ts_double);
            byte Tz  = ExternalFunctions.getTz(tz_double);

            byte[] Tq  = ExternalFunctions.getTq(tq_double);
            byte   Cth = ExternalFunctions.returnCthVoltage(cth_double);
            byte   Vq  = ExternalFunctions.getVq(Vq_double);

            byte[] cmd = new byte[9];
            cmd[0] = esc;
            cmd[1] = s;
            cmd[2] = nr;
            cmd[3] = Ts;
            cmd[4] = Tz;
            cmd[5] = Tq[0];
            cmd[6] = Tq[1];
            cmd[7] = Cth;
            cmd[8] = Vq;
            Crc32 crc = new Crc32();

            byte[] crc_code = crc.ComputeHash(cmd);
            byte[] cmd_ret  = new byte[cmd.Length + crc_code.Length];
            cmd.CopyTo(cmd_ret, 0);
            crc_code.CopyTo(cmd_ret, cmd.Length);
            return(cmd_ret);
        }
Example #2
0
        public static byte[] Write42Vset35IntoMemory(uint CmdNumber, int kiek, double value42Vset35, int Address, bool useAorB, int cmd_length = 13)
        {
            //naudojama įrašyti tiesiogiai 42Vset35 darbinei įtampai ( 3,5 - 4,2 kV ribos);
            //Upd: pasikeitė ribos - 2- 4 kV:
            byte[] cmd_w_crc = new byte[7];
            cmd_w_crc[0] = 0x1b;
            cmd_w_crc[1] = 0x77;
            cmd_w_crc[2] = (byte)CmdNumber;
            cmd_w_crc[3] = (byte)(kiek + 1);
            cmd_w_crc[4] = (byte)Address;
            //duomenys:
            byte[] Uarray = ExternalFunctions.get42Vset35array(value42Vset35, useAorB);
            cmd_w_crc[5] = Uarray[0]; //tikrinti, koks yra vyr jaun bitai;
            cmd_w_crc[6] = Uarray[1];
            //crc skaičiavimas
            Crc32 crc = new Crc32();

            byte[] crc_code = crc.ComputeHash(cmd_w_crc);

            //======cmd section
            byte[] cmd = new byte[crc_code.Length + cmd_w_crc.Length];
            cmd_w_crc.CopyTo(cmd, 0);
            crc_code.CopyTo(cmd, cmd_w_crc.Length);
            //==grąžinama komanda vykdymui:
            return(cmd);
        }