PLC时间对接
定时器测试 s7通讯加辅助方法 4.21 测试
This commit is contained in:
parent
76cd069435
commit
e8001a81bb
@ -134,7 +134,7 @@ namespace WindowsFormsApp1
|
||||
screwReportTimer.Interval = 1000 * 60 * 15;
|
||||
screwReportTimer.Tick += ScrewReportTimer_Tick;
|
||||
|
||||
fileUploadTimer.Interval = 1000 * 60 * 5;
|
||||
fileUploadTimer.Interval = 1000 * 60 * 15;
|
||||
fileUploadTimer.Tick += FileUploadTimer_Tick;
|
||||
}
|
||||
|
||||
@ -623,8 +623,15 @@ namespace WindowsFormsApp1
|
||||
//文件上传
|
||||
}
|
||||
// oeedatacollection
|
||||
var oeeresult = siemensHelp.ReadAddress(oeeaddresses);
|
||||
otherdata.Oeeaddresses = oeeaddresses;
|
||||
try
|
||||
{
|
||||
var oeeresult = siemensHelp.ReadAddress(oeeaddresses);
|
||||
otherdata.Oeeaddresses = oeeaddresses;
|
||||
}
|
||||
catch
|
||||
{
|
||||
LogExecute.logNet.WriteError("读取PLC OEE失败!");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 判断物料调用次数 固化站,抽真空
|
||||
@ -932,12 +939,15 @@ namespace WindowsFormsApp1
|
||||
// 启动状态上报定时器
|
||||
statusReportTimer.Start();
|
||||
|
||||
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
|
||||
//测试环境不上传数据
|
||||
if (Init.t_Keyvalues.FirstOrDefault(x => x.key == "TestMode").value == "0")
|
||||
{
|
||||
screwReportTimer.Start();
|
||||
if ("ScrewE,Assy2,Assy3,ScrewS,ScrewM,ScrewTC".ToLower().Contains(Init.t_Line.lineremark2.ToLower()))
|
||||
{
|
||||
screwReportTimer.Start();
|
||||
}
|
||||
fileUploadTimer.Start();
|
||||
}
|
||||
//fileUploadTimer.Start();
|
||||
|
||||
#endregion
|
||||
|
||||
#region 初始化COM口服务
|
||||
@ -1127,7 +1137,7 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
catch { /* 忽略异常 */ }
|
||||
}
|
||||
Init.threadHelps.Clear();
|
||||
Init.threadHelps.Clear();
|
||||
}
|
||||
|
||||
// 安全关闭串口
|
||||
@ -1658,95 +1668,92 @@ namespace WindowsFormsApp1
|
||||
//气密接收
|
||||
public void AirtightPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
||||
{
|
||||
// 使用异步方法处理串口数据
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
if (!Init.AirtightPort.IsOpen)
|
||||
{
|
||||
if (!Init.AirtightPort.IsOpen)
|
||||
Init.AirtightPort?.Open();
|
||||
}
|
||||
// 读取串口接收到的数据
|
||||
// 读取串口接收到的数据
|
||||
var dataBuilder = new StringBuilder();
|
||||
while (Init.AirtightPort.BytesToRead > 0)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
dataBuilder.Append(Init.AirtightPort.ReadExisting());
|
||||
}
|
||||
var ReturnValue = dataBuilder.ToString();
|
||||
//LogExecute.logNet.WriteDebug($"通过气密仪获取到 {ReturnValue}");
|
||||
if (ReturnValue.Length < 30)
|
||||
{
|
||||
//后一台气密
|
||||
//<01>:(OK): 0.032 ml/min
|
||||
//LogExecute.logNet.WriteDebug(ReturnValue);
|
||||
Init.airtight.Leak_Value = ReturnValue.Substring(11, 5);
|
||||
Init.airtight.LastTime = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index1 = 1;
|
||||
int index2 = 1;
|
||||
string press = string.Empty;
|
||||
string leakage = string.Empty;
|
||||
//pressure选择为yes// export选择为yes(非常重要)
|
||||
var dataArray = ReturnValue.Trim('\r', '\n').Split('\t');
|
||||
float[] sealFloat = new float[2];
|
||||
|
||||
//充气压力
|
||||
if (dataArray[3] == "")
|
||||
{
|
||||
Init.AirtightPort?.Open();
|
||||
}
|
||||
// 读取串口接收到的数据
|
||||
// 读取串口接收到的数据
|
||||
var dataBuilder = new StringBuilder();
|
||||
while (Init.AirtightPort.BytesToRead > 0)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
dataBuilder.Append(Init.AirtightPort.ReadExisting());
|
||||
}
|
||||
var ReturnValue = dataBuilder.ToString();
|
||||
//LogExecute.logNet.WriteDebug($"通过气密仪获取到 {ReturnValue}");
|
||||
if (ReturnValue.Length < 30)
|
||||
{
|
||||
//后一台气密
|
||||
//<01>:(OK): 0.032 ml/min
|
||||
Init.airtight.Leak_Value = ReturnValue.Substring(11, 5);
|
||||
Init.airtight.LastTime = DateTime.Now;
|
||||
sealFloat[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index1 = 1;
|
||||
int index2 = 1;
|
||||
string press = string.Empty;
|
||||
string leakage = string.Empty;
|
||||
//pressure选择为yes// export选择为yes(非常重要)
|
||||
var dataArray = ReturnValue.Trim('\r', '\n').Split('\t');
|
||||
float[] sealFloat = new float[2];
|
||||
|
||||
//充气压力
|
||||
if (dataArray[3] == "")
|
||||
if (dataArray[3].Contains("-"))
|
||||
{
|
||||
sealFloat[0] = 0;
|
||||
press = dataArray[3].Remove(0, 1);
|
||||
index1 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dataArray[3].Contains("-"))
|
||||
{
|
||||
press = dataArray[3].Remove(0, 1);
|
||||
index1 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
press = dataArray[3];
|
||||
index1 = 1;
|
||||
}
|
||||
sealFloat[0] = float.Parse(press);
|
||||
press = dataArray[3];
|
||||
index1 = 1;
|
||||
}
|
||||
|
||||
//测试泄露结果
|
||||
if (dataArray[5] == "")
|
||||
sealFloat[1] = 0;
|
||||
else
|
||||
{
|
||||
if (dataArray[5].Contains("-"))
|
||||
{
|
||||
leakage = dataArray[5].Remove(0, 1);
|
||||
index2 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
leakage = dataArray[5];
|
||||
index2 = 1;
|
||||
}
|
||||
sealFloat[1] = float.Parse(leakage);
|
||||
}
|
||||
|
||||
int[] sealInt = new int[2];
|
||||
sealInt[0] = Convert.ToInt32(sealFloat[1] * 1000) * (index2);
|
||||
sealInt[1] = Convert.ToInt32(sealFloat[0] * 1000) * (index1);
|
||||
Init.airtight.Airtight_Value = sealInt[0].ToString();
|
||||
Init.airtight.Leak_Value = sealInt[1].ToString();
|
||||
Init.airtight.LastTime = DateTime.Now;
|
||||
sealFloat[0] = float.Parse(press);
|
||||
}
|
||||
CsvLogger.Log($"{Init.airtight.Airtight_Value},{Init.airtight.Leak_Value}");
|
||||
LogExecute.SNlogNet.WriteDebug($"通过气密仪获取到 压力值:{Init.airtight.Airtight_Value},泄露值:{Init.airtight.Leak_Value}");
|
||||
|
||||
//测试泄露结果
|
||||
if (dataArray[5] == "")
|
||||
sealFloat[1] = 0;
|
||||
else
|
||||
{
|
||||
if (dataArray[5].Contains("-"))
|
||||
{
|
||||
leakage = dataArray[5].Remove(0, 1);
|
||||
index2 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
leakage = dataArray[5];
|
||||
index2 = 1;
|
||||
}
|
||||
sealFloat[1] = float.Parse(leakage);
|
||||
}
|
||||
|
||||
int[] sealInt = new int[2];
|
||||
sealInt[0] = Convert.ToInt32(sealFloat[1] * 1000) * (index2);
|
||||
sealInt[1] = Convert.ToInt32(sealFloat[0] * 1000) * (index1);
|
||||
Init.airtight.Airtight_Value = sealInt[0].ToString();
|
||||
Init.airtight.Leak_Value = sealInt[1].ToString();
|
||||
Init.airtight.LastTime = DateTime.Now;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"通过气密仪获取到压力参数失败,错误原因{ex.Message}");
|
||||
}
|
||||
});
|
||||
CsvLogger.Log($"{Init.airtight.Airtight_Value},{Init.airtight.Leak_Value}");
|
||||
LogExecute.SNlogNet.WriteDebug($"通过气密仪获取到 压力值:{Init.airtight.Airtight_Value},泄露值:{Init.airtight.Leak_Value}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogExecute.logNet.WriteError($"通过气密仪获取到压力参数失败,错误原因{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 在初始化组件的方法中添加按钮
|
||||
@ -1857,7 +1864,7 @@ namespace WindowsFormsApp1
|
||||
{
|
||||
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
|
||||
var material_sqlresult = sQLiteHelper_upload
|
||||
.Query(x => x.datacollectionUploaded == 1 && !string.IsNullOrEmpty(x.sn));
|
||||
.Query(x => x.datacollectionUploaded == 1 && x.sn != "");
|
||||
if (material_sqlresult.Success)
|
||||
{
|
||||
ApiClient apiClient = new ApiClient();
|
||||
@ -1877,6 +1884,11 @@ namespace WindowsFormsApp1
|
||||
sQLiteHelper_upload.Update(material);
|
||||
LogExecute.logNet.WriteDebug($"{material.sn} 扭力上报成功!");
|
||||
}
|
||||
else if (result.Mesresult == mesresult.NONE)
|
||||
{
|
||||
material.datacollectionUploaded = 3;
|
||||
sQLiteHelper_upload.Update(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1886,9 +1898,12 @@ namespace WindowsFormsApp1
|
||||
|
||||
private void FileUploadTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
//LogExecute.logNet.WriteDebug($"定时器文件执行!");
|
||||
SQLiteHelper<t_materialupload> sQLiteHelper_upload = new db.SQLiteHelper<t_materialupload>();
|
||||
var material_sqlresult = sQLiteHelper_upload
|
||||
.Query(x => (x.imageUploaded == 1) && x.sn != "");
|
||||
.Query(x => (x.imageUploaded == 1 || x.vedioUploaded == 1)
|
||||
&& x.sn != ""
|
||||
&& x.sn != "TEST MODE testsn");
|
||||
if (material_sqlresult.Success)
|
||||
{
|
||||
ApiClient apiClient = new ApiClient();
|
||||
@ -1914,6 +1929,14 @@ namespace WindowsFormsApp1
|
||||
material.vedioUploaded = 2;
|
||||
sQLiteHelper_upload.Update(material);
|
||||
LogExecute.logNet.WriteDebug($"{material.sn} 文件上传成功!");
|
||||
}else if (result.Mesresult == mesresult.NONE)
|
||||
{
|
||||
//标记该物料已上传
|
||||
if (material.imageUploaded == 1)
|
||||
material.imageUploaded = 3;
|
||||
if (material.vedioUploaded == 1)
|
||||
material.vedioUploaded = 3;
|
||||
sQLiteHelper_upload.Update(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1984,7 +2007,7 @@ namespace WindowsFormsApp1
|
||||
{
|
||||
SiemensHelp siemensHelp = Plc.plchelp;
|
||||
List<t_plcaddress> plcaddress = Init.t_Plcaddresses.FindAll(a => a.plcid == Plc.id
|
||||
&& a.code.Contains("Heartbeat"));
|
||||
&& a.code.Contains("Heartbeat") || a.code == "NowDateTime");
|
||||
|
||||
plcdata PlcData = new plcdata();
|
||||
|
||||
@ -1996,6 +2019,7 @@ namespace WindowsFormsApp1
|
||||
|
||||
//写入心跳
|
||||
PlcData.Write_Heartbeat = PlcData.Write_Heartbeat == 0 ? (short)1 : (short)0;
|
||||
PlcData.NowDateTime = DateTime.Now.AddSeconds(3);
|
||||
//LogExecute.logNet.WriteDebug($"{Plc.plcname}:{Plc.plcip}写入心跳{PlcData.Write_Heartbeat}!");
|
||||
var haertresult = siemensHelp.WriteAddress(plcaddress, PlcData);
|
||||
if (!haertresult.Success)
|
||||
|
||||
@ -187,5 +187,6 @@ namespace WindowsFormsApp1.mod.server
|
||||
/// 写入PLC的时间
|
||||
/// </summary>
|
||||
public DateTime Write_Time2 { get; set; }
|
||||
public DateTime NowDateTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -590,7 +590,7 @@ namespace WindowsFormsApp1.server
|
||||
}
|
||||
if(request.DC_INFO.Count == 0)
|
||||
{
|
||||
return ApiFormResult.Sucess(mesresult.FAIL, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
|
||||
return ApiFormResult.Sucess(mesresult.NONE, false, "请求马头服务器获取数据失败", PlcData, DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,8 +642,19 @@ namespace WindowsFormsApp1.server
|
||||
public ApiFormResult SN_FileUpload(string url, plcdata PlcData, otherdata OtherData)
|
||||
{
|
||||
// 准备文件 视频/图片 目的路径拼接
|
||||
var month = OtherData.material.date.Substring(0,6);
|
||||
var day = OtherData.material.date.Substring(6, 2);
|
||||
var month = "";
|
||||
var day = "";
|
||||
if (OtherData.material.imageUploaded == 1)
|
||||
{
|
||||
month = OtherData.material.date.Substring(0, 6);
|
||||
day =OtherData.material.date.Substring(6, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
var monthList = OtherData.material.date.Split('-');
|
||||
month = $"{monthList[0]}{monthList[1]}";
|
||||
day = monthList[2];
|
||||
}
|
||||
var monthDay = DateTime.Now.ToString("MMdd");
|
||||
var time = DateTime.Now.ToString("HHmmss");
|
||||
var result = OtherData.material.result;
|
||||
@ -696,7 +707,7 @@ namespace WindowsFormsApp1.server
|
||||
else
|
||||
{
|
||||
// 视频
|
||||
sourceFolder = Path.Combine(OtherData.VedioAddress, DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
sourceFolder = Path.Combine(OtherData.VedioAddress, OtherData.material.date);
|
||||
}
|
||||
if (Directory.Exists(sourceFolder.Trim()))
|
||||
{
|
||||
@ -730,7 +741,7 @@ namespace WindowsFormsApp1.server
|
||||
{
|
||||
//标记sn的回传状态,以免下次定时器还能查到这种
|
||||
LogExecute.logNet.WriteDebug($"在所有源文件夹中未找到包含SN号 {snNumber} 的文件");
|
||||
return ApiFormResult.Error(mesresult.FAIL, false, "", PlcData, DateTime.Now);
|
||||
return ApiFormResult.Sucess(mesresult.NONE, false, "", PlcData, DateTime.Now);
|
||||
}
|
||||
|
||||
// 组装 request json
|
||||
@ -891,25 +902,28 @@ namespace WindowsFormsApp1.server
|
||||
TorqueCount++;
|
||||
}
|
||||
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
if (!_isTestMode)
|
||||
{
|
||||
material = new t_materialupload
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
CarrierID = PlcData.Read_MaterialCode1,
|
||||
datacollectionUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.datacollectionUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
material = new t_materialupload
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
CarrierID = PlcData.Read_MaterialCode1,
|
||||
datacollectionUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.datacollectionUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1036,53 +1050,59 @@ namespace WindowsFormsApp1.server
|
||||
sninfo.CompList.Add(compListItem);
|
||||
}
|
||||
|
||||
//图片上传
|
||||
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
|
||||
if (!_isTestMode)
|
||||
{
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
//图片上传 Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5
|
||||
if ("Assy1,Assy4,Assy6,ThermalPaste,Sealant,CCD,AOI,Assy5".Contains(stationid))
|
||||
{
|
||||
material = new t_materialupload
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
imageUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyyMMdd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
material = new t_materialupload
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
imageUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyyMMdd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.imageUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
material.imageUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
}
|
||||
}
|
||||
|
||||
//视频上传
|
||||
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
|
||||
{
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
//视频上传 WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel
|
||||
if ("WAT,Assy2,Assy3,ScrewS,Assy5,LoadAging,PrintLabel".Contains(stationid))
|
||||
{
|
||||
material = new t_materialupload
|
||||
SQLiteHelper<t_materialupload> materialuploadHelper = new db.SQLiteHelper<t_materialupload>();
|
||||
var material = materialuploadHelper.QuerySingle(x => x.sn == PlcData.Write_stSN).Data;
|
||||
if (material == null)
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
vedioUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.vedioUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
material = new t_materialupload
|
||||
{
|
||||
sn = PlcData.Write_stSN,
|
||||
vedioUploaded = 1,
|
||||
result = logresult,
|
||||
date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
outtime = DateTime.Now
|
||||
};
|
||||
materialuploadHelper.Insert(material);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.vedioUploaded = 1;
|
||||
materialuploadHelper.Update(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//调用OEEDataCollection
|
||||
//CallFunctionByName("OEEDataCollection", PlcData, OtherData);
|
||||
return CallApi(url, request, "SN_Checkout", PlcData, PLC_Status.SN_Checkout);
|
||||
}
|
||||
|
||||
@ -1148,7 +1168,7 @@ namespace WindowsFormsApp1.server
|
||||
}
|
||||
}
|
||||
|
||||
return CallApi(url, request, "OEEDataCollection", PlcData, PLC_Status.OEEDataCollection);
|
||||
return CallApi(url, request, "OEEDataCollection", PlcData, 0);
|
||||
}
|
||||
|
||||
#region 暂时不用
|
||||
|
||||
@ -280,6 +280,10 @@ namespace WindowsFormsApp1.server
|
||||
.ToArray());
|
||||
break;
|
||||
|
||||
case "dtl":
|
||||
address[i].value = GetDTLTime(read.Content, index).ToString();
|
||||
break;
|
||||
|
||||
default:
|
||||
return BllResult.Error("找不到未知的数据类型");
|
||||
}
|
||||
@ -359,6 +363,12 @@ namespace WindowsFormsApp1.server
|
||||
stringBytes.CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
case "dtl":
|
||||
DateTime totime = Convert.ToDateTime(value);
|
||||
byte[] totime_byte = GetBytesFromDTLTime(totime);
|
||||
totime_byte.CopyTo(writebyte, index);
|
||||
break;
|
||||
|
||||
default:
|
||||
return BllResult.Error("找不到未知的数据类型");
|
||||
}
|
||||
@ -803,5 +813,40 @@ namespace WindowsFormsApp1.server
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
public byte[] GetBytesFromDTLTime(DateTime dateTime)
|
||||
{
|
||||
byte[] array = new byte[12];
|
||||
ByteTransform.TransByte((short)dateTime.Year).CopyTo(array, 0);
|
||||
array[2] = (byte)dateTime.Month;
|
||||
array[3] = (byte)dateTime.Day;
|
||||
array[4] = 5;
|
||||
array[5] = (byte)dateTime.Hour;
|
||||
array[6] = (byte)dateTime.Minute;
|
||||
array[7] = (byte)dateTime.Second;
|
||||
ByteTransform.TransByte(dateTime.Millisecond * 1000 * 1000).CopyTo(array, 8);
|
||||
return array;
|
||||
}
|
||||
|
||||
public DateTime GetDTLTime(byte[] buffer, int index)
|
||||
{
|
||||
int year = (int)ByteTransform.TransInt16(buffer, index);
|
||||
int month = (int)buffer[index + 2];
|
||||
int day = (int)buffer[index + 3];
|
||||
int hour = (int)buffer[index + 5];
|
||||
int minute = (int)buffer[index + 6];
|
||||
int second = (int)buffer[index + 7];
|
||||
int millisecond = ByteTransform.TransInt32(buffer, index + 8) / 1000 / 1000;
|
||||
if (year == 0 && month == 0 && day == 0)
|
||||
{
|
||||
year = 1900;
|
||||
month = 1;
|
||||
day = 1;
|
||||
}
|
||||
return new DateTime(year, month, day, hour, minute, second, millisecond);
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user