예제 #1
0
        public static void Pgm(String stSeconds, Queue <int> iQueue, Int16 lenQueue2, Int16 lenQueue4, bool flagDebug)
        {
            MyDLL.setWhite(0);
            MyDLL.cleanScreen();
            MyDLL.setAutoMaxMin(true, true);
            int ScaleValue = MyDLL.getScaleMove();

            WriteDebug.Pgm("MOVE = " + ScaleValue.ToString(), flagDebug);
            if (stSeconds == "4S")
            {
                for (int x = 0; x <= lenQueue4; x++)
                {
                    if (x % 4 == ScaleValue)
                    {
                        MyDLL.addData(iQueue.ElementAt(x));
                    }
                }
            }
            if (stSeconds == "2S")
            {
                for (int x = 0; x <= lenQueue2; x++)
                {
                    if (x % 2 == ScaleValue)
                    {
                        MyDLL.addData(iQueue.ElementAt(x));
                    }
                }
            }
        }
예제 #2
0
 public static String[] Pgm(bool flagDebug)
 {
     MyDLL.addCOMPort("");
     String[] ports = SerialPort.GetPortNames();
     // Add port list
     if (ports.Count() != 0)
     {
         String ListPort = "";
         foreach (string port in ports)
         {
             if (!ListPort.Contains(port))
             {
                 ListPort = ListPort + port + ",";
             }
             WriteDebug.Equals("SERIALPORT = " + port, flagDebug);
         }
         if (ListPort != "")
         {
             MyDLL.addCOMPort(ListPort);
         }
         else
         {
             MyDLL.addCOMPort("");
         }
     }
     return(ports);
 }
예제 #3
0
 //**********************************************************************************//
 //
 //**********************************************************************************//
 private static bool initPORTCOM(String PortName)
 {
     if (PortName == "")
     {
         WriteDebug.Pgm("NO COM port", FlagDebug);
         MyDLL.setVisible("START", false);
         MyDLL.setVisible("STOP", false);
         MyDLL.setVisible("1S1", false);
         MyDLL.setVisible("1S2", false);
         MyDLL.setVisible("1S3", false);
         MyDLL.setVisible("1S4", false);
         MyDLL.setVisible("2S1", false);
         MyDLL.setVisible("2S2", false);
         MyDLL.setVisible("4S", false);
     }
     else
     {
         if (!ComPort.IsOpen)
         {
             try
             {
                 WriteDebug.Pgm("Init COM port", FlagDebug);
                 ComPort.PortName  = PortName;
                 ComPort.BaudRate  = 115200;
                 ComPort.DataBits  = 8;
                 ComPort.StopBits  = StopBits.One;
                 ComPort.RtsEnable = false;
                 ComPort.Handshake = Handshake.None;
                 ComPort.Parity    = Parity.None;
                 //ComPort.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
                 ComPort.Open();
             }
             catch (Exception ex)
             {
                 WriteDebug.Pgm("ERROR : init COM port - " + ex.Message.ToString(), FlagDebug);
                 return(false);
             }
         }
         else
         {
             WriteDebug.Pgm("COM port is still opened", FlagDebug);
         }
         int totalBytes = ComPort.BytesToRead;
         while (totalBytes > 0)
         {
             char[] buffer = new char[totalBytes];
             ComPort.Read(buffer, 0, totalBytes);
             Thread.Sleep(100);
             totalBytes = ComPort.BytesToRead;
         }
     }
     return(true);
 }
예제 #4
0
 public static void Pgm(SerialPort comPort, int longueur, Int16 lenQueue1, Int16 lenQueue2, Int16 lenQueue3, Int16 lenQueue4, bool flagDebug)
 {
     try
     {
         int totalBytes = comPort.BytesToRead;
         while (totalBytes > 0)
         {
             WriteDebug.Pgm("Send data END (E)", flagDebug);
             comPort.Write("E");
             char[] buffer = new char[totalBytes];
             comPort.Read(buffer, 0, totalBytes);
             Thread.Sleep(100);
             totalBytes = comPort.BytesToRead;
             if (buffer[1] == 'j' && buffer[2] == 'o' && buffer[3] == '?')
             {
                 totalBytes = 0;
             }
         }
         totalBytes = comPort.BytesToRead;
         char[] buffer2 = new char[totalBytes];
         comPort.Read(buffer2, 0, totalBytes);
     }
     catch {}
     MyDLL.setVisible("START", true);
     MyDLL.setVisible("REFRESH", true);
     MyDLL.setVisible("STOP", false);
     MyDLL.setVisible("HELP", true);
     MyDLL.setAutoMaxMin(false, false);
     if (longueur > lenQueue4)
     {
         MyDLL.setVisible("1S", true);
         MyDLL.setVisible("2S", true);
         MyDLL.setVisible("4S", true);
     }
     else
     {
         if (longueur > lenQueue3)
         {
             MyDLL.setVisible("1S", true);
             MyDLL.setVisible("2S", true);
         }
         else
         {
             if (longueur > lenQueue1)
             {
                 MyDLL.setVisible("1S", true);
             }
         }
     }
 }
예제 #5
0
 public static bool Pgm(SerialPort comPort, bool flagDebug)
 {
     try
     {
         int totalBytes = comPort.BytesToRead;
         while (totalBytes > 0)
         {
             char[] buffer = new char[totalBytes];
             comPort.Read(buffer, 0, totalBytes);
             Thread.Sleep(100);
             totalBytes = comPort.BytesToRead;
         }
         int retValue = 0;
         while (retValue != 65534)
         {
             WriteDebug.Pgm("Send data BEGIN (B)", flagDebug);
             comPort.Write("B");
             retValue = readCOM.Pgm(comPort, true, flagDebug);
         }
     }
     catch (Exception ex)
     {
         WriteDebug.Pgm("ERROR : COM port - " + ex.Message.ToString(), flagDebug);
         MyDLL.writeMessage("ERROR", "START button", "Error Com port !");
         return(false);
     }
     MyDLL.setVisible("START", false);
     MyDLL.setVisible("REFRESH", false);
     MyDLL.setVisible("SAVE", false);
     MyDLL.setVisible("INSIDE", false);
     MyDLL.setVisible("MOVE", false);
     MyDLL.setVisible("1S", false);
     MyDLL.setVisible("2S", false);
     MyDLL.setVisible("4S", false);
     MyDLL.setVisible("STOP", true);
     MyDLL.setVisible("HELP", false);
     MyDLL.setAutoMaxMin(true, true);
     MyDLL.cleanScreen();
     MyDLL.setWhite(50);
     MyDLL.setVisible("MAX", true);
     return(true);
 }
예제 #6
0
 //**********************************************************************************//
 //
 //**********************************************************************************//
 private static void ENDApplication()
 {
     while (!MyDLL.getStatusClose())
     {
         Thread.Sleep(500);
     }
     try
     {
         WriteDebug.Pgm("Send data : E", FlagDebug);
         ComPort.Write("E");
     }
     catch (Exception) { }
     try
     {
         if (ComPort.IsOpen)
         {
             Thread.Sleep(500);
             ComPort.Close();
         }
     }
     catch (Exception) { }
     Thread.Sleep(500);
     Environment.Exit(0);
 }
예제 #7
0
        public static int Pgm(SerialPort comPort, bool flagWait, bool flagDebug)
        {
            byte[] buffer   = new byte[10];
            int    retValue = 65100;
            Thread tWait;

            try
            {
                if (!flagWait)
                {
                    while (comPort.BytesToRead < 4)
                    {
                    }
                }
                else
                {
                    tWait = new Thread(pgmWait);
                    tWait.Start();
                    while ((comPort.BytesToRead < 4) && FlagWait)
                    {
                    }
                    tWait.Abort();
                }
                int dimension = comPort.BytesToRead;
                buffer[0] = (byte)comPort.ReadChar();
                buffer[1] = (byte)comPort.ReadChar();
                buffer[2] = (byte)comPort.ReadChar();
                buffer[3] = (byte)comPort.ReadChar();
                if (buffer[3] != 10)
                {
                    if (buffer[0] == 10)
                    {
                        WriteDebug.Pgm("ERROR read 1 -char 10", flagDebug);
                        buffer[0] = buffer[1];
                        buffer[1] = buffer[2];
                        buffer[2] = buffer[3];
                        buffer[3] = (byte)comPort.ReadChar();
                    }
                    else
                    {
                        if (buffer[1] == 10)
                        {
                            WriteDebug.Pgm("ERROR read 2 -char 10", flagDebug);
                            buffer[0] = buffer[2];
                            buffer[1] = buffer[3];
                            buffer[2] = (byte)comPort.ReadChar();
                            buffer[3] = (byte)comPort.ReadChar();
                        }
                        else
                        {
                            if (buffer[2] == 10)
                            {
                                WriteDebug.Pgm("ERROR read 3 -char 10", flagDebug);
                                buffer[0] = buffer[3];
                                buffer[1] = (byte)comPort.ReadChar();
                                buffer[2] = (byte)comPort.ReadChar();
                                buffer[3] = (byte)comPort.ReadChar();
                            }
                            else
                            {
                                WriteDebug.Pgm("ERROR Other - char 10", flagDebug);
                            }
                        }
                    }
                }
                retValue = ((Convert.ToInt32(buffer[0]) - 0x30) & 0x0000003F) +
                           (((Convert.ToInt32(buffer[1]) - 0x30) << 6) & 0x00000FC0) +
                           (((Convert.ToInt32(buffer[2]) - 0x30) << 12) & 0x0000F000);
                //wDebug("=> " + retValue.ToString(),flagDebug);
            }
            catch (Exception)
            {}
            if (retValue == 65100)
            {
                doNothing();
            }
            return(retValue);
        }
예제 #8
0
        public static int Pgm(String stSeconds, int longeur, Int16 lenQueue1, Int16 lenQueue2, Int16 lenQueue3, Int16 lenQueue4, bool flagDebug)
        {
            MyDLL.setWhite(0);
            MyDLL.cleanScreen();
            MyDLL.setAutoMaxMin(true, true);
            int ScaleValue = MyDLL.getScaleInside();

            WriteDebug.Pgm("INSIDE = " + ScaleValue.ToString(), flagDebug);
            int valDecale = 0;

            if (stSeconds == "1S")
            {
                valDecale = ScaleValue * 250;
                if ((lenQueue1 + valDecale) < longeur)
                {
                    switch (ScaleValue)
                    {
                    case 0:
                        MyDLL.setZero("0");
                        MyDLL.setValueX("0.25", "0.5", "0.75", "1s");
                        break;

                    case 1:
                        MyDLL.setZero("0.25");
                        MyDLL.setValueX("0.5", "0.75", "1", "1.25s");
                        break;

                    case 2:
                        MyDLL.setZero("0.5");
                        MyDLL.setValueX("0.75", "1", "1.25", "1.5s");
                        break;

                    case 3:
                        MyDLL.setZero("0.75");
                        MyDLL.setValueX("1", "1.25", "1.5", "1.75s");
                        break;

                    case 4:
                        MyDLL.setZero("1");
                        MyDLL.setValueX("1.25", "1.5", "1.75", "2s");
                        break;

                    case 5:
                        MyDLL.setZero("1.25");
                        MyDLL.setValueX("1.5", "1.75", "2", "2.25s");
                        break;

                    case 6:
                        MyDLL.setZero("1.5");
                        MyDLL.setValueX("1.75", "2", "2.25", "2.5s");
                        break;

                    case 7:
                        MyDLL.setZero("1.75");
                        MyDLL.setValueX("2", "2.25", "2.5", "2.75s");
                        break;

                    case 8:
                        MyDLL.setZero("2");
                        MyDLL.setValueX("2.25", "2.5", "2.75", "3s");
                        break;

                    case 9:
                        MyDLL.setZero("2.25");
                        MyDLL.setValueX("2.5", "2.75", "3", "3.25s");
                        break;

                    case 10:
                        MyDLL.setZero("2.5");
                        MyDLL.setValueX("2.75", "3", "3.25", "3.5s");
                        break;

                    case 11:
                        MyDLL.setZero("2.75");
                        MyDLL.setValueX("3", "3.25", "3.5", "3.75s");
                        break;

                    case 12:
                        MyDLL.setZero("3");
                        MyDLL.setValueX("3.25", "3.5", "3.75", "4s");
                        break;

                    default:
                        break;
                    }
                }
            }
            if (stSeconds == "2S")
            {
                valDecale = ScaleValue * 500;
                if ((lenQueue1 + valDecale) < longeur)
                {
                    switch (ScaleValue)
                    {
                    case 0:
                        MyDLL.setZero("0");
                        MyDLL.setValueX("0.5", "1", "1.5", "2s");
                        break;

                    case 1:
                        MyDLL.setZero("0.5");
                        MyDLL.setValueX("1", "1.5", "2", "2.5s");
                        break;

                    case 2:
                        MyDLL.setZero("1");
                        MyDLL.setValueX("1.5", "2", "2.5", "3s");
                        break;

                    case 3:
                        MyDLL.setZero("1.5");
                        MyDLL.setValueX("2", "2.5", "3", "3.5s");
                        break;

                    case 4:
                        MyDLL.setZero("2");
                        MyDLL.setValueX("2.5", "3", "3.5", "4s");
                        break;

                    default:
                        break;
                    }
                }
            }
            return(valDecale);
        }
예제 #9
0
        //**********************************************************************************//
        //
        //**********************************************************************************//
        private static void launchRECEIVE()
        {
            try
            {
                int ComptNoReceive = 0;
                while (true)
                {
                    if (FlagReceive)
                    {
                        int iRead = 0;
                        while ((byte)ComPort.ReadChar() != '\n')
                        {
                            ComptNoReceive++;
                            iRead++;
                            if (ComptNoReceive > 2000)
                            {
                                WriteDebug.Pgm("Compteur No Receive : " + ComptNoReceive.ToString(), FlagDebug);
                                ComptNoReceive = 0;
                            }
                        }
                        ComptNoReceive = 0;
                        if (FlagDebug)
                        {
                            if (iRead > 0)
                            {
                                WriteDebug.Pgm("Error decalage : " + iRead, FlagDebug);
                            }
                        }
                        while (FlagReceive)
                        {
                            int Value = readCOM.Pgm(ComPort, false, FlagDebug);
                            //wDebug("=> " + Value.ToString());
                            if (Value > 40000)
                            {
                                WriteDebug.Pgm("=> " + Value.ToString(), FlagDebug);
                                // 40184
                                WriteDebug.Nothing();
                                switch (Value)
                                {
                                case 65530:
                                    MyDLL.writeMessage("WARNING", "MicroSupply disconneted !", "Warning datas received !");
                                    FlagReceive = false;
                                    stop.Pgm(ComPort, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug);
                                    break;

                                // OK launch datas serial
                                case 65520:
                                    MyDLL.writeMessage("ERROR", "MicroSupply disconneted !", "Low Power Output !");
                                    FlagReceive = false;
                                    stop.Pgm(ComPort, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug);
                                    break;

                                case 65100:
                                    FlagReceive = false;
                                    try
                                    {
                                        if (ComPort.IsOpen)
                                        {
                                            WriteDebug.Pgm("Send data : E", FlagDebug);
                                            ComPort.Write("E");
                                        }
                                    }
                                    catch (Exception) { }
                                    try
                                    {
                                        if (ComPort.IsOpen)
                                        {
                                            Thread.Sleep(500);
                                            ComPort.Close();
                                        }
                                    }
                                    catch (Exception) { }
                                    Thread.Sleep(500);
                                    MyDLL.writeMessage("ERROR", "MicroSupply Error Serial Port", "ERROR Serial Port ! \n\n EXIT");
                                    t.Abort();
                                    Environment.Exit(0);
                                    break;

                                default:
                                    break;
                                }
                            }
                            else
                            {
                                intQueue.Enqueue(Value);
                                if (intQueue.Count > LenQueue)
                                {
                                    int firstToLeave = intQueue.Dequeue();
                                }
                                MyDLL.addData(Value);
                                if (MyDLL.getStatusScale())
                                {
                                    int ValScale = MyDLL.getScale();
                                    if (ValScale == 0)
                                    {
                                        MyDLL.setValueY("10", "20", "30", "40", "µA");
                                    }
                                    else
                                    {
                                        if (ValScale == 1)
                                        {
                                            MyDLL.setValueY("100", "200", "300", "400", "µA");
                                        }
                                        else
                                        {
                                            if (ValScale == 10)
                                            {
                                                MyDLL.setValueY("1", "2", "3", "4", "mA");
                                            }
                                            else
                                            {
                                                if (ValScale == 100)
                                                {
                                                    MyDLL.setValueY("10", "20", "30", "40", "mA");
                                                }
                                                else
                                                {
                                                    MyDLL.setValueY("-", "-", "-", "-", "?");
                                                }
                                            }
                                        }
                                        WriteDebug.Nothing();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception)
            {
                FlagReceive = false;
                MyDLL.setVisible("START", false);
                MyDLL.setVisible("STOP", false);
            }
        }
예제 #10
0
        //**********************************************************************************//
        // Main program (if arg is "DEBUG" than the Console mode not be hiden
        // and debug informations will be print
        //**********************************************************************************//
        static void Main(string[] args)
        {
            // test arg = DEBUG
            if (args.Length > 0)
            {
                if (args[0].ToUpper() == "DEBUG")
                {
                    FlagDebug = true;
                }
            }
            // test Version Windows 10
            WriteDebug.Pgm("<< Test Version Windows 10 >>", FlagDebug);
            String Version  = GetOsVer().ToString().Replace(".", "");
            Int64  xVersion = 0;

            if (Int64.TryParse(Version, out xVersion))
            {
                WriteDebug.Pgm("Version Windows : " + xVersion.ToString(), FlagDebug);
                if (xVersion < 10014393)
                {
                    String errorVer = "Version Windows 10 is not updated : " + Version;
                    MessageBox((IntPtr)0, errorVer, "Error Windows 10", 0);
                    Environment.Exit(0);
                }
            }
            else
            {
                if (Version != "")
                {
                    MessageBox((IntPtr)0, "Version Windows 10 not found", "Error Windows 10", 0);
                    Environment.Exit(0);
                }
            }
            // test JAVA files
            WriteDebug.Pgm("<< Test folder Java >>", FlagDebug);
            try
            {
                bool bJava = Directory.Exists("C:\\Program files\\Java");
                if (!bJava)
                {
                    bJava = Directory.Exists("C:\\Program Files (x86)\\Java");
                    if (!bJava)
                    {
                        MessageBox((IntPtr)0, "Folder Java doesn't found !", "Error Java", 0);
                        Environment.Exit(0);
                    }
                }
            }
            catch
            {
                MessageBox((IntPtr)0, "Folder Java doesn't found !", "Error Java", 0);
                Environment.Exit(0);
            }
            // test version Java
            WriteDebug.Pgm("<< Test Version Java >>", FlagDebug);
            int verJava = 0;

            try
            {
                String registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey))
                {
                    foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                    {
                        string oneKey = subkey.GetValue("DisplayName") as string;

                        if (oneKey != null && oneKey.Contains("Java") && !oneKey.Contains("Updater"))
                        {
                            string versionMEM = subkey.GetValue("DisplayVersion") as String;
                            WriteDebug.Pgm("<< Version Java (1) >> " + versionMEM, FlagDebug);
                            string[] tempo = versionMEM.Split('.');
                            verJava = int.Parse(tempo[0]);
                        }
                    }
                }
                if (verJava == 0)
                {
                    registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey))
                    {
                        foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                        {
                            string oneKey = subkey.GetValue("DisplayName") as string;

                            if (oneKey != null && oneKey.Contains("Java") && !oneKey.Contains("Updater"))
                            {
                                string versionMEM = subkey.GetValue("DisplayVersion") as String;
                                WriteDebug.Pgm("<< Version Java (2) >> " + versionMEM, FlagDebug);
                                string[] tempo = versionMEM.Split('.');
                                verJava = int.Parse(tempo[0]);
                            }
                        }
                    }
                }
                if (verJava == 0)
                {
                    registryKey = @"SOFTWARE\JavaSoft\Java Runtime Environment";
                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey))
                    {
                        string versionMEM = key.GetValue("CurrentVersion") as string;
                        WriteDebug.Pgm("<< Version Java (3) >> " + versionMEM, FlagDebug);
                        string[] tempo = versionMEM.Split('.');
                        verJava = int.Parse(tempo[1]);
                    }
                }
                if (verJava == 0)
                {
                    registryKey = @"SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment";
                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey))
                    {
                        string versionMEM = key.GetValue("CurrentVersion") as string;
                        WriteDebug.Pgm("<< Version Java (4) >> " + versionMEM, FlagDebug);
                        string[] tempo = versionMEM.Split('.');
                        verJava = int.Parse(tempo[1]);
                    }
                }

                if (verJava < 8)
                {
                    MessageBox((IntPtr)0, "Java must have version 1.8 or over !", "Error version Java", 0);
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                MessageBox((IntPtr)0, "ERROR : " + ex.Message.ToString(), "Error version Java", 0);
                Environment.Exit(0);
            }
            // test files IKVM
            WriteDebug.Pgm("<< Test IKVM DLL files >>", FlagDebug);
            if (!File.Exists("ikvm-native-win32-x64.dll"))
            {
                MessageBox((IntPtr)0, "file ikvm-native-win32-x64.dll is missing", "File missing", 0);
                Environment.Exit(0);
            }
            if (!File.Exists("IKVM.OpenJDK.Core.dll"))
            {
                MessageBox((IntPtr)0, "file IKVM.OpenJDK.Core.dll is missing", "File missing", 0);
                Environment.Exit(0);
            }
            // test files SWT
            WriteDebug.Pgm("<< Test files SWT >>", FlagDebug);
            String pathSWT = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

            pathSWT += "\\.swt\\lib\\win32\\x86_64";
            bool[] bools = new bool[6];
            bools[0] = File.Exists(pathSWT + "\\swt-gdip-win32-4233.dll");
            bools[1] = File.Exists(pathSWT + "\\swt-gdip-win32-4763.dll");
            bools[2] = File.Exists(pathSWT + "\\swt-gdip-win32-4919.dll");
            bools[3] = File.Exists(pathSWT + "\\swt-win32-4233.dll");
            bools[4] = File.Exists(pathSWT + "\\swt-win32-4763.dll");
            bools[5] = File.Exists(pathSWT + "\\swt-win32-4919.dll");
            int[] arrs     = Array.ConvertAll(bools, b => b ? 0 : 1);
            int   arrCount = arrs[0] + arrs[1] + arrs[2] + arrs[3] + arrs[4] + arrs[5];

            switch (arrCount)
            {
            case 0:
                break;

            case 1:
                String stFile = "";
                if (bools[0])
                {
                    stFile = "swt-gdip-win32-4233.dll";
                }
                if (bools[1])
                {
                    stFile = "swt-gdip-win32-4763.dll";
                }
                if (bools[2])
                {
                    stFile = "swt-gdip-win32-4919.dll";
                }
                if (bools[3])
                {
                    stFile = "swt-win32-4233.dll";
                }
                if (bools[4])
                {
                    stFile = "swt-win32-4763.dll";
                }
                if (bools[5])
                {
                    stFile = "swt-win32-4919.dll";
                }
                MessageBox((IntPtr)0, "file " + stFile + " is missing in " + pathSWT, "File missing", 0);
                Environment.Exit(0);
                break;

            case 2:
            case 3:
            case 4:
            case 5:
                MessageBox((IntPtr)0, arrCount + " files missing in " + pathSWT, "Files missing", 0);
                Environment.Exit(0);
                break;

            case 6:
                MessageBox((IntPtr)0, "All files missing in " + pathSWT, "Files missing", 0);
                Environment.Exit(0);
                break;

            default:
                break;
            }
            // test if no COM port
            WriteDebug.Pgm("<< Test if COM port found >>", FlagDebug);
            string[] testPorts = SerialPort.GetPortNames();
            if (testPorts.Count() == 0)
            {
                MessageBox((IntPtr)0, "No COM port found !", "Error port COM", 0);
                Environment.Exit(0);
            }
            // Application standard
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            // Hide Console if not debug mode
            if (!FlagDebug)
            {
                var handle = GetConsoleWindow();
                ShowWindow(handle, SW_HIDE);
            }
            else
            {
                WriteDebug.Pgm("<< BEGIN >>", true);
            }
            // test to acces to the MicroSupply_JA.dll
            WriteDebug.Pgm("<< Test DLL MicroSupply_JA >>", FlagDebug);
            try
            {
                //String dllVersion = MyDLL.getVersion();
                //var thisApp = Assembly.GetExecutingAssembly();
                //AssemblyName name = new AssemblyName(thisApp.FullName);
                //String pgmVersion = name.Version.ToString().Substring(0, name.Version.ToString().Length - 2);
                //if (String.Compare(dllVersion, pgmVersion) == 0)
                //{
                //    WriteDebug.Pgm("MicroSupply_JA.dll Version : " + dllVersion, FlagDebug);
                //    WriteDebug.Pgm("MicroSupply.exe Version : " + pgmVersion, FlagDebug);
                //}
                //else
                //{
                //    WriteDebug.Pgm("Versions ERROR", true);
                //    WriteDebug.Pgm("MicroSupply_JA.dll Version : " + dllVersion, true);
                //    WriteDebug.Pgm("MicroSupply Version : " + pgmVersion, true);
                //    Thread.Sleep(5000);
                //    Environment.Exit(0);
                //}
            }
            catch (Exception e)
            {
                WriteDebug.Pgm(e.Message.ToString(), FlagDebug);
                Thread.Sleep(5000);
                Environment.Exit(0);
            }
            // INIT screen
            WriteDebug.Pgm("<< Launch the screen >>", FlagDebug);
            try
            {
                MyDLL.initScreenJA();
            }
            catch (Exception e)
            {
                WriteDebug.Pgm(e.Message.ToString(), FlagDebug);
                Thread.Sleep(5000);
                Environment.Exit(0);
            }

            try
            {
                while (!MyDLL.testScreenReady())
                {
                }
                MyDLL.setValueX("0.25", "0.5", "0.75", "1s");
                MyDLL.setValueY("10", "20", "30", "40", "µA");
                MyDLL.setVisible("COM", false);
                MyDLL.setVisible("REFRESH", false);
                MyDLL.setVisible("HELP", true);
                MyDLL.setVisible("EXIT", true);
                MyDLL.setVisible("START", false);
                // test arg = TEST
                if (args.Length > 0)
                {
                    if (args[0].ToUpper() == "TEST")
                    {
                        MyDLL.setVisible("COM", true);
                        MyDLL.setVisible("REFRESH", true);
                        MyDLL.setVisible("START", true);
                        MyDLL.setVisible("STOP", true);
                        MyDLL.setVisible("1S", true);
                        MyDLL.setVisible("2S", true);
                        MyDLL.setVisible("4S", true);
                        MyDLL.setVisible("SAVE", true);
                        MyDLL.setVisible("INSIDE", true);
                        MyDLL.setVisible("MOVE", true);
                        MyDLL.setVisible("MAX", true);
                        MyDLL.setVisible("MIN", true);
                        while (true)
                        {
                            while (!MyDLL.getStatusKey())
                            {
                            }
                            String stKey = MyDLL.getKeyValue();
                            WriteDebug.Pgm("KEY : " + stKey, FlagDebug);
                            if (stKey.Contains("EXIT"))
                            {
                                Thread.Sleep(500);
                                Environment.Exit(0);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                WriteDebug.Pgm(e.Message.ToString(), FlagDebug);
                Thread.Sleep(5000);
                Environment.Exit(0);
            }
            // Launch Thread if the screen will be closed
            t = new Thread(ENDApplication);
            t.Start();
            // Identify Serial port list
            string[] ports  = null;
            String   stPort = "";

            ports = SerialPort.GetPortNames();
            // Add port list
            MyDLL.setVisible("START", false);
            if (ports.Count() != 0)
            {
                String ListPort = "";
                bool   flagPort = true;
                foreach (string port in ports)
                {
                    if (ListPort.Contains(port))
                    {
                        flagPort = false;
                    }
                    else
                    {
                        ListPort = ListPort + port + ",";
                    }
                    WriteDebug.Pgm("COM PORT : " + port, FlagDebug);
                }
                if (!flagPort)
                {
                    string[] lports = ListPort.Split(',');
                    foreach (string port in lports)
                    {
                        try
                        {
                            if (port != "")
                            {
                                ComPort.PortName = port;
                                try
                                {
                                    ComPort.Open();
                                }
                                finally
                                {
                                    if (ComPort.IsOpen)
                                    {
                                        ComPort.Close();//<---this is the important bit!!!
                                    }
                                }
                                ComPort.Close();
                            }
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            //Process[] processlist = Process.GetProcesses();
                            //foreach (Process theprocess in processlist)
                            //{
                            //    Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
                            //}
                            try
                            {
                                ComPort.Close();
                            }
                            catch (UnauthorizedAccessException ex2)
                            {
                                WriteDebug.Log(FlagDebug);
                                WriteDebug.Pgm(ex2.Message.ToString(), FlagDebug);
                                WriteDebug.Log(FlagDebug);
                            }
                            WriteDebug.Log(FlagDebug);
                            WriteDebug.Pgm("ERROR : " + port + " port doesn't work", FlagDebug);
                            WriteDebug.Pgm(ex.Message.ToString(), FlagDebug);
                            WriteDebug.Log(FlagDebug);
                            MyDLL.writeMessage("ERROR", "MicroSupply ERROR", port + " port doesn't work !");
                            ListPort = ListPort.Replace(port + ",", "");
                        }
                        catch (IOException ex)
                        {
                            WriteDebug.Log(FlagDebug);
                            WriteDebug.Pgm("WARNING : " + port + " port can't be open", FlagDebug);
                            WriteDebug.Pgm(ex.Message.ToString(), FlagDebug);
                            WriteDebug.Log(FlagDebug);
                            MyDLL.writeMessage("WARNING", "MicroSupply WARNING", port + " port can't be open !");
                        }
                    }
                }
                //if (!flagPort)
                //{
                // error port COM
                //    wDebug("ERROR : A COM port doesn't work");
                //    MyDLL.writeMessage("ERROR", "MicroSupply ERROR", "A COM port doesn't work !");
                //    Thread.Sleep(500);
                //    t.Abort();
                //    Environment.Exit(0);
                //}
                MyDLL.setVisible("COM", true);
                MyDLL.setVisible("REFRESH", true);
                MyDLL.addCOMPort(ListPort);
                if (ports.Length == 1)
                {
                    initPORTCOM(ports[0]);
                    stPort = ports[0];
                    // Launch Thread to receive datas but not now (FlagReceive is false)
                    tw          = new Thread(launchRECEIVE);
                    FlagReceive = false;
                    tw.Start();
                }
            }

            // Wait a key to begin the program
            WriteDebug.Pgm("Wait Key Start", FlagDebug);
            String stTouchSeconds = "";

            while (true)
            {
                while (!MyDLL.getStatusKey())
                {
                }
                String stKey = MyDLL.getKeyValue();
                WriteDebug.Pgm("KEY : " + stKey, FlagDebug);
                // Refresh the port COM
                if (stKey.Contains("REFRESH"))
                {
                    ports = refresh.Pgm(FlagDebug);
                    if (ports.Length == 1)
                    {
                        bool bRet = initPORTCOM(ports[0]);
                        // Launch Thread to receive datas but not now
                        if (bRet)
                        {
                            tw          = new Thread(launchRECEIVE);
                            FlagReceive = false;
                            tw.Start();
                        }
                        else
                        {
                            MyDLL.addCOMPort("");
                        }
                    }
                }
                // COM port
                if (stKey.Contains("COM"))
                {
                    stPort = stKey.Replace(",", "");
                    initPORTCOM(stPort);
                    tw          = new Thread(launchRECEIVE);
                    FlagReceive = false;
                    tw.Start();
                    MyDLL.setVisible("START", true);
                }
                // START button
                if (stKey.Contains("START"))
                {
                    initPORTCOM(stPort);
                    bool codeReturn = start.Pgm(ComPort, FlagDebug);
                    FlagReceive = true;
                    MyDLL.setEnable("COM", false);
                }
                // STOP button
                if (stKey.Contains("STOP"))
                {
                    FlagReceive = false;
                    int retValue = 0;
                    while (retValue < 50000)
                    {
                        WriteDebug.Pgm("Send data END (E)", FlagDataDebug);
                        try
                        {
                            ComPort.Write("E");
                        }
                        catch { }
                        retValue = readCOM.Pgm(ComPort, true, FlagDebug);
                    }
                    stop.Pgm(ComPort, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug);
                    MyDLL.setEnable("COM", true);
                }
                // 1 secondes button
                if (stKey.Contains("1S"))
                {
                    stTouchSeconds = "1S";
                    seconds.Pgm("1S", intQueue, LenQueue1, LenQueue2, LenQueue3, LenQueue4);
                }
                // 2 secondes button
                if (stKey.Contains("2S"))
                {
                    stTouchSeconds = "2S";
                    seconds.Pgm("2S", intQueue, LenQueue1, LenQueue2, LenQueue3, LenQueue4);
                }
                // 4 secondes button
                if (stKey.Contains("4S"))
                {
                    stTouchSeconds = "4S";
                    seconds.Pgm("4S", intQueue, LenQueue1, LenQueue2, LenQueue3, LenQueue4);
                }
                // INSIDE button
                if (stKey.Contains("INSIDE"))
                {
                    int valDecale = inside.Pgm(stTouchSeconds, intQueue.Count, LenQueue1, LenQueue2, LenQueue3, LenQueue4, FlagDebug);
                    for (int x = valDecale; x <= (LenQueue1 + valDecale); x++)
                    {
                        MyDLL.addData(intQueue.ElementAt(x));
                    }
                }
                // MOVE button
                if (stKey.Contains("MOVE"))
                {
                    move.Pgm(stTouchSeconds, intQueue, LenQueue2, LenQueue4, FlagDebug);
                }
                // the SAVE button is choose
                if (stKey.Contains("SAVE"))
                {
                    save.Pgm(intQueue);
                }
                // the EXIT button is choose
                if (stKey.Contains("EXIT"))
                {
                    FlagReceive = false;
                    int retValue = 0;
                    while (retValue < 50000)
                    {
                        WriteDebug.Pgm("Send data END (E)", FlagDataDebug);
                        try
                        {
                            ComPort.Write("E");
                        }
                        catch { }
                        retValue = readCOM.Pgm(ComPort, true, FlagDebug);
                    }
                    try
                    {
                        if (ComPort.IsOpen)
                        {
                            Thread.Sleep(500);
                            ComPort.Close();
                        }
                    }
                    catch (Exception) { }
                    Thread.Sleep(500);
                    t.Abort();
                    Environment.Exit(0);
                }
                if (stKey.Contains("HELP"))
                {
                    WebRequest request = WebRequest.Create("http://www.acrd.fr");
                    try
                    {
                        request.GetResponse();
                    }
                    catch //If exception thrown then couldn't get response from address
                    {
                        WriteDebug.Pgm("The URL is incorrect", FlagDebug);
                    }
                }
            }
        }