private void sim_SendData(string Data)
        {
            byte[]         Buffer = DEFAULT_ENCODE.GetBytes(Data + "\x00");
            COPYDATASTRUCT cds;

            if (SimProc == null || SimProc.HasExited) // do we need to launch a new simulator?
            {
                TimeOutManager OpTimer = new TimeOutManager();
                string         path    = System.Reflection.Assembly.GetExecutingAssembly().Location; //Get App Path
                path    = System.IO.Path.GetDirectoryName(path);                                     //remove App exe from App Path
                SimProc = new Process();
                SimProc.StartInfo.FileName         = System.IO.Path.Combine(path, "alphasim.exe");
                SimProc.StartInfo.WorkingDirectory = path;
                SimProc.StartInfo.Arguments        = " -class simwin";
                SimProc.Start();

                OpTimer.Start();
                while (SimProc.MainWindowHandle == IntPtr.Zero && !OpTimer.IsTimedOut)
                {
                    System.Threading.Thread.Sleep(100); // don't pester windows
                    SimProc.Refresh();                  // need this to refresh MainWindowHandle property
                }

                if (SimProc.MainWindowHandle == IntPtr.Zero)
                {
                    throw new Exception("Cannot launch simulator:" + SimProc.StartInfo.FileName);
                }
                SetWindowPos(SimProc.MainWindowHandle, HWND_TOPMOST, Sim_X, Sim_Y, 0, 0, SWP_NOSIZE);
            }

            IntPtr ptrData = Marshal.AllocCoTaskMem(Buffer.Length);

            Marshal.Copy(Buffer, 0, ptrData, Buffer.Length);
            cds.dwData = (IntPtr)0x24A;
            cds.cbData = Buffer.Length;
            cds.lpData = ptrData;
            int Ret = SendMessage(SimProc.MainWindowHandle, WM_COPYDATA, (int)OwnerHandle, ref cds);

            if (Ret == 0)
            {
                throw new Exception("Win32 SendMessage Failed");
            }
            //Marshal.FreeCoTaskMem(ptrData); // receiver must deallocate
        }
        private void serial_SendData(string Data)
        {
            TimeOutManager OpTimer = new TimeOutManager();
            SerialPort     RS232   = new SerialPort();

            RS232.Encoding = DEFAULT_ENCODE;    // IMPORTANT FOR CHARACTERS >127
            RS232.PortName = "COM" + Serial_Port.ToString();
            SetSerial(Serial_Settings, ref RS232);

            RS232.Open();

            RS232.Write(Data);

            OpTimer.Start();
            while (RS232.BytesToWrite > 0 && !OpTimer.IsTimedOut)
            {
                ;
            }

            RS232.Close();
        }