Exemplo n.º 1
0
        /// <summary>
        /// 4 MINUTE BUTTON
        /// WILL RUN 8 TURNS
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmd4Min_Click(object sender, System.EventArgs e)
        {
            try
            {
                Object objData = new Object();
                for (int i = 1; i <= 35; i++)
                {
                    objData = "RECD";
                    if (i % 4 == 0)
                    {
                        ParsedData dataOutParse = new ParsedData(dataOut);
                        objData = algorithm(dataOutParse.getDemand(), dataOutParse);
                        if (output || i >= 33)
                        {
                            txtDataRx.Text += Environment.NewLine;
                        }
                    }
                    byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());
                    m_socWorker.Send(byData);
                    byte[] buffer = new byte[1024];
                    int iRx = m_socWorker.Receive(buffer);
                    char[] chars = new char[iRx];
                    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                    int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
                    System.String szData = new System.String(chars);
                    if (output || i >= 33)
                        {
                            txtDataRx.Text += Environment.NewLine + szData;
                            txtDataRx.SelectionStart = txtDataRx.Text.Length;
                            txtDataRx.ScrollToCaret();
                        }

                    if (i % 4 != 0 & szData != "END")
                    {
                        dataOut[dataCount] = szData;
                        dataCount++;

                        if (dataCount == 3)
                        {
                            ParsedData dataOutParse = new ParsedData(dataOut);
                            frm2.chartUpdate(dataOutParse.getDemand());
                            frm2.profitUpdate(dataOutParse.getProfit());
                            frm2.profitChartUpdate(dataOutParse.getDemand(), dataOutParse.getProfit());
                            dataCount = 0;
                        }
                    }
                    cmd30Seconds.Enabled = false;
                    cmd4Min.Enabled = false;
                    cmd30Min.Enabled = false;
                    cmdRead.Enabled = false;

                        if (szData == "END")
                        {
                            cmdClose_Click(sender, e);
                        }

                }
            }
            catch (System.Net.Sockets.SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 30 SECOND BUTTON
        /// SENDS ONE TURN TO THE SERVER
        /// REQUIRES A MANUAL CONTROL
        /// IF LOOP IS ENABLED, THIS BUTTON WILL RUN UNTIL SERVER THROWS END AT IT
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void cmd30Seconds_Click_1(object sender, System.EventArgs e)
        {
            try
            {
                Object objData = new Object();
                for (int i = 1; i <= 3 ; i++)
                {
                    objData = "RECD";
                    byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());
                    m_socWorker.Send(byData);
                    byte[] buffer = new byte[1024];
                    int iRx = m_socWorker.Receive(buffer);
                    char[] chars = new char[iRx];

                    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                    int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
                    System.String szData = new System.String(chars);
                    if (output || szData == "END")
                    {
                        txtDataRx.Text += Environment.NewLine + szData;
                        txtDataRx.SelectionStart = txtDataRx.Text.Length;
                        txtDataRx.ScrollToCaret();
                    }

                    if (szData != "END")
                    {
                        dataOut[dataCount] = szData;
                        dataCount++;

                        if (dataCount == 3)
                        {
                            ParsedData dataOutParse = new ParsedData(dataOut);
                            frm2.chartUpdate(dataOutParse.getDemand());
                            frm2.profitUpdate(dataOutParse.getProfit());
                            frm2.profitChartUpdate(dataOutParse.getDemand(), dataOutParse.getProfit());
                            dataCount = 0;
                        }
                    }

                    if (!loop)
                    {
                        cmd30Seconds.Enabled = false;
                        cmd4Min.Enabled = false;
                        cmd30Min.Enabled = false;
                        cmdRead.Enabled = false;
                    }

                    //IF THE SERVER ENDS, THROW STOP
                    if (szData == "END")
                    {
                        cmdClose_Click(sender, e);
                    }

                    if (loop == true && i == 3)
                    {
                        cmdSendData_Click(sender, e);
                        i = 0;
                        /*count++;
                        if (count > 50)
                        {
                            txtDataRx.Text = "";
                            count = 0;
                        }*/
                    }
                }
            }
            catch (System.Net.Sockets.SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }