private void StartButton_Click(object sender, EventArgs e) { OutputSteps.Text = RubikSolve.GetResult(InputStatus.Text); }
//refresh picture every 500ms private void timer1_Tick(object sender, EventArgs e) { //temp_status Graphics g = Graphics.FromHwnd(this.pictureBox1.Handle); //背景色 //g.FillRectangle(getColorformStatus(1), 0, 0, 240, 180); g.FillRectangle(new SolidBrush(Color.Gray), 0, 0, 240, 180); //中心块颜色 g.FillRectangle(new SolidBrush(Color.Yellow), 80, 20, 20, 20); g.FillRectangle(new SolidBrush(Color.Blue), 80, 80, 20, 20); g.FillRectangle(new SolidBrush(Color.White), 80, 140, 20, 20); g.FillRectangle(new SolidBrush(Color.Orange), 20, 80, 20, 20); g.FillRectangle(new SolidBrush(Color.Maroon), 140, 80, 20, 20); g.FillRectangle(new SolidBrush(Color.MediumSeaGreen), 200, 80, 20, 20); //黄色面 g.FillRectangle(getColorformStatus(cube_status[30]), 60, 0, 20, 20); g.FillRectangle(getColorformStatus(cube_status[4]), 80, 0, 20, 20); g.FillRectangle(getColorformStatus(cube_status[27]), 100, 0, 20, 20); g.FillRectangle(getColorformStatus(cube_status[6]), 60, 20, 20, 20); g.FillRectangle(getColorformStatus(cube_status[2]), 100, 20, 20, 20); g.FillRectangle(getColorformStatus(cube_status[33]), 60, 40, 20, 20); g.FillRectangle(getColorformStatus(cube_status[0]), 80, 40, 20, 20); g.FillRectangle(getColorformStatus(cube_status[24]), 100, 40, 20, 20); //橙色面 g.FillRectangle(getColorformStatus(cube_status[32]), 0, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[7]), 20, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[34]), 40, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[23]), 0, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[19]), 40, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[43]), 0, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[15]), 20, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[41]), 40, 100, 20, 20); //白色面 g.FillRectangle(getColorformStatus(cube_status[39]), 60, 120, 20, 20); g.FillRectangle(getColorformStatus(cube_status[8]), 80, 120, 20, 20); g.FillRectangle(getColorformStatus(cube_status[36]), 100, 120, 20, 20); g.FillRectangle(getColorformStatus(cube_status[14]), 60, 140, 20, 20); g.FillRectangle(getColorformStatus(cube_status[10]), 100, 140, 20, 20); g.FillRectangle(getColorformStatus(cube_status[42]), 60, 160, 20, 20); g.FillRectangle(getColorformStatus(cube_status[12]), 80, 160, 20, 20); g.FillRectangle(getColorformStatus(cube_status[45]), 100, 160, 20, 20); //红色面 g.FillRectangle(getColorformStatus(cube_status[26]), 120, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[3]), 140, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[28]), 160, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[17]), 120, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[21]), 160, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[37]), 120, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[11]), 140, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[47]), 160, 100, 20, 20); //绿色面 g.FillRectangle(getColorformStatus(cube_status[29]), 180, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[5]), 200, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[31]), 220, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[20]), 180, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[22]), 220, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[46]), 180, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[13]), 200, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[44]), 220, 100, 20, 20); //蓝色面 g.FillRectangle(getColorformStatus(cube_status[35]), 60, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[1]), 80, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[25]), 100, 60, 20, 20); g.FillRectangle(getColorformStatus(cube_status[18]), 60, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[16]), 100, 80, 20, 20); g.FillRectangle(getColorformStatus(cube_status[40]), 60, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[9]), 80, 100, 20, 20); g.FillRectangle(getColorformStatus(cube_status[38]), 100, 100, 20, 20); //各种线 g.DrawLine(new Pen(Color.Teal, 1), 60, 20, 120, 20); g.DrawLine(new Pen(Color.Teal, 1), 60, 40, 120, 40); g.DrawLine(new Pen(Color.Teal, 1), 60, 140, 120, 140); g.DrawLine(new Pen(Color.Teal, 1), 60, 160, 120, 160); g.DrawLine(new Pen(Color.Teal, 1), 20, 60, 20, 120); g.DrawLine(new Pen(Color.Teal, 1), 40, 60, 40, 120); g.DrawLine(new Pen(Color.Teal, 1), 140, 60, 140, 120); g.DrawLine(new Pen(Color.Teal, 1), 160, 60, 160, 120); g.DrawLine(new Pen(Color.Black, 1), 180, 60, 180, 120); g.DrawLine(new Pen(Color.Teal, 1), 220, 60, 220, 120); g.DrawLine(new Pen(Color.Teal, 1), 200, 60, 200, 120); g.DrawLine(new Pen(Color.Black, 1), 60, 0, 60, 180); g.DrawLine(new Pen(Color.Teal, 1), 80, 0, 80, 180); g.DrawLine(new Pen(Color.Teal, 1), 100, 0, 100, 180); g.DrawLine(new Pen(Color.Black, 1), 120, 0, 120, 180); g.DrawLine(new Pen(Color.Black, 1), 0, 60, 240, 60); g.DrawLine(new Pen(Color.Teal, 1), 0, 80, 240, 80); g.DrawLine(new Pen(Color.Teal, 1), 0, 100, 240, 100); g.DrawLine(new Pen(Color.Black, 1), 0, 120, 240, 120); if (All_Scan_OK && (currentStatus == 0)) { System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding(); string Scan_Result = ASCII.GetString(cube_status); for (int x = 1; x < 20; x++) { int temp = (x < 13 ? 3 * x - 1 : 4 * x - 13); Scan_Result = Scan_Result.Insert(temp, " "); } All_Scan_OK = false; String Calc_Result = RubikSolve.GetResult(Scan_Result); textBox1.Text += DateTime.Now.ToString("hh:mm:ss") + " 步骤计算结果:" + Calc_Result + "\r\n"; //results textBox1.SelectionStart = textBox1.Text.Length; textBox1.ScrollToCaret(); byte[] frameHead = { 0xfe, 0xAA }; byte[] Buffer = System.Text.Encoding.Default.GetBytes(Calc_Result); byte[] frameend = { 0x8A }; if (serialPort1.IsOpen) { try { serialPort1.Write(frameHead, 0, 2); Thread.Sleep(10); serialPort1.Write(Buffer, 0, Buffer.Length); //写数据 Thread.Sleep(10); serialPort1.Write(frameend, 0, 1); Thread.Sleep(10); //sw.Stop(); //timer2.Stop(); } catch { MessageBox.Show("串口数据发送出错,请检查.", "错误");//错误处理 } } } }