Ejemplo n.º 1
0
        private void PrinterThreadCom(object obj)
        {
            TCPCom ThreadCom = (TCPCom)obj;
            string ReceivedData;


            if (!ThreadCom.SetupCom())
            {
                //DebugWrite("Error setting up communication with printer.");
            }
            else
            {
                while (ProgramActive)
                {
                    if (tick)
                    {
                        tick         = false;
                        ReceivedData = ThreadCom.GetACC();
                        if (ReceivedData != "" && ReceivedData != null && ReceivedData.Length > 0)
                        {
                            //StatusBar.Dispatcher.Invoke(() =>
                            //{
                            //    StatusBar.Content = ReceivedData;
                            //});
                        }
                        if (ReceivedData.Contains("0A44") && ReceivedData.Length > 15)
                        {
                            if (ReceivedData[14].ToString() == "1")
                            {
                                palletInPosition = true;
                                PalletStatus.Dispatcher.Invoke(() =>
                                {
                                    PalletStatus.Icon       = FontAwesome.WPF.FontAwesomeIcon.CheckCircle;
                                    PalletStatus.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009d58"));
                                });
                            }
                            else if (ReceivedData[14].ToString() == "0")
                            {
                                palletInPosition = false;
                                printSent        = false;
                                PalletStatus.Dispatcher.Invoke(() =>
                                {
                                    PalletStatus.Icon       = FontAwesome.WPF.FontAwesomeIcon.TimesCircle;
                                    PalletStatus.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ca0b00"));
                                });
                            }
                        }
                        if (palletInPosition && !printSent)
                        {
                            SendPrint();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void AskHeat_Click(object sender, EventArgs e)
        {
            SerialPort serialPort = null;

            // Create a new SerialPort object with default settings.
            serialPort = new SerialPort();

            // Allow the user to set the appropriate properties.
            serialPort.PortName = COM.Text;
            serialPort.DataBits = 8;
            serialPort.Parity   = Parity.None;
            serialPort.StopBits = StopBits.One;
            serialPort.BaudRate = 9600;

            // Set the read/write timeouts
            serialPort.ReadTimeout  = 500;
            serialPort.WriteTimeout = 500;

            try
            {
                serialPort.Open();
                serialPort.DiscardOutBuffer();
                serialPort.DiscardInBuffer();

                String ReceivedData;
                //RecievedData = serialPort.ReadLine();
                //serialPort.DataReceived += new SerialDataReceivedEventHandler(responseHandler);
                serialPort.Write("i" + "\r\n");

                Boolean conti = true;
                do
                {
                    ReceivedData = serialPort.ReadLine();
                    if (ReceivedData.Contains('$'))
                    {
                        conti = false;
                    }
                } while (conti);


                ReceivedData = ReceivedData.Replace("$", "");
                ReceivedData = ReceivedData.Replace("\r", "");
                ReceivedData = ReceivedData.Replace("\n", "");

                AppendHeatLabel("Temperature U:" + ReceivedData.Split(',')[4] + "," + "Temperature M:" + ReceivedData.Split(',')[5]);

                serialPort.Close();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Serial could not be opened, please check that the device is correct one");
                serialPort.Close();
            }
        }
Ejemplo n.º 3
0
        void OnProcessExit(object sender, EventArgs e)
        {
            // Cancel the heat
            SerialPort serialPortCancel = null;

            try
            {
                // Create a new SerialPort object with default settings.
                serialPortCancel = new SerialPort();

                // Allow the user to set the appropriate properties.
                serialPortCancel.PortName = COM.SelectedItem.ToString();
                serialPortCancel.DataBits = 8;
                serialPortCancel.Parity   = Parity.None;
                serialPortCancel.StopBits = StopBits.One;
                serialPortCancel.BaudRate = 9600;

                // Set the read/write timeouts
                serialPortCancel.ReadTimeout  = 500;
                serialPortCancel.WriteTimeout = 500;

                serialPortCancel.Open();
                serialPortCancel.DiscardOutBuffer();
                serialPortCancel.DiscardInBuffer();

                String ReceivedData;
                //RecievedData = serialPort.ReadLine();
                //serialPort.DataReceived += new SerialDataReceivedEventHandler(responseHandler);
                serialPortCancel.Write("C" + "\r\n");

                Boolean conti = true;
                do
                {
                    ReceivedData = serialPortCancel.ReadLine();
                    if (ReceivedData.Contains('$'))
                    {
                        conti = false;
                    }
                } while (conti);


                ReceivedData = ReceivedData.Replace("$", "");
                ReceivedData = ReceivedData.Replace("\r", "");
                ReceivedData = ReceivedData.Replace("\n", "");

                serialPortCancel.Close();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Serial could not be opened, please check that the device is correct one. The heat could not be turned off.");
                serialPortCancel.Close();
            }
        }
Ejemplo n.º 4
0
        private void connect()
        {
            string[] ArrayComPortsNames = null;
            //int index = -1;
            //string ComPortName = null;

            ArrayComPortsNames = SerialPort.GetPortNames();

            SerialPort serialPort = null;

            // Create a new SerialPort object with default settings.
            serialPort = new SerialPort();

            // Allow the user to set the appropriate properties.
            serialPort.PortName = selectedCom;
            serialPort.DataBits = 8;
            serialPort.Parity   = Parity.None;
            serialPort.StopBits = StopBits.One;
            serialPort.BaudRate = 9600;

            // Set the read/write timeouts
            serialPort.ReadTimeout  = 10000;
            serialPort.WriteTimeout = 500;

            try
            {
                serialPort.Open();
                serialPort.DiscardOutBuffer();
                serialPort.DiscardInBuffer();

                String ReceivedData;
                //RecievedData = serialPort.ReadLine();
                //serialPort.DataReceived += new SerialDataReceivedEventHandler(responseHandler);
                serialPort.Write("AT+CWQAP" + "\r\n");

                Boolean cont = true;
                do
                {
                    ReceivedData = serialPort.ReadLine();
                    writeConnect(ReceivedData);
                    if (ReceivedData.Contains('$'))
                    {
                        cont = false;
                    }
                } while (cont);

                serialPort.Write("AT+CWJAP=" + "\"" + "QB3@953" + "\"" + "," + "\"" + "QB34innovation!" + "\"" + "\r\n");

                cont = true;
                do
                {
                    ReceivedData = serialPort.ReadLine();
                    writeConnect(ReceivedData);
                    if (ReceivedData.Contains('$'))
                    {
                        cont = false;
                    }
                } while (cont);
                cont = true;

                serialPort.Write("AT+CIFSR" + "\r\n");

                cont = true;
                do
                {
                    ReceivedData = serialPort.ReadLine();
                    writeConnect(ReceivedData);
                    Console.WriteLine(ReceivedData);
                    if (ReceivedData.Contains('$'))
                    {
                        cont = false;
                        Console.WriteLine(ReceivedData.Split('\"')[5]);
                        TCPIP.ip = ReceivedData.Split('\"')[5];
                    }
                } while (cont);
                cont = true;


                serialPort.Close();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Serial could not be opened, please check that the device is correct one");
                serialPort.Close();
            }
        }
Ejemplo n.º 5
0
        private void doAssay()
        {
            Boolean cont = true;

            int loop = 0;

            do
            {
                DateTime current  = DateTime.Now;
                int      endCycle = current.Hour * 60 * 60 + current.Minute * 60 + current.Second;

                if (duration < endCycle)
                {
                    cont = false;
                }


                SerialPort serialPort = null;

                // Create a new SerialPort object with default settings.
                serialPort = new SerialPort();

                // Allow the user to set the appropriate properties.
                serialPort.PortName = port;
                serialPort.DataBits = 8;
                serialPort.Parity   = Parity.None;
                serialPort.StopBits = StopBits.One;
                serialPort.BaudRate = 9600;

                // Set the read/write timeouts
                serialPort.ReadTimeout  = 10000;
                serialPort.WriteTimeout = 500;

                try
                {
                    serialPort.Open();
                    serialPort.DiscardOutBuffer();
                    serialPort.DiscardInBuffer();

                    String ReceivedData;
                    //RecievedData = serialPort.ReadLine();
                    //serialPort.DataReceived += new SerialDataReceivedEventHandler(responseHandler);
                    serialPort.Write("R" + "\r\n");

                    Boolean conti = true;
                    do
                    {
                        ReceivedData = serialPort.ReadLine();
                        if (ReceivedData.Contains('$'))
                        {
                            conti = false;
                        }
                    } while (conti);


                    conti = true;

                    serialPort.Write("i" + "\r\n");
                    String ReceivedData1;
                    do
                    {
                        ReceivedData1 = serialPort.ReadLine();
                        if (ReceivedData1.Contains('$'))
                        {
                            conti = false;
                        }
                    } while (conti);


                    conti = true;


                    Thread.Sleep(2000);

                    ReceivedData  = ReceivedData.Replace("$", "");
                    ReceivedData1 = ReceivedData1.Replace("$", "");
                    ReceivedData  = ReceivedData.Replace("\r", "");
                    ReceivedData1 = ReceivedData1.Replace("\r", "");
                    ReceivedData  = ReceivedData.Replace("\n", "");
                    ReceivedData1 = ReceivedData1.Replace("\n", "");

                    AppendHeatLabel("Temperature U:" + ReceivedData1.Split(',')[4] + "," + "Temperature M:" + ReceivedData1.Split(',')[5]);



                    AppendData(loop.ToString() + "," + ReceivedData1.Split(',')[4] + "," +
                               ReceivedData1.Split(',')[5] + "," + ReceivedData);

                    string resToAppend = loop.ToString() + ",U,M,";

                    AppendResult(loop.ToString() + "," + ReceivedData1.Split(',')[4] + "," +
                                 ReceivedData1.Split(',')[5] + "," + ReceivedData);

                    Thread.Sleep(2000);

                    serialPort.Close();
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Serial could not be opened, please check that the device is correct one");
                    serialPort.Close();
                }


                Boolean timeRunning = true;



                do
                {
                    DateTime wait = DateTime.Now;
                    if (endCycle + 120 < wait.Hour * 60 * 60 + wait.Minute * 60 + wait.Second)
                    {
                        timeRunning = false;
                    }
                    Thread.Sleep(100);
                } while (timeRunning);
                loop += 1;
            } while (cont);

            // Cancel the heat
            SerialPort serialPortCancel = null;

            try
            {
                // Create a new SerialPort object with default settings.
                serialPortCancel = new SerialPort();

                // Allow the user to set the appropriate properties.
                serialPortCancel.PortName = port;
                serialPortCancel.DataBits = 8;
                serialPortCancel.Parity   = Parity.None;
                serialPortCancel.StopBits = StopBits.One;
                serialPortCancel.BaudRate = 9600;

                // Set the read/write timeouts
                serialPortCancel.ReadTimeout  = 500;
                serialPortCancel.WriteTimeout = 500;

                serialPortCancel.Open();
                serialPortCancel.DiscardOutBuffer();
                serialPortCancel.DiscardInBuffer();

                String ReceivedData;
                //RecievedData = serialPort.ReadLine();
                //serialPort.DataReceived += new SerialDataReceivedEventHandler(responseHandler);
                serialPortCancel.Write("C" + "\r\n");

                Boolean conti = true;
                do
                {
                    ReceivedData = serialPortCancel.ReadLine();
                    if (ReceivedData.Contains('$'))
                    {
                        conti = false;
                    }
                } while (conti);


                ReceivedData = ReceivedData.Replace("$", "");
                ReceivedData = ReceivedData.Replace("\r", "");
                ReceivedData = ReceivedData.Replace("\n", "");

                serialPortCancel.Close();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Serial could not be opened, please check that the device is correct one");
                serialPortCancel.Close();
            }
            MessageBox.Show("Assay ready");
        }