PLC时间对接
定时器测试 s7通讯加辅助方法 4.21 测试
This commit is contained in:
1 parent
76cd069435
commit
e8001a81bb
4 files changed
+238
-148
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user