public void Start() { fInitialized = true; printer.ResetStepper(); z_rail_init(); Process(); // this is a blocking call }
//set height after z is sent from firmware //states for each 3 states //calls step stepper afer the calucaltion of steps //public static bool initialized = false; //states...unknown- known //private current hieght postion variable //initialize method //checks state and initializes...then sets height public void InitializeState() { printer.ResetStepper(); if (initialized == false) { GoToLimitSwitch(); GoToBuildSurface(); } initialized = true; currentheightposition = 0; }
void ProcessCommand(byte[] packet, PrinterControl printer) { // Process // TYLER's Section, Recieves byte array . /* Byte 0: Command byte * Byte 1: Length of parameter data (# of bytes) * Byte 2: Low-byte of 16-bit checksum * Byte 3: High-byte of 16-bit checksum * Byte 4-n: Parameter data wait ms, stepper, move galvos, remove model, set laser * * Note: what we need to know is which bytes corespond to controling which of the below commands. */ if (firstCommand) { printer.ResetStepper(); moveTop(printer); firstCommand = false; } printByteArray(packet, "Firmware received successfully. Now in process command."); byte command = packet[0]; byte MoveGalvos_command = 0x00; byte MoveZ_command = 0x01; byte SetLaser_command = 0x02; byte PrintDone_command = 0x03; //byte WaitMicroseconds_command = 0x00; //byte ResetStepper_command = 0x00; //byte RemoveModelFromPrinter_command = 0x00; //if (command == WaitMicroseconds_command) //WaitMicroseconds //{ // // convert from byte to long // long microsec = 0; // printer.WaitMicroseconds(microsec); //} //if (command == ResetStepper_command) //ResetStepper //{ // // void function // printer.ResetStepper(); //} if (command == MoveGalvos_command) //MoveGalvos { // convert from byte to float x and float y byte[] x_substring = new byte[4]; // should I make this 4? Array.Copy(packet, 4, x_substring, 0, 4); byte[] y_substring = new byte[4]; // should I make this 4? Array.Copy(packet, 8, y_substring, 0, 4); float x = BitConverter.ToSingle(x_substring, 0); float y = BitConverter.ToSingle(y_substring, 0); float x_voltage = (float)(x * (2.5 / 100)); // find a better way to do these magic numbers float y_voltage = (float)(y * (2.5 / 100)); printer.MoveGalvos(x_voltage, y_voltage); // sends voltages to MoveGalvos(); } //else if (command == RemoveModelFromPrinter_command) //RemoveModelFromPrinter //{ // // void function // printer.RemoveModelFromPrinter(); //} else if (command == SetLaser_command) //SetLaser { // convert from byte to bool bool set = BitConverter.ToBoolean(packet, 4); printer.SetLaser(set); } else if (command == MoveZ_command) { // convert from byte to float float z_frombottom = BitConverter.ToSingle(packet, 4); // converting from byte[] starting at 4 to float movementWithSpeed(printer, calculateDirection(printer, z_frombottom), CalculateDistance(printer, z_frombottom)); // zrailcontroller } else if (command == PrintDone_command) { fDone = true; moveTop(printer); } }
public void executeCommand(byte command, byte[] param) { try { switch (command) { case 0x00: return; case 0x01: commandsExecuted["ResetStepper"] += 1; printer.ResetStepper(); moveStepperToTop(); moveStepperFromTopToBuildPlate(); break; case 0x02: float direction = BitConverter.ToSingle(param, 0); if (direction == 1) { Console.WriteLine("Step up"); commandsExecuted["StepStepperUp"] += 1; bool result = printer.StepStepper(PrinterControl.StepperDir.STEP_UP); } else if (direction == 0) { Console.WriteLine("Step down"); commandsExecuted["StepStepperDown"] += 1; bool result = printer.StepStepper(PrinterControl.StepperDir.STEP_DOWN); } break; case 0x03: float value = BitConverter.ToSingle(param, 0); if (value == 1) { printer.SetLaser(true); Console.WriteLine("Turned on laser"); } else if (value == 0) { printer.SetLaser(false); Console.WriteLine("Turned laser off"); } else { Console.WriteLine("Invalid laser value for on/off"); } break; case 0x04: commandsExecuted["MoveGalvonometer"] += 1; float x = BitConverter.ToSingle(param, 0); float y = BitConverter.ToSingle(param, 4); printer.MoveGalvos(x, y); Console.WriteLine("Moved galvo"); break; default: Console.WriteLine("Bad command"); break; } } catch (Exception e) { System.Console.WriteLine(e.StackTrace); } }