public SimpleMode_Form.StepInfo TcpConnect()
        {
            SimpleMode_Form.StepInfo retSI = new SimpleMode_Form.StepInfo();

            try
            {
                StationConfig mySC = new StationConfig();
                if (mySC.GetTcpClientActive(ref this.TcpClientServer, ref this.TcpClientPort))
                {
                    this.Cursor          = Cursors.WaitCursor;
                    this.myTcpClientRead = new TcpClient(this.TcpClientServer, this.TcpClientPort);
                    NetworkStream myNS = this.myTcpClientRead.GetStream();
                    this.myTcpClientWrite = new TcpClient(this.TcpClientServer, this.TcpClientPort);
                    this.Cursor           = Cursors.Default;
                    String strTcpMessage   = String.Concat("1000;", this.actSN.SerialNumber, ";", this.Item);
                    byte[] bytesTcpMessage = Encoding.ASCII.GetBytes(strTcpMessage);

                    //MessageBox.Show(String.Concat("Posielam string \n", strTcpMessage, "\n\n byty:\n", bytesTcpMessage.ToString()));
                    this.myTcpClientWrite.Client.Send(bytesTcpMessage, 0, bytesTcpMessage.Length, SocketFlags.None);

                    /*
                     * this.myTcpClientRead.Client.Close();
                     * this.myTcpClientRead.Close();
                     */
                    //this.myTcpClientWrite = new TcpClient(this.TcpClientServer, this.TcpClientPort);


                    //NetworkStream myNS = this.myTcpClientRead.GetStream();
                    myNS.ReadTimeout = 2000;
                    bytesTcpMessage  = new byte[256];
                    String response = String.Empty;
                    Int32  bytes    = 0;
                    try
                    {
                        bytes = myNS.Read(bytesTcpMessage, 0, bytesTcpMessage.Length);
                    }
                    catch (IOException e)
                    {
                        MessageBox.Show("kamerovy program nebezi");
                        MessageBox.Show(e.Message);
                    }

                    String strTcpReceivedMessage = Encoding.ASCII.GetString(bytesTcpMessage, 0, bytes);
                    //MessageBox.Show(strTcpReceivedMessage);
                    if (strTcpReceivedMessage == "1001;OK")
                    {
                        this.Visible = false;
                        //myNS.Close();
                        //myNS = this.myTcpClientRead.GetStream();
                        myNS.ReadTimeout = -1;
                        bytesTcpMessage  = new byte[256];
                        response         = String.Empty;
                        //MessageBox.Show("Zaciatok cakania na vysledok kamerovej kontroly");
                        bytes = myNS.Read(bytesTcpMessage, 0, bytesTcpMessage.Length);
                        strTcpReceivedMessage = Encoding.ASCII.GetString(bytesTcpMessage, 0, bytes);
                        //MessageBox.Show(strTcpReceivedMessage);
                        if (strTcpReceivedMessage.Substring(0, 4) == "2000")
                        {
                            //this.myTcpClientWrite = new TcpClient(TcpClientServer, TcpClientPort);
                            strTcpMessage   = "2001;OK";
                            bytesTcpMessage = Encoding.ASCII.GetBytes(strTcpMessage);

                            //MessageBox.Show(String.Concat("Posielam string \n", strTcpMessage, "\n\n byty:\n", bytesTcpMessage.ToString()));
                            this.myTcpClientWrite.Client.Send(bytesTcpMessage, 0, bytesTcpMessage.Length, SocketFlags.None);
                        }
                        if (strTcpReceivedMessage.Substring(0, 9) == "2000;PASS")   //navratova hodnota po kamerovej kontrole
                        {
                            Thread.Sleep(2000);
                            retSI.Grade       = "PASS";
                            retSI.ResultValue = strTcpReceivedMessage.Substring(10);
                        }
                        else if (strTcpReceivedMessage.Substring(0, 9) == "2000;FAIL")
                        {
                            Thread.Sleep(2000);
                            retSI.Grade = "FAIL";
                            //retSI.ResultValue = strTcpReceivedMessage.Substring(10);
                        }
                        //MessageBox.Show(strTcpReceivedMessage.Substring(10));

                        this.Visible = true;
                    }
                    else
                    {
                        MessageBox.Show("TCP komunikacia nepracuje spravne. Zavolajte prosim technika.", "CHYBA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    myNS.Close();
                    this.myTcpClientWrite.Client.Close();
                    this.myTcpClientWrite.Close();
                }
            }
            catch (ArgumentNullException e)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("ArgumentNullException: {0}", e.Message);
            }
            catch (SocketException e)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("SocketException: {0}", e.Message);
            }

            return(retSI);
        }
        private void tb_Order_KeyUp(object sender, KeyEventArgs e)
        {
            if (!btn_Pass.Enabled)
            {
                return;
            }
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }
            String actOrder = this.tb_Order.Text.Trim();
            String buffer   = Regex.Match(actOrder, @"\d+").Value;

            if (buffer.Length > 12)
            {
                if (buffer.Substring(0, 13) == actSN.SerialNumber)
                {
                    actOrder = "$StepPass#";
                }
            }


            ProductsConfigurationFile.ChildTestInfo actCI = (ProductsConfigurationFile.ChildTestInfo)Instructions.GetValue(actInstruction);
            SimpleMode_Form.StepInfo actSI = new SimpleMode_Form.StepInfo();
            if (actCI.CameraInspection == "1")
            {
                actSI = this.TcpConnect();
                if (actSI.Grade == "")
                {
                    this.ErrorMessageBoxShow(String.Concat("Nemozem nadviazat spojenie s kamerovym systemom. Skontrolujte ci je spusteny program pre obsluhu kamery - Ikona je na ploche PC. Ak sa chyba aj napriek tomu opakuje, zavolajte prosim technika."), true);
                    return;
                }
                if (actSI.Grade == "FAIL")
                {
                    return;
                }
            }

            if (actCI.ScanBarcode != "")
            {
                if (!ProductsConfigurationFile.CheckValueToMask(actOrder, actCI.ScanBarcode))
                {
                    this.lbl_Instruction.Text      = String.Concat("Nespravne zoskenovany udaj\n\n", actCI.Instruction);
                    this.lbl_Instruction.ForeColor = Color.Red;
                    this.tb_Order.Text             = "";
                    this.tb_Order.Focus();
                    return;
                }
                else
                {
                    actSI.Name        = actCI.Name;
                    actSI.Description = actCI.Instruction;
                    actSI.Grade       = "PASS";
                    actSI.ResultValue = actOrder;
                }
            }
            else
            {
                if (actOrder == "$StepFail#")
                {
                    actSI.Name = actCI.Name;
                    if (actCI.CameraInspection != "1")
                    {
                        actSI.Description = actCI.Instruction;
                    }
                    actSI.Grade = "FAIL";
                    this.Close();
                }
                else if (actOrder == "$StepPass#")
                {
                    actSI.Name = actCI.Name;
                    if (actCI.CameraInspection != "1")
                    {
                        actSI.Description = actCI.Instruction;
                    }
                    actSI.Grade = "PASS";
                }
                else
                {
                    this.lbl_Instruction.Text      = String.Concat("Nespravne zoskenovany/zadany udaj\n\n", actCI.Instruction);
                    this.lbl_Instruction.ForeColor = Color.Red;
                    this.tb_Order.Text             = "";
                    this.tb_Order.Focus();
                    return;
                }
            }
            if (actSI.ResultValue.Trim() == "")
            {
                actSI.ResultValue = "Checked";
            }
            Array.Resize(ref actSN.Steps, actSN.Steps.Length + 1);
            actSN.Steps.SetValue(actSI, actSN.Steps.Length - 1);

            this.actInstruction++;
            if (actInstruction == this.Instructions.Length)
            {
                this.Close();
            }
            else
            {
                this.lbl_InsCounter.Text = String.Format("Instruction   {0}/{1}", actInstruction + 1, this.Instructions.Length);
                actCI                          = (ProductsConfigurationFile.ChildTestInfo)Instructions.GetValue(actInstruction);
                this.actTimeout                = Convert.ToInt32(actCI.Timeout);
                this.lbl_Instruction.Text      = actCI.Instruction;
                this.lbl_Instruction.ForeColor = Color.Black;
                if (actCI.CameraInspection == "1")
                {
                    this.btn_Pass.Text = "START";
                }
                else
                {
                    this.btn_Pass.Text = "PASS";
                }
                if (actCI.PicturePath != "")
                {
                    String str_actPicturesPath = String.Concat(str_PicturesPath, actCI.PicturePath);
                    if (actCI.CameraInspection == "1")
                    {
                        Int32  foldIndex   = actCI.PicturePath.IndexOf('\\');
                        String instrfolder = actCI.PicturePath.Substring(0, foldIndex + 1);
                        str_actPicturesPath = String.Concat(str_PicturesPath, instrfolder, this.Item, "_CAM.jpg");
                        if (!File.Exists(str_actPicturesPath))
                        {
                            str_actPicturesPath = String.Concat(str_PicturesPath, instrfolder, "Default_CAM.jpg");
                        }
                    }
                    if (Directory.Exists(Path.GetDirectoryName(str_actPicturesPath)))
                    {
                        if (!File.Exists(str_actPicturesPath))
                        {
                            this.Cursor = Cursors.Default;
                            if (Path.GetFileName(str_actPicturesPath) == "")
                            {
                                return;
                            }
                            else
                            {
                                this.ErrorMessageBoxShow(String.Concat("Neexistuje subor \"", str_actPicturesPath, "\". Zavolajte prosim testovacieho technika."), true);
                            }
                            return;
                        }
                        Image img_PictureToShow = Image.FromFile(str_actPicturesPath);
                        this.pictureBox1.Visible  = true;
                        this.pictureBox1.Image    = img_PictureToShow;
                        this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
                    }
                }
                else
                {
                    this.pictureBox1.Visible = false;
                }
                this.btn_Pass.BackColor = this.BackColor;
                this.btn_Pass.Enabled   = false;
                this.btn_Fail.BackColor = this.BackColor;
                this.btn_Fail.Enabled   = false;
                this.tb_Order.Text      = "";
                this.timeoutStart       = DateTime.Now;
                this.t_Main.Start();
            }
        }