static void Main(string[] args) { const int SOURCE_URL = 0, TARGET_PATH = 1; AutoMapperConfig.RegisterMapping(); MinhaCDNBusiness minhaCDNBusiness; string path = ConfigurationManager.AppSettings["outputPath"]; List <string> sourceURLtargetPath = null; Console.Write("\nconvert "); var stringCall = Console.ReadLine(); try { ValidationStringCall(ref sourceURLtargetPath, ref stringCall); minhaCDNBusiness = new MinhaCDNBusiness(sourceURLtargetPath.ElementAt(SOURCE_URL).Trim()); string outputFileName = path + sourceURLtargetPath.ElementAt(TARGET_PATH).Trim(); if (File.Exists(outputFileName)) { Console.Write("\nThere is a file with the same name in this location." + "\nDo you want to replace it? y(yes)/n(no)/c(cancel): "); EnumProcess processeDeleteFile = GetResponse(); if (processeDeleteFile == EnumProcess.cancel) { return; } else if (processeDeleteFile == EnumProcess.yes) { File.Delete(outputFileName); } else if (processeDeleteFile == EnumProcess.no) { outputFileName = NewFileName(path, sourceURLtargetPath.ElementAt(1)); } } minhaCDNBusiness.CreateFileFormatAgora(outputFileName); Console.WriteLine("Successfully converted file!\nPress enter..."); Console.ReadLine(); } catch (Exception e) { Console.Write(e.Message); Console.Write("\nPress enter..."); Console.Read(); } }
/// <summary> /// Click the Start button. /// </summary> /// <param name="sender">The evented object</param> /// <param name="e">Additional event information</param> /// <remarks> /// Start scenario. /// </remarks> private void btnStart_Click(object sender, EventArgs e) { // Start scenario this._enumProcess = EnumProcess.Running; // Button control this.btnDisconnect.Enabled = false; this.btnStart.Enabled = false; this.btnStop.Enabled = true; // Scenario creation this.SetScenario(); // Send command this._indexSendCommandID = EnumSenario.StartMeasurement; TOFCommand command = this._listCommand[(int)this._indexSendCommandID]; this.AsyncSerialPort(command); }
public static void ExecuteWaitCommand(string command, string workingFolder, EnumProcess proc, bool IsCreateNoWindow = false) { int ExitCode; ProcessStartInfo ProcessInfo; Process process; ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command); ProcessInfo.CreateNoWindow = IsCreateNoWindow; ProcessInfo.UseShellExecute = false; ProcessInfo.WorkingDirectory = workingFolder; // *** Redirect the output *** // ProcessInfo.RedirectStandardError = true; // ProcessInfo.RedirectStandardOutput = true; ProcessInfo.RedirectStandardError = false; ProcessInfo.RedirectStandardOutput = false; process = Process.Start(ProcessInfo); switch (proc) { case EnumProcess.NonGlobal: break; case EnumProcess.Designer: GlobalDef.CurrentDesigner.Process = process; break; case EnumProcess.Player: GlobalDef.ProcessPlayer = process; break; case EnumProcess.Receiver: GlobalDef.ProcessReceiver = process; break; case EnumProcess.Sender: GlobalDef.ProcessSender = process; break; default: break; } process.WaitForExit(); // *** Read the streams *** // string output = process.StandardOutput.ReadToEnd(); // string error = process.StandardError.ReadToEnd(); ExitCode = process.ExitCode; if (ExitCode > 0) { BotHttpClient.Log("ERROR on " + proc.ToString(), true); } // MessageBox.Show("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output)); // MessageBox.Show("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error)); // MessageBox.Show("ExitCode: " + ExitCode.ToString(), "ExecuteCommand"); process.Close(); process = null; switch (proc) { case EnumProcess.NonGlobal: break; case EnumProcess.Designer: GlobalDef.CurrentDesigner.Process = process; break; case EnumProcess.Player: GlobalDef.ProcessPlayer = process; break; case EnumProcess.Receiver: GlobalDef.ProcessReceiver = process; break; case EnumProcess.Sender: GlobalDef.ProcessSender = process; break; default: break; } #region EXAMPLE //// This will get the current WORKING directory (i.e. \bin\Debug) //string workingDirectory = Environment.CurrentDirectory; //// This will get the current PROJECT directory //string projectDirectory = Directory.GetParent(workingDirectory).Parent.FullName; //string commandToExecute = Path.Combine(projectDirectory, "TestSetup", "WreckersTestSetupQA.bat"); //string workingFolder = Path.GetDirectoryName(commandToExecute); //commandToExecute = QuotesAround(commandToExecute); //ExecuteCommand(commandToExecute, workingFolder); #endregion }
/// <summary> /// Callback processing after receiving data. /// </summary> /// <remarks> /// </remarks> async private void CallbackSerialPort() { byte[] data = this._serialPort.ReceiveDataBuffer; int length = this._serialPort.ReceivedDataLength; bool isError = this._serialPort.IsError; byte responseCode = 0x00; try { TOFCommand command = this._listCommand[(int)this._indexSendCommandID]; if (6 <= length && data[0] == 0xFE) { responseCode = data[1]; // When the synchronization code is 0xFE and the received data length is 6 or more. int dataLength = (data[2] << 24) + (data[3] << 16) + (data[4] << 8) + data[5]; if (length == dataLength + 6) { // When all data can be received, // Write received data information to log area. this.txtLog.AppendText(string.Format("{0} {1} {2} {3}\r\n" , DateTime.Now.ToString("HH:mm:ss.fff") , length.ToString("D7") , "Receive" , BitConverter.ToString(data, 0, 20 <= length ? 20 : length))); this.txtLog.ScrollToCaret(); // Command processing switch (command.CommandID) { case 0x80: // Start measurement command // To get imager temperature this._indexSendCommandID = EnumSenario.GetImagerTemperature; break; case 0x9B: // Get imager temperature // Get upper left temperature double curImagerUL = ((data[6] << 8) + data[7]) / 10d; this.txtCurrentImagerUL.Text = string.Format("{0:F1}", curImagerUL); // Get upper right temperature double curImagerUR = ((data[8] << 8) + data[9]) / 10d; this.txtCurrentImagerUR.Text = string.Format("{0:F1}", curImagerUR); // Get lower left temperature double curImagerLL = ((data[10] << 8) + data[11]) / 10d; this.txtCurrentImagerLL.Text = string.Format("{0:F1}", curImagerLL); // Get lower right temperature double curImagerLR = ((data[12] << 8) + data[13]) / 10d; this.txtCurrentImagerLR.Text = string.Format("{0:F1}", curImagerLR); // Get imager start temperature double startImager = (double)this.nudStartImager.Value; // Get imager stop temperature double stopImager = (double)this.nudStopImager.Value; if (stopImager < curImagerUL || stopImager < curImagerUR || stopImager < curImagerLL || stopImager < curImagerLR) { // When Current temperature is larger than Stop temperature // To stop measurement this._indexSendCommandID = EnumSenario.StopMeasurement; // Detect Abnormal this._isAbnormalTemperatureImager = true; } else { if (this._isAbnormalTemperatureImager && (startImager < curImagerUL || startImager < curImagerUR || startImager < curImagerLL || startImager < curImagerLR)) { // When Current temperature is larger than Start temperature // To stop measurement this._indexSendCommandID = EnumSenario.StopMeasurement; // Detect Abnormal this._isAbnormalTemperatureImager = true; } else { // When Current temperature is less than Start temperature // To get LED temperature this._indexSendCommandID = EnumSenario.GetLEDTemperature; // Release Abnormal this._isAbnormalTemperatureImager = false; } } break; case 0x9C: // Get LED temperature double curLED = ((data[6] << 8) + data[7]) / 10d; this.txtCurrentLED.Text = string.Format("{0:F1}", curLED); // Get LED start temperature double startLED = (double)this.nudStartLED.Value; // Get LED stop temperature double stopLED = (double)this.nudStopLED.Value; if (stopLED < curLED) { // When Current temperature is larger than Stop temperature // To stop measurement this._indexSendCommandID = EnumSenario.StopMeasurement; // Detect Abnormal this._isAbnormalTemperatureLED = true; } else { if (this._isAbnormalTemperatureLED && startLED < curLED) { // When Current temperature is larger than Start temperature // To stop measurement this._indexSendCommandID = EnumSenario.StopMeasurement; // Detect Abnormal this._isAbnormalTemperatureLED = true; } else { // When Current temperature is less than Start temperature // To get imager temperature this._indexSendCommandID = EnumSenario.GetImagerTemperature; // Release Abnormal this._isAbnormalTemperatureLED = false; } } break; case 0x81: // Stop measurement command // Set time interval command.WaitTime = (int)this.nudInterval.Value * 1000; // To start measurement this._indexSendCommandID = EnumSenario.StartMeasurement; break; default: break; } } else { // When some data could not be received, // Write received data information to log area. this.txtLog.AppendText(string.Format("Failed to receive data. The received data length is {0} bytes.\r\n" , length)); this.txtLog.ScrollToCaret(); } } else { responseCode = 0x99; if (isError) { // When some data could not be received, // Write received data information to log area. this.txtLog.AppendText(string.Format("Failed to send data.\r\n")); } else { // When some data could not be received, // Write received data information to log area. this.txtLog.AppendText(string.Format("Failed to receive data.\r\n")); } this.txtLog.ScrollToCaret(); } // Processing steps if (this._enumProcess == EnumProcess.Stopping) { // To stop measurement this._indexSendCommandID = EnumSenario.StopMeasurement; this._enumProcess = EnumProcess.Stopped; } else if (this._enumProcess == EnumProcess.Stopped) { // End of scenario. MessageBox.Show("End of scenario.", "End", MessageBoxButtons.OK, MessageBoxIcon.Information); this.ChangeEnabledButton(false); return; } // Wait processing await Task.Run(() => this.Wait(command.WaitTime)); // Send command command = this._listCommand[(int)this._indexSendCommandID]; this.AsyncSerialPort(command); } catch (ObjectDisposedException) { // Do nothing until the object is destroyed. } }
/// <summary> /// Click the Stop button. /// </summary> /// <param name="sender">The evented object</param> /// <param name="e">Additional event information</param> /// <remarks> /// Scenario stop. /// </remarks> private void btnStop_Click(object sender, EventArgs e) { // Scenario stop this._enumProcess = EnumProcess.Stopping; }
/// <summary> /// 开灯,拉带trayType,slot无效 /// </summary> /// <param name="kangShiDaLightController"></param> /// <param name="threadName">线程名称</param> /// <param name="process">工序位置</param> /// <param name="slot">槽位,0代表空盘</param> private void SetLightBox(ATL_MC.KangShiDaLightController.KangShiDaLightController kangShiDaLightController, string threadName, EnumProcess process, EnumTrayType trayType, int slot = 0) { //先开灯 PolicyTypeA.Execute(() => { if (process == EnumProcess.MoveIn) { //拉带开灯 if (1 == kangShiDaLightController.SetLightBox(GetProductParam <int>(p => p.MoveInLight_1), GetProductParam <int>(p => p.MoveInLight_2))) { throw new Exception($"{threadName}:开灯失败"); } SYS_IBG_LOG(DEBUGL1MSG, 0, 0, $"{threadName}:{process.ToString()}工序,开灯成功"); } else { //tray盘开灯 if (1 == kangShiDaLightController.SetLightBox( GetProductParam <int>(p => p.ProductInfo(trayType, slot).Brightness_1), GetProductParam <int>(p => p.ProductInfo(trayType, slot).Brightness_2), GetProductParam <int>(p => p.ProductInfo(trayType, slot).Brightness_3), GetProductParam <int>(p => p.ProductInfo(trayType, slot).Brightness_4) )) { throw new Exception($"{threadName}:{process.ToString()}工序,{slot}槽位开灯失败"); } SYS_IBG_LOG(DEBUGL1MSG, 0, 0, $"{threadName}:{process.ToString()}工序,{slot}槽位开灯成功"); } }); }