Add File_Mover()

This commit is contained in:
YuYang Shen
2025-03-19 15:54:22 +08:00
parent 9bdb2ea937
commit 75738a0863
46 changed files with 126 additions and 24595 deletions
+123 -145
View File
@@ -482,20 +482,20 @@ namespace Testrong.User.Program
}
/*
/* ----------Metadata_handler-------------
* StreamWriter swdata: File Handler, Should be Initialized ahead,
* int SlotNum: Current Slot Number,
* List<int> slotList: Slot List,
* string arm_dna: DNA Data from Zynq,
* IFlowRunnerContext context: info from ATE Software,
* bool init_Flag: choose from Header to Body| True=Header/False=Body,
* string Type:[OPTIONAL] Only need if init_Flag==False, Channel Type, Possible Value="PMU","DPS", "NULL"(Default),
* int Channel:[OPTIONAL] Only need if init_Flag==False, Channel Number, Default = -1,
* string Mode:[OPTIONAL] Only need if init_Flag==False, Test Mode, Possible Value="FVMV","FVMI","FIMV","FIMI","FZMV"(PMU Only), "NULL"(Default),
* string Rload:[OPTIONAL] Only need if init_Flag==False,Resistance Load, Default = "NaN",
* string Range:[OPTIONAL] Only need if init_Flag==False,Range, Possible Value="5uA", "20uA", "200uA", "2mA", "60mA", "1A"(DPS Only), Default = "N/A",
* string filepath:[OPTIONAL] Only need if init_Flag==False, CSV File Path, Default = "N/A",
* string filetime:[OPTIONAL] Only need if init_Flag==False, CSV File Creation Time, Default = "N/A"
* string Type:[OPTIONAL] Only need if init_Flag == False, Channel Type, Possible Value="PMU","DPS", "NULL"(Default),
* int Channel:[OPTIONAL] Only need if init_Flag == False, Channel Number, Default = -1,
* string Mode:[OPTIONAL] Only need if init_Flag == False, Test Mode, Possible Value="FVMV","FVMI","FIMV","FIMI","FZMV"(PMU Only), "NULL"(Default),
* string Rload:[OPTIONAL] Only need if init_Flag == False,Resistance Load, Default = "NaN",
* string Range:[OPTIONAL] Only need if init_Flag == False,Range, Possible Value="5uA", "20uA", "200uA", "2mA", "60mA", "1A"(DPS Only), Default = "N/A",
* string filepath:[OPTIONAL] Only need if init_Flag == False, CSV File Path, Default = "N/A",
* string filetime:[OPTIONAL] Only need if init_Flag == False, CSV File Creation Time, Default = "N/A"
*/
public void Metadata_handler(StreamWriter swdata, int SlotNum, List<int> slotList, string arm_dna, IFlowRunnerContext context, bool init_Flag, string Type = "NULL", int Channel = -1, string Mode = "NULL", string Rload = "NaN", string Range = "N/A", string filepath = "N/A", string filetime = "N/A")
{
@@ -584,6 +584,76 @@ namespace Testrong.User.Program
}
}
/* ----------File_Mover-------------
* int SlotNum: Current Slot Number,
* List<int> slotList: Slot List,
* string pathFlag: Path Selector, Possible Value="Freq","CAL_Single"(No Pre/Post),"CAL_Normal",
* bool isPreCheck:[OPTIONAL] Only need if pathFlag =="CAL_Normal",PreCheck Flag, Default = false
*/
public void File_Mover(int SlotNum, List<int> slotList, string pathFlag, bool isPreCheck = false)
{
string DateCode = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
string WritePath;
string BakPath;
string HistoryPath;
switch (pathFlag)
{
case "Freq":
WritePath = EXT_CAL_FREQ_PATH;
HistoryPath = EXT_CAL_FREQ_HISTORY_PATH;
BakPath = "C:\\ProgramData\\Testrong\\ATE_Tester";
break;
default:
WritePath = EXT_CAL_PATH;
HistoryPath = EXT_CAL_HISTORY_PATH;
BakPath = EXT_CAL_MV_PATH;
break;
}
try
{
if (SlotNum == slotList[0])
{
if (pathFlag == "CAL_Normal")
{
if (isPreCheck == true)
{
EmptyDir(CAL_COMPFILE_PATH);
ClearPrePostFile(CAL_PRECHECK_PATH);
ClearPrePostFile(CAL_POSTCHECK_PATH);
}
else if (isPreCheck == false)
{
Thread.Sleep(1);
}
}
if (Directory.Exists(BakPath))
{
if (!Directory.Exists(HistoryPath))
{
Directory.CreateDirectory(HistoryPath);
}
Directory.Move(BakPath, HistoryPath + DateCode);
}
if (Directory.Exists(WritePath))
{
Directory.Move(WritePath, BakPath);
}
Directory.CreateDirectory(WritePath);
}
}
catch (Exception ex)
{
LogRawText(ex.StackTrace);
throw ex;
}
}
private int GetPMUTempSensorIndex(int channel)
{
if ((channel >= 65 && channel <= 80) || (channel >= 97 && channel <= 112) || (channel >= 193 && channel <= 208) || (channel >= 241 && channel <= 256))
@@ -1026,26 +1096,7 @@ namespace Testrong.User.Program
}
//creat dir
try
{
if (SlotNum == slotList[0])
{
if (Directory.Exists(EXT_CAL_FREQ_PATH))
{
if (!Directory.Exists(EXT_CAL_FREQ_HISTORY_PATH))
{
Directory.CreateDirectory(EXT_CAL_FREQ_HISTORY_PATH);
}
Directory.Move(EXT_CAL_FREQ_PATH, EXT_CAL_FREQ_HISTORY_PATH + DateCode);
}
Directory.CreateDirectory(EXT_CAL_FREQ_PATH);
}
}
catch (Exception ex)
{
LogRawText(ex.StackTrace);
throw ex;
}
File_Mover(SlotNum:SlotNum,slotList:slotList,pathFlag:"Freq");
StreamWriter swResult;
if (SlotNum == slotList[0])
@@ -1277,31 +1328,10 @@ namespace Testrong.User.Program
string arm_dna = BitConverter.ToUInt64(armDnaRaw, 0).ToString();
int SlotNum = context.Communicator.SlotNo;
double[,] ExtBoard_Res = ReadRext(EXT_CAL_INIT_PATH + "ExtBoardRes.csv");
try
{
string DateCode = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
if (SlotNum == slotList[0])
{
if (Directory.Exists(EXT_CAL_MV_PATH))
{
if (!Directory.Exists(EXT_CAL_HISTORY_PATH))
{
Directory.CreateDirectory(EXT_CAL_HISTORY_PATH);
}
Directory.Move(EXT_CAL_MV_PATH, EXT_CAL_HISTORY_PATH + DateCode);
}
if (Directory.Exists(EXT_CAL_PATH))
{
Directory.Move(EXT_CAL_PATH, EXT_CAL_MV_PATH);
}
Directory.CreateDirectory(EXT_CAL_PATH);
}
}
catch (Exception ex)
{
LogRawText(ex.StackTrace);
throw ex;
}
//Folder Related
File_Mover(SlotNum:SlotNum,slotList:slotList,pathFlag:"CAL_Single");
//-----Start Slot Number-----
StreamWriter swdata;
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8)
@@ -1551,31 +1581,7 @@ namespace Testrong.User.Program
double[,] ExtBoard_Res = ReadRext(EXT_CAL_INIT_PATH + "ExtBoardRes.csv");
//-----Move File To History-----
try
{
string DateCode = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
if (SlotNum == slotList[0])
{
if (Directory.Exists(EXT_CAL_MV_PATH))
{
if (!Directory.Exists(EXT_CAL_HISTORY_PATH))
{
Directory.CreateDirectory(EXT_CAL_HISTORY_PATH);
}
Directory.Move(EXT_CAL_MV_PATH, EXT_CAL_HISTORY_PATH + DateCode);
}
if (Directory.Exists(EXT_CAL_PATH))
{
Directory.Move(EXT_CAL_PATH, EXT_CAL_MV_PATH);
}
Directory.CreateDirectory(EXT_CAL_PATH);
}
}
catch (Exception ex)
{
LogRawText(ex.StackTrace);
throw ex;
}
File_Mover(SlotNum:SlotNum,slotList:slotList,pathFlag:"CAL_Single");
//-----Start Slot Number-----
StreamWriter swdata;
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8)
@@ -1730,6 +1736,8 @@ namespace Testrong.User.Program
singlefile.Close();
}
Pmur.Close();
#region Thread Lock
if (SlotNum < slotList[slotList.Count - 1])
{
StreamWriter swSignal = new StreamWriter(EXT_CAL_PATH + SlotNum + ".flag"); //Create file flagging end of current thread
@@ -1737,7 +1745,7 @@ namespace Testrong.User.Program
swSignal.Flush();
swSignal.Close();
}
#endregion
}
void ExternalCalibrationReset(IFlowRunnerContext context)
{
@@ -1908,6 +1916,7 @@ namespace Testrong.User.Program
}
void ExternalCalibrationCollect(IFlowRunnerContext context, TestVersion testVersion, bool isFirstTest, bool isPreCheck)
{
#region Read JSON
bool isDefault = Readjson(CONFIG_JSON_PATH).Default;
List<int> Range_pmu_fvmv = Readjson(CONFIG_JSON_PATH).PMU_FVMV;
List<int> Range_pmu_fvmi = Readjson(CONFIG_JSON_PATH).PMU_FVMI;
@@ -1948,7 +1957,9 @@ namespace Testrong.User.Program
Dictionary<string, TestParaSet> testParaSet_dps_fvmv = new Dictionary<string, TestParaSet>();
Dictionary<string, TestParaSet> testParaSet_dps_fvmi = new Dictionary<string, TestParaSet>();
Dictionary<string, TestParaSet> testParaSet_dps_fimv = new Dictionary<string, TestParaSet>();
//配置延时,采样次数,采样间隔
#endregion
#region
switch (testVersion)
{
case TestVersion.Board_1K_FT:
@@ -2004,6 +2015,9 @@ namespace Testrong.User.Program
testParaSet_pmu_fvmv = avgDelays_fvmv_pmu;
testParaSet_pmu_fzmv = avgDelays_fzmv_pmu;
testParaSet_dps_fvmv = avgDelays_fvmv_dps;
#endregion
#region Do Configuration
//-----get all connect slot number-----
var slotInfos = context.FlowCatalog.GetAll<SlotInfo>();
List<int> slotList = new List<int>();
@@ -2029,6 +2043,7 @@ namespace Testrong.User.Program
armDnaRaw = armDnaRaw.Reverse().ToArray();
string arm_dna = BitConverter.ToUInt64(armDnaRaw, 0).ToString();
int SlotNum = context.Communicator.SlotNo;
#endregion
//-----Select PreTest or ReTest-----
#region
if (isFirstTest == true)
@@ -2136,42 +2151,10 @@ namespace Testrong.User.Program
Dictionary<string, string> RlDpsFi = ReadRload(EXT_CAL_INIT_PATH + "res.csv")[3];
double[,] ExtBoard_Res = ReadRext(EXT_CAL_INIT_PATH + "ExtBoardRes.csv");
#region File/Folder Prepartion
//-----Move File To History-----
try
{
string DateCode = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
if (SlotNum == slotList[0])
{
if (isPreCheck == true)
{
EmptyDir(CAL_COMPFILE_PATH);
ClearPrePostFile(CAL_PRECHECK_PATH);
ClearPrePostFile(CAL_POSTCHECK_PATH);
}
else if (isPreCheck == false)
{
Thread.Sleep(1);
}
if (Directory.Exists(EXT_CAL_MV_PATH))
{
if (!Directory.Exists(EXT_CAL_HISTORY_PATH))
{
Directory.CreateDirectory(EXT_CAL_HISTORY_PATH);
}
Directory.Move(EXT_CAL_MV_PATH, EXT_CAL_HISTORY_PATH + DateCode);
}
if (Directory.Exists(EXT_CAL_PATH))
{
Directory.Move(EXT_CAL_PATH, EXT_CAL_MV_PATH);
}
Directory.CreateDirectory(EXT_CAL_PATH);
}
}
catch (Exception ex)
{
LogRawText(ex.StackTrace);
throw ex;
}
File_Mover(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Normal",isPreCheck:isPreCheck);
//-----Start Slot Number-----
// Write MetaData.csv Header
StreamWriter swdata;
@@ -2188,6 +2171,10 @@ namespace Testrong.User.Program
context: context,
init_Flag: true
);
#endregion
#region Data Collection
//-----Start Data Collection-----
dmm.Init(ksightConnStr);
List<TestInfoSet> Info = slotTestInfo[SlotNum];
@@ -2327,12 +2314,15 @@ namespace Testrong.User.Program
string[] PmuPinName_FV = new string[1];
string[] PmuPinName_FZFV = new string[2];
double[] AteMeasure = new double[SampliCount];
double[] ForceValue = new double[SampliCount];
double[] TempValue = new double[SampliCount];
#region Do Force/Measure/DMM
for (int loopk = 0; loopk < ListChannels.Count/*ListChannels.Count*/; loopk++)//-----Loop Channel-----
{
//Note: Must put them here as Dictionary `Add` do reference NOT clone
double[] AteMeasure = new double[SampliCount];
double[] ForceValue = new double[SampliCount];
double[] TempValue = new double[SampliCount];
if (Type == "PMU")
{
int ch = ListChannels[loopk];
@@ -2720,13 +2710,16 @@ namespace Testrong.User.Program
testCh.Add(ch);
}
}
//Read Back Value From DMM
int DataCount = testCh.Count * SampliCount;
double[] dmmRead = dmm.MultiRead(DataCount);
dmm.ClearReadingMemory();
DmmMeasureDir = ReadBackDmm(dmmRead, testCh);
#endregion
#region WriteToFile
//Write Data to File
if (Type == "PMU")
{
@@ -2769,7 +2762,7 @@ namespace Testrong.User.Program
);
}
}
else
else if(Type == "DPS")
{
for (int writeNum = 0; writeNum < testCh.Count; writeNum++)
{
@@ -2813,9 +2806,12 @@ namespace Testrong.User.Program
);
}
}
#endregion
}
}
#endregion
#region Thread Lock
if (SlotNum < slotList[slotList.Count - 1])
{
StreamWriter swSignal = new StreamWriter(EXT_CAL_PATH + SlotNum + ".flag"); //Create file flagging end of current thread
@@ -2823,9 +2819,12 @@ namespace Testrong.User.Program
swSignal.Flush();
swSignal.Close();
}
#endregion
dmm.ResetInstrument();
swdata.Flush();
swdata.Close();
}
void ExternalCalibrationWriteCalFiles(IFlowRunnerContext context)
@@ -2910,31 +2909,10 @@ namespace Testrong.User.Program
string arm_dna = BitConverter.ToUInt64(armDnaRaw, 0).ToString();
int SlotNum = context.Communicator.SlotNo;
double[,] ExtBoard_Res = ReadRext(EXT_CAL_INIT_PATH + "ExtBoardRes.csv");
try
{
string DateCode = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
if (SlotNum == slotList[0])
{
if (Directory.Exists(EXT_CAL_MV_PATH))
{
if (!Directory.Exists(EXT_CAL_HISTORY_PATH))
{
Directory.CreateDirectory(EXT_CAL_HISTORY_PATH);
}
Directory.Move(EXT_CAL_MV_PATH, EXT_CAL_HISTORY_PATH + DateCode);
}
if (Directory.Exists(EXT_CAL_PATH))
{
Directory.Move(EXT_CAL_PATH, EXT_CAL_MV_PATH);
}
Directory.CreateDirectory(EXT_CAL_PATH);
}
}
catch (Exception ex)
{
LogRawText(ex.StackTrace);
throw ex;
}
//Folder Related
File_Mover(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Single");
//-----Start Slot Number-----
StreamWriter swdata;
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8)