Fix MetaData file confilct

This commit is contained in:
YuYang Shen
2025-04-08 16:22:31 +08:00
parent bee8715471
commit fc794c971c
15 changed files with 104 additions and 74 deletions
+34 -30
View File
@@ -4,8 +4,10 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading;
using System.Xml.Linq;
using Testrong.Core.Common;
using Testrong.Core.Model.ACTiming;
using Testrong.Core.Model.ChannelMap;
@@ -557,8 +559,6 @@ namespace Testrong.User.Program
else
{
int slotIndex = slotList.FindIndex(x => x.Equals(SlotNum));
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)
@@ -664,6 +664,10 @@ namespace Testrong.User.Program
}
Directory.CreateDirectory(WritePath);
}
else
{
File.Move(METADATA_PATH, EXT_CAL_PATH + "metadata_temp" + ".csv");
}
}
catch (Exception ex)
{
@@ -702,25 +706,31 @@ namespace Testrong.User.Program
WritePath = EXT_CAL_PATH;
break;
}
if (SlotNum != slotList[0]) //If we are NOT the FIRST slot in the list
if(lockFlag==true)
{
int slotIndex = slotList.FindIndex(x => x.Equals(SlotNum));
while (lockFlag) //Do we need lock or just set the Flag as we are done
if (SlotNum != slotList[0]) //If we are NOT the FIRST slot in the list
{
Thread.Sleep(1000);
if (File.Exists(WritePath + slotList[slotIndex - 1] + ".flag")) //Wait until previous thread flags completion
int slotIndex = slotList.FindIndex(x => x.Equals(SlotNum));
while (lockFlag) //Do we need lock or just set the Flag as we are done
{
File.Delete(WritePath + slotList[slotIndex - 1] + ".flag");
break;
Thread.Sleep(1000);
if (File.Exists(WritePath + slotList[slotIndex - 1] + ".flag")) //Wait until previous thread flags completion
{
File.Delete(WritePath + slotList[slotIndex - 1] + ".flag");
break;
}
}
}
if(SlotNum != slotList[slotList.Count - 1]) //If we are NOT the LAST slot in the list
}
else
{
if (SlotNum != slotList[slotList.Count - 1]) //If we are NOT the LAST slot in the list
{
StreamWriter swSignal = new StreamWriter(WritePath + SlotNum + ".flag"); //Create file flagging end of current thread
swSignal.WriteLine();
swSignal.Flush();
swSignal.Close();
}
}
}
}
private int GetPMUTempSensorIndex(int channel)
@@ -1397,7 +1407,6 @@ namespace Testrong.User.Program
armDnaRaw = armDnaRaw.Reverse().ToArray();
string arm_dna = BitConverter.ToUInt64(armDnaRaw, 0).ToString(); //convert hex dna to decimal
int SlotNum = context.Communicator.SlotNo;
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Init",lockFlag: true);
if (SlotNum == slotList[0])
{
if (Directory.Exists(RINT_PATH))
@@ -1413,19 +1422,11 @@ namespace Testrong.User.Program
EmptyDir(DOWN_INITVALUE_PATH);
}
DelayHelper.Sleep(1);
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Init", lockFlag: true);
}
else
{
int slotIndex = slotList.FindIndex(x => x.Equals(SlotNum));
while (true)
{
Thread.Sleep(1000);
if (File.Exists(EXT_CAL_INIT_PATH + slotList[slotIndex - 1] + ".flag"))
{
File.Delete(EXT_CAL_INIT_PATH + slotList[slotIndex - 1] + ".flag");
break;
}
}
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Init", lockFlag: true);
}
ExternalCalibrationHandle extCaliHandle = new ExternalCalibrationHandle();
@@ -1514,9 +1515,9 @@ namespace Testrong.User.Program
swdata = new StreamWriter(METADATA_PATH, true, Encoding.UTF8)
{
AutoFlush = true
};
};
Metadata_handler(
Metadata_handler(
swdata: swdata,
SlotNum: SlotNum,
slotList: slotList,
@@ -1672,7 +1673,6 @@ namespace Testrong.User.Program
File_Mover(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Single");
//---------Thread Locker--------
int slotIndex = slotList.FindIndex(x => x.Equals(SlotNum));
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL", lockFlag: true);
//-----Start Write MetaData-----
@@ -1682,14 +1682,14 @@ namespace Testrong.User.Program
AutoFlush = true
};
Metadata_handler(
Metadata_handler(
swdata: swdata,
SlotNum: SlotNum,
slotList: slotList,
arm_dna: arm_dna,
context: context,
init_Flag: true
);
);
#endregion
#region Config DMM
@@ -1910,6 +1910,7 @@ namespace Testrong.User.Program
if (SlotNum == slotList[0])
{
DelayHelper.Sleep(1);
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "RINT", lockFlag: true);
}
else
{
@@ -2002,6 +2003,7 @@ namespace Testrong.User.Program
if (SlotNum == slotList[0])
{
DelayHelper.Sleep(1);
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Init", lockFlag: true);
}
else
{
@@ -2069,6 +2071,7 @@ namespace Testrong.User.Program
}
DelayHelper.Sleep(1);
dmm.InitDMM(ksightConnStr);
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_Init", lockFlag: true);
}
else
{
@@ -2377,7 +2380,7 @@ namespace Testrong.User.Program
//---------Thread Locker--------
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL", lockFlag: true);
//-----Start Slot Number-----
// Write MetaData.csv Header
@@ -3125,10 +3128,11 @@ namespace Testrong.User.Program
if (SlotNum == slotList[0])
{
DelayHelper.Sleep(1);
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_COM", lockFlag: true);
}
else
{
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_COM",lockFlag:true);
SlotThreadLocker(SlotNum: SlotNum, slotList: slotList, pathFlag: "CAL_COM", lockFlag: true);
}
//Write files
@@ -3196,7 +3200,7 @@ namespace Testrong.User.Program
arm_dna: arm_dna,
context: context,
init_Flag: true
);
);
string filetime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
for (int loopk = 0; loopk < 256; loopk++)
{