Create Func : metadata_handler()

Merged Func: WriteSingleFilePmu() + WriteSingleFileDps()
This commit is contained in:
YuYang Shen
2025-03-18 16:03:59 +08:00
parent d731356b00
commit 18a986a128
6 changed files with 210 additions and 170 deletions
Binary file not shown.
@@ -51,9 +51,9 @@
"Title": "UserProgram.cs",
"DocumentMoniker": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs",
"RelativeDocumentMoniker": "Testrong.User.Program\\UserProgram.cs",
"ToolTip": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs",
"RelativeToolTip": "Testrong.User.Program\\UserProgram.cs",
"ViewState": "AgIAAP4IAAAAAAAAAAAowAcJAABWAAAAAAAAAA==",
"ToolTip": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs*",
"RelativeToolTip": "Testrong.User.Program\\UserProgram.cs*",
"ViewState": "AgIAAOADAAAAAAAAAAAQwPUDAAAYAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-18T12:27:43.78Z",
"EditorCaption": ""
@@ -1,16 +1,16 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\",
"WorkspaceRootPath": "D:\\WORK\\ManLin\\Verify\\UserProgram_time\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{E96B1A19-D109-4F67-B1AA-5BF15E580D77}|Testrong.User.Program\\Testrong.User.Program.csproj|d:\\work\\manlin\\verify\\prometheus\\1ks_ft_engineeringmachine\\userprogram_time\\testrong.user.program\\userprogram.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"AbsoluteMoniker": "D:0:0:{E96B1A19-D109-4F67-B1AA-5BF15E580D77}|Testrong.User.Program\\Testrong.User.Program.csproj|d:\\work\\manlin\\verify\\userprogram_time\\testrong.user.program\\userprogram.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{E96B1A19-D109-4F67-B1AA-5BF15E580D77}|Testrong.User.Program\\Testrong.User.Program.csproj|solutionrelative:testrong.user.program\\userprogram.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\ProgramData\\Testrong\\ATE_Tester\\setting\\NLog.config||{FA3CD31E-987B-443A-9B81-186104E8DAC1}"
},
{
"AbsoluteMoniker": "D:0:0:{E96B1A19-D109-4F67-B1AA-5BF15E580D77}|Testrong.User.Program\\Testrong.User.Program.csproj|D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\testrong.user.program\\keysight53220a.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"AbsoluteMoniker": "D:0:0:{E96B1A19-D109-4F67-B1AA-5BF15E580D77}|Testrong.User.Program\\Testrong.User.Program.csproj|D:\\WORK\\ManLin\\Verify\\UserProgram_time\\testrong.user.program\\keysight53220a.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{E96B1A19-D109-4F67-B1AA-5BF15E580D77}|Testrong.User.Program\\Testrong.User.Program.csproj|solutionrelative:testrong.user.program\\keysight53220a.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
@@ -37,9 +37,9 @@
"$type": "Document",
"DocumentIndex": 2,
"Title": "Keysight53220A.cs",
"DocumentMoniker": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\Keysight53220A.cs",
"DocumentMoniker": "D:\\WORK\\ManLin\\Verify\\UserProgram_time\\Testrong.User.Program\\Keysight53220A.cs",
"RelativeDocumentMoniker": "Testrong.User.Program\\Keysight53220A.cs",
"ToolTip": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\Keysight53220A.cs",
"ToolTip": "D:\\WORK\\ManLin\\Verify\\UserProgram_time\\Testrong.User.Program\\Keysight53220A.cs",
"RelativeToolTip": "Testrong.User.Program\\Keysight53220A.cs",
"ViewState": "AQIAAHMAAAAAAAAAAAAYwKkAAAAiAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
@@ -49,11 +49,11 @@
"$type": "Document",
"DocumentIndex": 0,
"Title": "UserProgram.cs",
"DocumentMoniker": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs",
"DocumentMoniker": "D:\\WORK\\ManLin\\Verify\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs",
"RelativeDocumentMoniker": "Testrong.User.Program\\UserProgram.cs",
"ToolTip": "D:\\WORK\\ManLin\\Verify\\Prometheus\\1KS_FT_EngineeringMachine\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs*",
"RelativeToolTip": "Testrong.User.Program\\UserProgram.cs*",
"ViewState": "AgIAAOADAAAAAAAAAAAQwPUDAAAYAAAAAAAAAA==",
"ToolTip": "D:\\WORK\\ManLin\\Verify\\UserProgram_time\\Testrong.User.Program\\UserProgram.cs",
"RelativeToolTip": "Testrong.User.Program\\UserProgram.cs",
"ViewState": "AgIAALAKAAAAAAAAAAAQwMUKAAApAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-06-18T12:27:43.78Z",
"EditorCaption": ""
+198 -158
View File
@@ -496,6 +496,93 @@ namespace Testrong.User.Program
return get;
}
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")
{
//Are We Writing the header of MetaData?
if (init_Flag == true)
{
//Each Slot has its own Thread
//But We DON'T want to run in parallel in this case(Cali&Write file)
//So We Should Check Which Slot We Are Running...
if (SlotNum == slotList[0])
{
swdata.WriteLine("Tester_Name,Board_Id,Slot_Ip,Stil_Version");
for (int w = 0; w < 12; w++)//修改为12SLOT
{
if (w == (slotList[0] - 1))
{
swdata.WriteLine($"Slot{SlotNum},{arm_dna},{context.Communicator.ServerIP},V1.0.0");
}
else
{
swdata.WriteLine($"Slot{(w + 1)}");
}
}
for (int i = 0; i < 1; i++)
{
swdata.WriteLine();
}
swdata.Write("Slot_Dna,Channel_Type,Channel_No,Mode,R_Load,I_Range,V_Range,Meas_Range,File_Path,File_Time\n");
}
else
{
int Cried = slotList.FindIndex(x => x.Equals(SlotNum));
while (true)
{
Thread.Sleep(1000);
if (File.Exists(EXT_CAL_PATH + slotList[Cried - 1] + ".flag")) //Wait until previous thread flags completion
{
File.Delete(EXT_CAL_PATH + slotList[Cried - 1] + ".flag");
break;
}
}
File.Move(METADATA_PATH, EXT_CAL_PATH + "metadata_temp" + ".csv");
StreamReader sr = new StreamReader(EXT_CAL_PATH + "metadata_temp" + ".csv", Encoding.UTF8);
int line = 0;
while (!sr.EndOfStream)
{
string tmp = sr.ReadLine();
if (line == slotList[Cried])
{
swdata.WriteLine("Slot" + SlotNum + "," + arm_dna + "," + context.Communicator.ServerIP + "," + "V1.0.0");
}
else
{
swdata.WriteLine(tmp);
}
line++;
}
sr.Close();
File.Delete(EXT_CAL_PATH + "metadata_temp" + ".csv");
}
}
//Now We Are Writing the body of the file
else
{
swdata.Write($"{arm_dna},");
swdata.Write($"{Type},");
if (Type == "PMU")
{
swdata.Write($"{Channel},");
}
else
{
swdata.Write($"PS{Channel},");
}
swdata.Write($"{Mode},");
swdata.Write($"{Rload},");
swdata.Write($"{Range},");
swdata.Write("20V,");
swdata.Write("13V,");
swdata.Write($"{filepath},");
swdata.Write($"{filetime}\n");
swdata.Flush();
}
}
private int GetPMUTempSensorIndex(int channel)
{
if ((channel >= 65 && channel <= 80) || (channel >= 97 && channel <= 112) || (channel >= 193 && channel <= 208) || (channel >= 241 && channel <= 256))
@@ -727,19 +814,43 @@ namespace Testrong.User.Program
}
return DmmDic;
}
public void WriteSingleFilePmu(string filename,int slot, string dna, int channel, string mode, string rload, double[,] extR, string range, double[] ForceValue, double[] AteMeasure, double[] DmmMeasure)
//Write Data To File
/*
* Variable Definition
* string filename: filename
* int slot: Slot Number
* string dna: DNA Number
* string type: DPS/PMU
* int channel: Channel Number(PMU:1-256, DPS:1-32/64)
* string mode: FVMV/FVMI/FIMV/FZMV(PMU Only)
* string rload: External Resistance Load
* double[,] extR: Internal Resistance On the External Calibration Board
* string range: Board Measurment Range(5uA; 20uA; 200uA; 2mA; 60mA; 1A(DPS Only))
* double[] ForceValue: ForceValue
* double[] AteMeasure: ATE Measure Value
* double[] DmmMeasure: DMM Measure Value
*/
public void WriteSingleFile(string filename,int slot, string dna, string type,int channel, string mode, string rload, double[,] extR, string range, double[] ForceValue, double[] AteMeasure, double[] DmmMeasure)
{
StreamWriter sw = new StreamWriter(filename, true, Encoding.UTF8);
sw.AutoFlush = true;
sw.Write("Tester_Name,Foo\n");
sw.Write($"Slot_No,{slot}\n");
sw.Write($"Board_Dna,{dna}\n");
sw.Write("Channel_Type,PMU\n");
sw.Write("Channel_Type,{type}\n");
sw.Write($"Channel_No,{channel}\n");
sw.Write($"Mode,{mode}\n");
sw.Write($"R_Load,{rload}\n");
sw.Write($"R_Int,{0}\n");
sw.Write($"R_Ext,{extR[channel - 1, slot - 1]}\n");
if(type == "PMU")
{
sw.Write($"R_Ext,{extR[channel - 1, slot - 1]}\n");
}
else
{
sw.Write($"R_Ext,{0}\n");
}
sw.Write($"I_Range,{range}\n");
sw.Write("V_Range,20V\n");
sw.Write("Meas_Range,13V\n");
@@ -789,67 +900,7 @@ namespace Testrong.User.Program
sw.Flush();
sw.Close();
}
public void WriteSingleFileDps(string filename, int slot, string dna, int channel, string mode, string rload, string range, double[] ForceValue, double[] AteMeasure, double[] DmmMeasure)
{
StreamWriter sw = new StreamWriter(filename, true, Encoding.UTF8);
sw.AutoFlush = true;
sw.Write("Tester_Name,Foo\n");
sw.Write($"Slot_No,{slot}\n");
sw.Write($"Board_Dna,{dna}\n");
sw.Write("Channel_Type,DPS\n");
sw.Write($"Channel_No,{channel}\n");
sw.Write($"Mode,{mode}\n");
sw.Write($"R_Load,{rload}\n");
sw.Write($"R_Int,{0}\n");
sw.Write($"R_Ext,{0}\n");
sw.Write($"I_Range,{range}\n");
sw.Write("V_Range,20V\n");
sw.Write("Meas_Range,13V\n");
sw.Write("\n");
sw.Write("Force Value,ATE Measure,DMM Measure,Temperature\n");
for (int writeLine = 0; writeLine < 5; writeLine++)
{
if (mode == "FVMV")
{
sw.Write($"{ForceValue[writeLine]:F8},");
sw.Write($"{AteMeasure[writeLine]:F8},");
sw.Write($"{DmmMeasure[writeLine]:F8},");
}
else if (mode == "FVMI")
{
if (range == "60mA" || range == "1A")
{
sw.Write($"{ForceValue[writeLine]:F10},");
sw.Write($"{AteMeasure[writeLine]:F15},");
sw.Write($"{DmmMeasure[writeLine]:F15},");
}
else
{
sw.Write($"{ForceValue[writeLine]:F10},");
sw.Write($"{AteMeasure[writeLine]:F15},");
sw.Write($"{(DmmMeasure[writeLine] / Convert.ToDouble(rload)):F15},");
}
}
else if (mode == "FIMV")
{
if (range == "60mA" || range == "5uA")
{
sw.Write($"{ForceValue[writeLine]:F10},");
sw.Write($"{AteMeasure[writeLine]:F15},");
sw.Write($"{(DmmMeasure[writeLine] / Convert.ToDouble(rload)):F15},");
}
else
{
sw.Write($"{ForceValue[writeLine]:F10},");
sw.Write($"{AteMeasure[writeLine]:F15},");
sw.Write($"{(DmmMeasure[writeLine] / Convert.ToDouble(rload)):F15},");
}
}
sw.Write($"{0:F8}\n");
}
sw.Flush();
sw.Close();
}
#endregion
#region TestCase
@@ -1302,17 +1353,7 @@ namespace Testrong.User.Program
File.Delete(EXT_CAL_PATH + "metadata_temp" + ".csv");
dmm.InitDMM(ksightConnStr);
}
Dictionary<int, int> M013_PMU = new Dictionary<int, int>()
{
{166,114 },
{167,113 },
{168,112 },
{169,111 },
{230,242 },
{231,241 },
{232,240 },
{233,239 }
};
string filetime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
for (int loopk = 0; loopk < 256; loopk++)
{
@@ -2193,65 +2234,21 @@ namespace Testrong.User.Program
throw ex;
}
//-----Start Slot Number-----
//Write Meta DATA
StreamWriter swdata;
if (SlotNum == slotList[0])
{
dmm.Init(ksightConnStr);
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8);
swdata.AutoFlush = true;
swdata.WriteLine("Tester_Name,Board_Id,Slot_Ip,Stil_Version");
for (int w = 0; w < 12; w++)//修改为12SLOT
{
if (w == (slotList[0] - 1))
{
swdata.WriteLine($"Slot{SlotNum},{arm_dna},{context.Communicator.ServerIP},V1.0.0");
}
else
{
swdata.WriteLine($"Slot{(w + 1)}");
}
}
for (int i = 0; i < 1; i++)
{
swdata.WriteLine();
}
swdata.Write("Slot_Dna,Channel_Type,Channel_No,Mode,R_Load,I_Range,V_Range,Meas_Range,File_Path,File_Time\n");
}
else
{
int Cried = slotList.FindIndex(x => x.Equals(SlotNum));
while (true)
{
Thread.Sleep(1000);
if (File.Exists(EXT_CAL_PATH + slotList[Cried - 1] + ".flag")) //Wait until previous thread flags completion
{
File.Delete(EXT_CAL_PATH + slotList[Cried - 1] + ".flag");
break;
}
}
dmm.Init(ksightConnStr);
File.Move(METADATA_PATH, EXT_CAL_PATH + "metadata_temp" + ".csv");
StreamReader sr = new StreamReader(EXT_CAL_PATH + "metadata_temp" + ".csv", Encoding.UTF8);
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8);
swdata.AutoFlush = true;
int line = 0;
while (!sr.EndOfStream)
{
string tmp = sr.ReadLine();
if (line == slotList[Cried])
{
swdata.WriteLine("Slot" + SlotNum + "," + arm_dna + "," + context.Communicator.ServerIP + "," + "V1.0.0");
}
else
{
swdata.WriteLine(tmp);
}
line++;
}
sr.Close();
File.Delete(EXT_CAL_PATH + "metadata_temp" + ".csv");
}
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8);
swdata.AutoFlush = true;
metadata_handler(
swdata: swdata,
SlotNum: SlotNum,
slotList: slotList,
arm_dna: arm_dna,
context: context,
init_Flag: true
);
//-----Start Data Collection-----
dmm.Init(ksightConnStr);
List<TestInfoSet> Info = slotTestInfo[SlotNum];
//{0:PMU_FVMV; 1:PMU_FVMI; 2:PMU_FIMV; 3:PMU_FZMV; 4:DPS_FVMV; 5:DPS_FVMI; 6:DPS_FIMV}
for (int loopi = 0; loopi < Info.Count/*Info.Count*/; loopi ++)//-----Loop Mode and Type-----
@@ -2387,7 +2384,7 @@ namespace Testrong.User.Program
string[] PmuPinName_FZFV = new string[2];
for (int loopk = 0; loopk < ListChannels.Count/*ListChannels.Count*/; loopk++)//-----Loop Channel-----
{
if (Info[loopi].chType == "PMU")
if (Type == "PMU")
{
int ch = ListChannels[loopk];
@@ -2564,7 +2561,7 @@ namespace Testrong.User.Program
ForceValueDir.Add(ListChannels[loopk], ForceValue);
testCh.Add(ListChannels[loopk]);
}
if(Info[loopi].chType == "DPS")
else if(Type == "DPS")
{
string[] DpsPinName = { ("DPS" + ListChannels[loopk]) };
string[] allDpsPinNames = Select_DpsPin[testVersion];
@@ -2749,10 +2746,14 @@ namespace Testrong.User.Program
testCh.Add(ListChannels[loopk]);
}
}
//Read Back Value From DMM
int DataCount = testCh.Count * SampliCount;
double[] dmmRead = dmm.MultiRead(DataCount);
dmm.ClearReadingMemory();
DmmMeasureDir = ReadBackDmm(dmmRead, testCh);
//Write Data to File
if (Type == "PMU")
{
for (int writeNum = 0; writeNum < testCh.Count; writeNum++)
@@ -2761,18 +2762,36 @@ namespace Testrong.User.Program
string filepath = "Slot" + SlotNum + "_PMU_" + "ch" + ch + "_" + Mode + "_" + Rload + "_" + Range + ".csv";
string filename = EXT_CAL_PATH + filepath;
string filetime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
WriteSingleFilePmu(filename, SlotNum, arm_dna, ch, Mode, rl, ExtBoard_Res, Range, ForceValueDir[ch], AteMeasureDir[ch], DmmMeasureDir[ch]);
swdata.Write($"{arm_dna},");
swdata.Write("PMU,");
swdata.Write($"{ch},");
swdata.Write($"{Mode},");
swdata.Write($"{rl},");
swdata.Write($"{Range},");
swdata.Write("20V,");
swdata.Write("13V,");
swdata.Write($"{filepath},");
swdata.Write($"{filetime}\n");
swdata.Flush();
WriteSingleFile(
filename: filename,
slot: SlotNum,
dna: arm_dna,
type: Type,
channel: ch,
mode: Mode,
rload: rl,
extR: ExtBoard_Res,
range: Range,
ForceValue: ForceValueDir[ch],
AteMeasure: AteMeasureDir[ch],
DmmMeasure: DmmMeasureDir[ch]
);
metadata_handler(
swdata: swdata,
SlotNum: SlotNum,
slotList: slotList,
arm_dna: arm_dna,
context: context,
init_Flag: false,
Type:Type,
Channel:ch,
Mode:Mode,
Rload:rl,
Range:Range,
filepath:filepath,
filetime:filetime
);
}
}
else
@@ -2783,18 +2802,39 @@ namespace Testrong.User.Program
string filepath = "Slot" + SlotNum + "_DPS_" + "ch" + ch + "_" + Mode + "_" + Rload + "_" + Range + ".csv";
string filename = EXT_CAL_PATH + filepath;
string filetime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
WriteSingleFileDps(filename, SlotNum, arm_dna, ch, Mode, rl, Range, ForceValueDir[ch], AteMeasureDir[ch], DmmMeasureDir[ch]);
swdata.Write($"{arm_dna},");
swdata.Write("DPS,");
swdata.Write($"PS{ch},");
swdata.Write($"{Mode},");
swdata.Write($"{rl},");
swdata.Write($"{Range},");
swdata.Write("20V,");
swdata.Write("13V,");
swdata.Write($"{filepath},");
swdata.Write($"{filetime}\n");
swdata.Flush();
double[,] ZeroExtR = {
{ 0.0 , 0.0 , 0.0}
};
WriteSingleFile(
filename:filename,
slot: SlotNum,
dna :arm_dna,
type: Info[loopi].chType,
channel:ch,
mode:Mode,
rload:rl,
extR: ZeroExtR,
range:Range,
ForceValue:ForceValueDir[ch],
AteMeasure:AteMeasureDir[ch],
DmmMeasure:DmmMeasureDir[ch]
);
metadata_handler(
swdata: swdata,
SlotNum: SlotNum,
slotList: slotList,
arm_dna: arm_dna,
context: context,
init_Flag: false,
Type: Type,
Channel: ch,
Mode: Mode,
Rload: rl,
Range: Range,
filepath: filepath,
filetime: filetime
);
}
}
}