Beispiel #1
0
 private void button_pauseResume_Click(object sender, EventArgs e)
 {
     // Pause the print. Can only pause print once all drawing bytes have been sent to the Arduino.
     if (currentPrinterState == printerState.printInProgress)
     {
         currentPrinterState     = printerState.printPaused;
         textBox_Status.Text     = "Print Paused";
         button_pauseResume.Text = "Resume Print";
         // Send start print command to Arduino
         if (serialPort1.IsOpen)
         {
             dataByte = 0;
             serialPort1.Write(new byte[2] {
                 startByte, pausePrintCommand
             }, 0, 2);
         }
     }
     // Resume the print
     else if (currentPrinterState == printerState.printPaused)
     {
         textBox_Status.Text     = "Printing";
         currentPrinterState     = printerState.printInProgress;
         button_pauseResume.Text = "Pause Print";
         // Send stop print command to Arduino
         if (serialPort1.IsOpen)
         {
             dataByte = 0;
             serialPort1.Write(new byte[2] {
                 startByte, resumePrintCommand
             }, 0, 2);
         }
     }
 }
Beispiel #2
0
        private void button_startStop_Click(object sender, EventArgs e)
        {
            // Start print
            if (currentPrinterState == printerState.idle && !drawQueue.IsEmpty)
            {
                currentPrinterState   = printerState.printInProgress;
                button_startStop.Text = "Stop Print";
                richTextBox_debug.Clear();
                textBox_Status.Text = "Printing";

                // Send start print command to Arduino
                if (serialPort1.IsOpen)
                {
                    // Determine resolution of print
                    if (comboBox_Resolution.Text == "Low")
                    {
                        dataByte = 0;
                    }
                    else if (comboBox_Resolution.Text == "Medium")
                    {
                        dataByte = 1;
                    }
                    else if (comboBox_Resolution.Text == "High")
                    {
                        dataByte = 2;
                    }
                    serialPort1.Write(new byte[] { startByte, startPrintCommand, dataByte }, 0, 3);
                }
            }
            // Stop print.
            else if (currentPrinterState == printerState.printInProgress || currentPrinterState == printerState.printPaused)
            {
                currentPrinterState     = printerState.idle;
                button_startStop.Text   = "Start Print";
                button_pauseResume.Text = "Pause Print";
                textBox_Status.Text     = "Print Stopped";
                // Send stop print command to Arduino
                if (serialPort1.IsOpen)
                {
                    dataByte = 0;
                    serialPort1.Write(new byte[2] {
                        startByte, stopPrintCommand
                    }, 0, 2);
                }
            }

            // Error : user has not uploaded their image
            else if (currentPrinterState == printerState.idle && drawQueue.IsEmpty)
            {
                textBox_Status.Text = "Please upload your image";
            }
        }
Beispiel #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Dequeue and print incoming messages from Arduino
            byte queueData = 0;

            while (cqueue.Count > 0)
            {
                cqueue.TryDequeue(out queueData);
                richTextBox_debug.AppendText(queueData + " ");

                // Incoming command from Arduino
                if (queueData == 255)
                {
                    cqueue.TryDequeue(out queueData);

                    // Arduino is ready for the next byte
                    if (queueData == 6 && currentPrinterState == printerState.printInProgress)
                    {
                        currentPrinterState = printerState.sendDrawingBytes;
                    }
                }
            }
        }
Beispiel #4
0
        private void timerDraw_Tick(object sender, EventArgs e)
        {
            // Send tile bytes to the Arduino
            if (currentPrinterState == printerState.sendDrawingBytes)
            {
                drawQueue.TryDequeue(out dataByte);
                if (serialPort1.IsOpen)
                {
                    serialPort1.Write(new byte[] { startByte, drawCommand, dataByte }, 0, 3);
                }

                // Wait until Arduino is ready for the next byte
                currentPrinterState = printerState.printInProgress;

                // Print is complete
                if (drawQueue.IsEmpty)
                {
                    // Send print complete command
                    serialPort1.Write(new byte[] { startByte, stopPrintCommand }, 0, 2);
                    currentPrinterState = printerState.idle;
                    textBox_Status.Text = "Print complete!";
                }
            }
        }