using System; using System.Text; using System.IO; using System.Linq; using System.Drawing; using System.Diagnostics; using System.Windows.Forms; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using Tango.PMR.Stubs; using Tango.Stubs; const int Winder_UNDER_TEST=6; string [,] Units_status_Winder = new string[Winder_UNDER_TEST,2] { {"Winder_Motor","Not Test"}, {"Screw_Motor","Not Test"}, {"LS_Screw_Right","Not Test"}, {"LS_Screw_Left","Not Test"}, {"Screw_Encoder","Not Test"}, {"SW_Spool_Exist","Not Test"}, }; //-------------------------------------------------------------------------------- public Task Winder_test( Action settext, CancellationToken cancellationToken, string SN, string Location) { Task task = null; // Start a task and return it task = Task.Run(() => { stubManager.Write("S/N:" +SN+ "\n"); stubManager.Write("Location:" +Location+ "\n"); copy_table (Winder_UNDER_TEST,Units_status_Winder); DialogResult result2 = MessageBox.Show("Insert Spool"); settext("Test_Winder_motor"); Test_Winder_motor(); settext("Test_Screw_LS_Motor_Encoder"); Test_Screw_LS_Motor_Encoder (); settext("Test_Pooler_Exis"); Test_Pooler_Exist (); Status=write_to_file(SN,Location,Winder_UNDER_TEST,"Winder"); settext("End Test"); decimal result = 0; return result; }); return task; } //------------------------------------------ public int Test_Winder_motor () { stubManager.Run("StubMotorRunRequest" ,WINDER_Motor, true, 500); //rotate Winder Motor. stubManager.Write("Winder Motor rotate \n"); DialogResult result = MessageBox.Show("Are Winder Motor rotate?", "Warning",MessageBoxButtons.YesNo); if (_cancellationTokenSource.Token.IsCancellationRequested) { _cancellationTokenSource.Token.ThrowIfCancellationRequested(); throw new TaskCanceledException(); return 0; } if(result == DialogResult.No) { Units_status[0,1]="Fail"; stubManager.Write("Winder Motor not rotate\n"); } else { Units_status[0,1]="Pass"; stubManager.Write("Winder Motor rotate\n"); } stubManager.Run("StubMotorStopRequest" ,WINDER_Motor,3); //stop motor return 0; } //-------------------------------------------- int Test_Screw_LS_Motor_Encoder() { UInt32 temp ; Int32 Bit = 1; stubManager.Run("StubMotorRunRequest" ,SCREW, false, 250); //rotate screw Motor out. delay(1000); stubManager.Run("StubMotorStopRequest" ,SCREW,3); //stop motor DialogResult result2 = MessageBox.Show("Did screw Motor move ?", "Warning",MessageBoxButtons.YesNo); if(result2 == DialogResult.No) { Units_status[1,1]="Fail"; stubManager.Write("Screw Motor not move\n"); return 0; } Units_status[1,1]="Pass"; stubManager.Write("Screw Motor rotate \n"); stubManager.Run("StubMotorRunRequest" ,SCREW, true, 250); stubManager.Write("Move screw in\n"); Bit = 1; int i=0; while ((Bit != 0x0)&& (i<200) ) //wait until Limit Switch or timeout 200*50msec=10sec { Bit = GetBit(F1_LS_03_Direct,0); delay(50); i++; } stubManager.Run("StubMotorStopRequest" ,SCREW,3); //stop motor DialogResult result1 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo); if(result1 == DialogResult.No) { Units_status[2,1]="Fail"; stubManager.Write("LS_SCREW_RIGHT Not calibrate\n"); return 0; } Units_status[2,1]="Pass"; stubManager.Write("Move screw out\n"); stubManager.Run("StubFpgaWriteRegRequest" ,F1_SCREW_ROTENC_lsb, 0x0000); //clear encoder stubManager.Run("StubFpgaWriteRegRequest" ,F1_SCREW_ROTENC_msb, 0x0000); //clear encoder Bit = 1; stubManager.Run("StubMotorRunRequest" ,SCREW, false, 250); i=0; while ((Bit != 0x0) && (i<200)) //wait until Limit Switch or timeout 200*50msec=10sec { Bit = GetBit(F1_LS_03_Direct,1); delay(50); i++; } stubManager.Run("StubMotorStopRequest" ,SCREW,3); //stop motor DialogResult result3 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo); if(result3 == DialogResult.No) { Units_status[3,1]="Fail"; stubManager.Write("LS_SCREW_LEFT Not calibrate\n"); return 0; } Units_status[3,1]="Pass"; var response = stubManager.Run("StubFpgaReadRegRequest" ,F1_SCREW_ROTENC_lsb); var response1 = stubManager.Run("StubFpgaReadRegRequest" ,F1_SCREW_ROTENC_msb); temp=(response.Value & 0xffff )+((response1.Value & 0xffff )<<16); temp=temp&0x0fffffff; temp= 0x4000000-temp; stubManager.Write("Encoder positio:" +temp+"\n"); if ((temp>20000) && temp<28000) Units_status[4,1]="Pass"; else Units_status[4,1]="Fail";// return 1; } //--------------------------------------- int Test_Pooler_Exist() { if ( (GetBit(F1_LS_03_Direct,11))==0) { Units_status[5,1]="Fail"; return 0; } DialogResult result2 = MessageBox.Show("Remove Spool"); if ( (GetBit(F1_LS_03_Direct,11))!=0) Units_status[5,1]="Fail"; // else Units_status[5,1]="Pass"; return 0 ; }