public ThorStage(ThorStageModel model) { stageModel = model; factorsTable = new ThorStageFactors[(int)ThorStageModel.TOTAL_AVAILABLE]; modelIndex = (int)model; /* Setup model factors here */ factorsTable[(int)ThorStageModel.MTS25_Z8] = new ThorStageFactors(34304, 34304, 767367.49, 261.93); /* End model factors */ ScaleFactors = factorsTable[modelIndex]; }
public ThorController(ThorStageModel stageModel, string serialNumber) { stage = new ThorStage(stageModel); UInt32 deviceCount = 0; uint numBytesWritten = 0; this.serialNumber = serialNumber; deviceHandle = new FTDI(); // Determine the number of FTDI devices connected to the machine ftStatus = deviceHandle.GetNumberOfDevices(ref deviceCount); // Populate device list FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[deviceCount]; ftStatus = deviceHandle.GetDeviceList(ftdiDeviceList); ftStatus = deviceHandle.OpenBySerialNumber(serialNumber); if (ftStatus != FTDI.FT_STATUS.FT_OK) { // Wait for a key press throw new Exception("Failed to open FTDI device " + ftStatus.ToString()); } // Set baud rate to 115200. ftStatus = deviceHandle.SetBaudRate(115200); // 8 data bits, 1 stop bit, no parity ftStatus = deviceHandle.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_1, FTDI.FT_PARITY.FT_PARITY_NONE); // Pre purge dwell 50ms. Thread.Sleep(50); // Purge the device. ftStatus = deviceHandle.Purge(FTDI.FT_PURGE.FT_PURGE_RX | FTDI.FT_PURGE.FT_PURGE_TX); // Post purge dwell 50ms. Thread.Sleep(50); // Reset device. ftStatus = deviceHandle.ResetDevice(); // Set flow control to RTS/CTS. ftStatus = deviceHandle.SetFlowControl(FTDI.FT_FLOW_CONTROL.FT_FLOW_RTS_CTS, 0, 0); // Set RTS. ftStatus = deviceHandle.SetRTS(true); // Disable then enable channel byte[] change_enstate = { 0x10, 0x02, 0x01, 0x02, 0x50, 0x1 }; ftStatus = deviceHandle.Write(change_enstate, 6, ref numBytesWritten); change_enstate[3] = 0x01; ftStatus = deviceHandle.Write(change_enstate, 6, ref numBytesWritten); // Move home byte[] movehome = { 0x43, 0x04, 0x01, 0x00, 0x50, 0x01 }; /*ftStatus = deviceHandle.Write(movehome, 6, ref numBytesWritten); * Thread.Sleep(3000); * do * { * statusBits = GetStatus(); * //Console.WriteLine("{0:X}", statusbits); * } while ((statusBits & 0x400) != 0x400 || statusBits == 0);*/ }