コード例 #1
0
        public void setLED(int myDevice) // command to set LED color
        {
            byte[] color = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            switch (device[myDevice].activeCoil) // based on which coil is currently active - determine which color the LED should be.
            {
            case 0:
            {
                color[0] = 0xff;
                color[1] = 0xff;
                device[myDevice].ledColor = "red";
                break;
            }

            case 1:
            {
                color[2] = 0xff;
                color[3] = 0xff;
                device[myDevice].ledColor = "green";
                break;
            }

            case 2:
            {
                color[4] = 0xff;
                color[5] = 0xff;
                device[myDevice].ledColor = "blue";
                break;
            }
            }
            GeneralCommand writeColor = new GeneralCommand(device[myDevice].m_si, 0x01, 0x0C, new byte[] { color[0], color[1], color[2], color[3], color[5], color[5] }, "set led color");

            writeColor.RegisterListener(this); device[myDevice].target.Queue(writeColor);
        }
コード例 #2
0
        private void GetApplicationVersionSync()
        {
            GeneralCommand app_vers = new GeneralCommand(m_interface, 0x01, 0x1E, null, "get application version");

            app_vers.RegisterListener(this);
            m_target.Queue(app_vers);
            m_target.Wait();
        }
コード例 #3
0
        public void Run(string com_port, string full_file_name)
        {
            bool abort = false;

            m_full_file_name = full_file_name;
            m_interface      = new WcaInterfaceLibrary.SerialInterface(com_port, globals.baud, Parity.None, 8);
            m_target         = new Target();
            m_interface.RegisterListener(this);

            Console.WriteLine("Wait until charger is ready.");

            if (m_interface.Open() && File.Exists(m_full_file_name))
            {
                while (!abort)
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKey key = Console.ReadKey().Key;

                        switch (key)
                        {
                        case ConsoleKey.Escape:
                            abort = true;
                            break;
                        }
                    }

                    if (m_start_indication_received.WaitOne(2000))
                    {
                        m_start_indication_received.Reset();
                        Thread.Sleep(400);
                        GeneralCommand set_bl = new GeneralCommand(m_interface, 0x01, 0x24, new byte[] { 0x01, 0x03, 0x7D }, "keep bootloader running");
                        set_bl.RegisterListener(this);
                        m_target.Queue(set_bl);
                        m_target.Wait();
                        Thread.Sleep(500);
                        GetApplicationVersionSync();
                        Upload();
                        Thread.Sleep(200);
                        GetApplicationVersionSync();
                        Console.WriteLine("Flashing done.");
                        abort = true;
                    }
                }
            }
            else
            {
                Console.WriteLine("COM port cannot be opened or file does not exists. Pls. check both of them.");
            }

            m_interface.Close();
        }
コード例 #4
0
        public void resendCommand() // command called by the check funciton if there is a failed command. it repackages the command info and resends it.
        {

            for (int a = 0; a < rerunIndex; a++) //runs through all failed commands regardless if there is only 1 failed command
            {
                int currentIndex = 0;
                for (int b = 0; b < deviceNum; b++) // runs through all devices refardless if there is only 1 device
                {
                    if (device[b].comport.Equals(myRerun[a].comport)) currentIndex = b; // need to know what device index needs a command to be resent - so i compare comports
                }
                if (device[currentIndex].count < 58) // we don't want any repetitive commands from this coil loop to enter into the next coil loop to we stop sending commands for the last second of the loop.
                {
                    GeneralCommand rerunCommand = new GeneralCommand(device[currentIndex].m_si, 0x01, myRerun[a].command, myRerun[a].data, "resent command");
                    rerunCommand.RegisterListener(this); device[currentIndex].target.Queue(rerunCommand);
                    device[currentIndex].ackFailures = myRerun[a].name;
                    writeToLog(currentIndex, true);
                    device[currentIndex].ackFailures = "";
                }
            }
            rerunIndex = 0; // after all failed commands are resent, set this value back to 0
            myRerun = new rerun[20]; // also creat a new stuct array
        }
コード例 #5
0
        public void readESN_HW(int myDevice)                                                                                                 // read the esn and hw version
        {
            GeneralCommand readParaLE = new GeneralCommand(device[myDevice].m_si, 0x01, 0x03, new byte[] { 0x03, 0x01 }, "read ESN and HW"); //"read general device parameters for ESN (little endian)");

            readParaLE.RegisterListener(this); device[myDevice].target.Queue(readParaLE);
        }
コード例 #6
0
        public void readAppID(int myDevice) // read the application ID
        {
            GeneralCommand readAppVer = new GeneralCommand(device[myDevice].m_si, 0x01, 0x1E, new byte[] { }, "read Application Version");

            readAppVer.RegisterListener(this); device[myDevice].target.Queue(readAppVer);
        }
コード例 #7
0
        public void readTemp(int myDevice)                                                                                          // read temp values for all 3 coils
        {
            GeneralCommand readtemp = new GeneralCommand(device[myDevice].m_si, 0x01, 0x04, new byte[] { 0x11 }, "read coil temp"); //"read runtime parameter: Requests the temperature values of all available sensors in degree celcius.");

            readtemp.RegisterListener(this); device[myDevice].target.Queue(readtemp);                                               // read coil temps
        }
コード例 #8
0
        public void readCADC(int myDevice)                                                                                                 // read coil current rms value
        {
            GeneralCommand readcadc = new GeneralCommand(device[myDevice].m_si, 0x01, 0x04, new byte[] { 0x0A }, "read coil current RMS"); //"read runtime parameter: Requests the Coil RMS Current");

            readcadc.RegisterListener(this); device[myDevice].target.Queue(readcadc);
        }
コード例 #9
0
        public void readVADC(int myDevice)                                                                                            // read adc count for voltage
        {
            GeneralCommand readVadc = new GeneralCommand(device[myDevice].m_si, 0x01, 0x04, new byte[] { 0x08 }, "read ADC Voltage"); //"read runtime parameter: Requests the ADC count of the measured H - bridge input voltage.");

            readVadc.RegisterListener(this); device[myDevice].target.Queue(readVadc);
        }
コード例 #10
0
        public void stopCoils(int myDevice)                                                                                                  // stop any active coil.
        {
            GeneralCommand stopcoils = new GeneralCommand(device[myDevice].m_si, 0x01, 0x06, new byte[] { 0x19, 0x0F }, "stop active coil"); // have to stop all coils first before setting new coils.

            stopcoils.RegisterListener(this); device[myDevice].target.Queue(stopcoils);
        }
コード例 #11
0
        public void setCoil(int myDevice) // set which coil should be active
        {
            GeneralCommand setactivecoil = new GeneralCommand(device[myDevice].m_si, 0x01, 0x06, new byte[] { 0x19, Convert.ToByte(device[myDevice].activeCoil) }, "set active coil");

            setactivecoil.RegisterListener(this); device[myDevice].target.Queue(setactivecoil);
        }
コード例 #12
0
        public void readCoil(int myDevice) // command to request which coil is active
        {
            GeneralCommand readactivecoil = new GeneralCommand(device[myDevice].m_si, 0x01, 0x06, new byte[] { 0x19 }, "read active coil");

            readactivecoil.RegisterListener(this); device[myDevice].target.Queue(readactivecoil);
        }
コード例 #13
0
        public void readLED(int myDevice) // command to request the LED color
        {
            GeneralCommand readColor = new GeneralCommand(device[myDevice].m_si, 0x01, 0x0E, new byte[] { }, "read led color");

            readColor.RegisterListener(this); device[myDevice].target.Queue(readColor);
        }