新增MES接口存库

master
CaesarBao 5 months ago
parent 0dec20413c
commit fcc3882b60

@ -12,10 +12,7 @@
<add key="SqlString" value="Persist Security Info=True;Password=haiwei@123;User ID=sa;Initial Catalog=XJMIDDBTOMES;Data Source=119.45.202.115;Connection Timeout=5" />
<add key="UpdateUrl" value="ftp://118.24.158.141" />
<!--定时删除日志时间间隔(单位:月)-->
<add key="DeleteLogIntervel" value="2" />
<!--webapi端口号-->
<add key="ApiPort" value="6001" />
<add key="DeleteLogIntervel" value="2" />
<!--是否启用光电信号回执功能(1:启用0:停用)-->
<add key="IsIOSendData" value="1" />

@ -63,9 +63,6 @@
this.columnHeader19 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader20 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader21 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader22 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader23 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader24 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label_Version = new System.Windows.Forms.Label();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
@ -120,8 +117,8 @@
// v20230913ToolStripMenuItem
//
this.v20230913ToolStripMenuItem.Name = "v20230913ToolStripMenuItem";
this.v20230913ToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
this.v20230913ToolStripMenuItem.Text = "V20230920";
this.v20230913ToolStripMenuItem.Size = new System.Drawing.Size(148, 34);
this.v20230913ToolStripMenuItem.Text = "V2.0";
//
// panel1
//
@ -149,7 +146,7 @@
//
this.splitContainer1.Panel2.Controls.Add(this.groupBox3);
this.splitContainer1.Size = new System.Drawing.Size(1425, 945);
this.splitContainer1.SplitterDistance = 293;
this.splitContainer1.SplitterDistance = 292;
this.splitContainer1.SplitterWidth = 6;
this.splitContainer1.TabIndex = 0;
//
@ -167,7 +164,7 @@
// splitContainer2.Panel2
//
this.splitContainer2.Panel2.Controls.Add(this.groupBox2);
this.splitContainer2.Size = new System.Drawing.Size(1425, 293);
this.splitContainer2.Size = new System.Drawing.Size(1425, 292);
this.splitContainer2.SplitterDistance = 271;
this.splitContainer2.SplitterWidth = 6;
this.splitContainer2.TabIndex = 0;
@ -180,7 +177,7 @@
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Size = new System.Drawing.Size(271, 293);
this.groupBox1.Size = new System.Drawing.Size(271, 292);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "MES软件";
@ -198,7 +195,7 @@
this.adapter_list.Location = new System.Drawing.Point(4, 26);
this.adapter_list.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.adapter_list.Name = "adapter_list";
this.adapter_list.Size = new System.Drawing.Size(263, 262);
this.adapter_list.Size = new System.Drawing.Size(263, 261);
this.adapter_list.TabIndex = 0;
this.adapter_list.UseCompatibleStateImageBehavior = false;
this.adapter_list.View = System.Windows.Forms.View.Details;
@ -239,7 +236,7 @@
this.groupBox2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox2.Size = new System.Drawing.Size(1148, 293);
this.groupBox2.Size = new System.Drawing.Size(1148, 292);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "设备信息";
@ -259,7 +256,7 @@
this.equip_list.Location = new System.Drawing.Point(4, 26);
this.equip_list.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.equip_list.Name = "equip_list";
this.equip_list.Size = new System.Drawing.Size(1140, 262);
this.equip_list.Size = new System.Drawing.Size(1140, 261);
this.equip_list.TabIndex = 1;
this.equip_list.UseCompatibleStateImageBehavior = false;
this.equip_list.View = System.Windows.Forms.View.Details;
@ -267,13 +264,13 @@
// columnHeader6
//
this.columnHeader6.Text = "编号";
this.columnHeader6.Width = 78;
this.columnHeader6.Width = 50;
//
// columnHeader7
//
this.columnHeader7.Text = "名称";
this.columnHeader7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader7.Width = 95;
this.columnHeader7.Width = 120;
//
// columnHeader8
//
@ -309,7 +306,7 @@
this.groupBox3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox3.Size = new System.Drawing.Size(1425, 646);
this.groupBox3.Size = new System.Drawing.Size(1425, 647);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "传感器信息";
@ -324,16 +321,13 @@
this.columnHeader15,
this.columnHeader19,
this.columnHeader20,
this.columnHeader21,
this.columnHeader22,
this.columnHeader23,
this.columnHeader24});
this.columnHeader21});
this.sensor_list.Dock = System.Windows.Forms.DockStyle.Fill;
this.sensor_list.HideSelection = false;
this.sensor_list.Location = new System.Drawing.Point(4, 26);
this.sensor_list.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.sensor_list.Name = "sensor_list";
this.sensor_list.Size = new System.Drawing.Size(1417, 615);
this.sensor_list.Size = new System.Drawing.Size(1417, 616);
this.sensor_list.TabIndex = 1;
this.sensor_list.UseCompatibleStateImageBehavior = false;
this.sensor_list.View = System.Windows.Forms.View.Details;
@ -341,11 +335,13 @@
// columnHeader11
//
this.columnHeader11.Text = "编号";
this.columnHeader11.Width = 80;
//
// columnHeader12
//
this.columnHeader12.Text = "名称";
this.columnHeader12.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader12.Width = 120;
//
// columnHeader13
//
@ -381,23 +377,6 @@
this.columnHeader21.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader21.Width = 100;
//
// columnHeader22
//
this.columnHeader22.Text = "多组上传";
this.columnHeader22.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader22.Width = 70;
//
// columnHeader23
//
this.columnHeader23.Text = "超时时间(ms)";
this.columnHeader23.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader23.Width = 100;
//
// columnHeader24
//
this.columnHeader24.Text = "立即返回";
this.columnHeader24.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// timer1
//
this.timer1.Enabled = true;
@ -516,9 +495,6 @@
private System.Windows.Forms.ColumnHeader columnHeader19;
private System.Windows.Forms.ColumnHeader columnHeader20;
private System.Windows.Forms.ColumnHeader columnHeader21;
private System.Windows.Forms.ColumnHeader columnHeader22;
private System.Windows.Forms.ColumnHeader columnHeader23;
private System.Windows.Forms.ColumnHeader columnHeader24;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label_Version;
private System.Windows.Forms.NotifyIcon notifyIcon1;

@ -6,6 +6,7 @@ using Highway.Assemble.Sql;
using Highway.Assemble.SqlSugar.serviceImpl;
using Highway.SocketServer;
using HighWayAssemble.Protocol;
using Mesnac.DeviceAdapter;
using RRQMCore.XREF.Newtonsoft.Json.Serialization;
using RRQMSocket;
using System;
@ -20,6 +21,7 @@ using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Rpc;
using TouchSocket.Sockets;
using static System.Net.Mime.MediaTypeNames;
using IPHost = TouchSocket.Sockets.IPHost;
using SocketClient = TouchSocket.Sockets.SocketClient;
@ -62,79 +64,97 @@ namespace HighWayAssemble
/// </summary>
void Init()
{
SoftInfo = App.Make<ISoftInfo>();
SoftInfo.CollectInfo = new Collect();
// configInfo = App.Make<IConfigInfo>();
m_BoxDB = App.Make<IBoxDB>();
GetConfiginfo();
Sql = App.Make<ISql>(SoftInfo.CollectInfo.sqlstring);
GetSoftInfo();
m_EquipClient = App.Make<IEquipClient>();
//创建webapi
var t = Task.Run(async delegate
try
{
await Task.Delay(10);
CreateTcp();
MesHttpClient = new MesHttpClient();
MesHttpClient.init();
var service = new HttpService();
await service.SetupAsync(new TouchSocketConfig()
.SetListenIPHosts(int.Parse(System.Configuration.ConfigurationManager.AppSettings["ApiPort"]))
.ConfigureContainer(a =>
{
a.AddConsoleLogger();
a.AddRpcStore(store =>
{
store.RegisterServer<ApiServer>();//注册服务
});
})
.ConfigurePlugins(a =>
{
a.UseCheckClear();
a.UseWebApi()
.ConfigureConverter(converter =>
{
converter.AddJsonSerializerFormatter(new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None });
});
//此插件是http的兜底插件应该最后添加。作用是当所有路由不匹配时返回404.且内部也会处理Option请求。可以更好的处理来自浏览器的跨域探测。
a.UseDefaultHttpServicePlugin();
}
));
await service.StartAsync();
await m_service.StartAsync();//启动
//CreatSocketServer();
SoftInfo = App.Make<ISoftInfo>();
SoftInfo.CollectInfo = new Collect();
// configInfo = App.Make<IConfigInfo>();
m_BoxDB = App.Make<IBoxDB>();
GetConfiginfo();
Sql = App.Make<ISql>(SoftInfo.CollectInfo.sqlstring);
GetSoftInfo();
m_EquipClient = App.Make<IEquipClient>();
InitEquipClient();
if (IsOPCFlag == 1)
{
LoadOPCInfo();
}
FrmDisplayView.LogInfo.Info("创建SockteSvr成功");
});
Task.Run(async delegate
{
while (true)
{//每十分钟将软件状态插入数据库
Sql.InsertCollectState(SoftInfo.CollectInfo.collectID, 1);
await Task.Delay(1000 * 60 * 10);
}
});
//创建webapi
if (SoftInfo.mode == Mode.Triangle)
{
var t = Task.Run(async delegate
{
await Task.Delay(10);
CreateTcp();
MesHttpClient = new MesHttpClient();
MesHttpClient.init();
var service = new HttpService();
await service.SetupAsync(new TouchSocketConfig()
.SetListenIPHosts(SoftInfo.CollectInfo.Port)
.ConfigureContainer(a =>
{
////添加跨域服务
//a.AddCors(corsOption =>
//{
// //添加跨域策略后续使用policyName即可应用跨域策略。
// corsOption.Add("cors", corsBuilder =>
// {
// corsBuilder.AllowAnyMethod()
// .AllowAnyOrigin();
// });
//});
a.AddConsoleLogger();
a.AddRpcStore(store =>
{
store.RegisterServer<ApiServer>();//注册服务
});
})
.ConfigurePlugins(a =>
{
a.UseWebApi()
.ConfigureConverter(converter =>
{
converter.AddJsonSerializerFormatter(new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None });
});
//此插件是http的兜底插件应该最后添加。作用是当所有路由不匹配时返回404.且内部也会处理Option请求。可以更好的处理来自浏览器的跨域探测。
a.UseDefaultHttpServicePlugin();
}
));
await service.StartAsync();
await m_service.StartAsync();//启动
//CreatSocketServer();
if (IsOPCFlag == 1)
{
LoadOPCInfo();
}
FrmDisplayView.LogInfo.Info("创建SockteSvr成功");
});
Task.Run(async delegate
{
await Task.Delay(1000);
//SendHeard();
while (true)
{//每十分钟将软件状态插入数据库
Sql.InsertCollectState(SoftInfo.CollectInfo.collectID, 1);
await Task.Delay(1000 * 60 * 10);
}
});
//Thread th = new Thread(SendHeard);
//th.Start();
//if (SoftInfo.mode == Mode.Triangle)
//{
// Task.Run(async delegate
// {
// await Task.Delay(1000);
// //SendHeard();
// });
// //Thread th = new Thread(SendHeard);
// //th.Start();
//}
//DealProcessReceive();
DeleteLogFile();
}
//DealProcessReceive();
DeleteLogFile();
catch (Exception ex)
{
}
}
private Object obj = new object();
@ -316,23 +336,23 @@ namespace HighWayAssemble
for (int i = 0; i < state.Count; i++)
{
//add by 2024-08-26 OPC新增设备断线后写入空格
if (state[i].m_ConnectState == 2)
{
if (state[i].m_iDeviceId == 30101)
{
string strTag1 = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RFIDMessage.Value", 1);
opc.WriteTag(strTag1, "NoRead");
string strTag2 = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RealStack.Value", 1);
opc.WriteTag(strTag2, "NoRead");
}
if (state[i].m_iDeviceId == 30102)
{
string strTag = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RFIDMessage.Value", 2);
opc.WriteTag(strTag, "NoRead");
string strTag2 = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RealStack.Value", 2);
opc.WriteTag(strTag2, "NoRead");
}
}
//if (state[i].m_ConnectState == 2)
//{
// if (state[i].m_iDeviceId == 30101)
// {
// string strTag1 = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RFIDMessage.Value", 1);
// opc.WriteTag(strTag1, "NoRead");
// string strTag2 = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RealStack.Value", 1);
// opc.WriteTag(strTag2, "NoRead");
// }
// if (state[i].m_iDeviceId == 30102)
// {
// string strTag = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RFIDMessage.Value", 2);
// opc.WriteTag(strTag, "NoRead");
// string strTag2 = string.Format(@"\\172.18.19.21\HMMLZD.No{0}_IntoStack_RealStack.Value", 2);
// opc.WriteTag(strTag2, "NoRead");
// }
//}
//Sql.InsertEquipState(state[i].m_iDeviceId.ToString(), state[i].m_ConnectState);
await InsertDeviceState(state[i].m_iDeviceId, state[i].m_ConnectState);
}
@ -381,13 +401,16 @@ namespace HighWayAssemble
}
else
{
//data = data.Where((x, i) => data.FindIndex(z => z.EPCstring == x.EPCstring) == i).ToList();
if (data != null && data.Any())
{
info = string.Join(",", data.Select(item => item.EPCstring));
}
else
{
info = string.Empty; // 处理空集合的情况
info = "NoData"; // 处理空集合的情况
}
//dataInfo = data;
// dataInfo = Encoding.ASCII.GetBytes(MsgUtil.bytesToHexStr(data, data.Length));//dataInfo = data;
@ -410,7 +433,7 @@ namespace HighWayAssemble
//FrmDisplayView.LogInfo.Info(string.Format("发送MES主动读取到的数据 MES地址:{0},消息内容:{1} --{2}", addr, MsgUtil.bytesToHexStr(sendbuf, sendbuf.Length), token == null ? "MES断开" : ""));
//2022-11-17 添加注释等待时间10s
//Sql.InsertReadData(id.ToString(), info, 0);
//await InsertRealWorkData(id.ToString(), info, 0);
await InsertRealWorkData(id.ToString(), info, 0);
}
});
@ -439,13 +462,15 @@ namespace HighWayAssemble
}
else
{
//data = data.Where((x, i) => data.FindIndex(z => z.EPCstring == x.EPCstring) == i).ToList();
if (data != null && data.Any())
{
info = string.Join(",", data.Select(item => item.EPCstring));
}
else
{
info = string.Empty; // 处理空集合的情况
info = "NoData"; // 处理空集合的情况
}
//dataInfo = data;// dataInfo = Encoding.ASCII.GetBytes(MsgUtil.bytesToHexStr(data, data.Length));//dataInfo = data;
//info = MsgUtil.bytesToHexStr(data, data.Length);
@ -473,10 +498,10 @@ namespace HighWayAssemble
mesParaData.EPCID = info;
mesParaData.READSTATUS = info == "NoData" ? "1" : "0";
mesParaData.READTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//MesHttpClient.autoread(mesParaData);
MesHttpClient.autoread(mesParaData);
//await InsertRealWorkData(id.ToString(), info, 2);
await InsertRealWorkData(id.ToString(), info, 2);
});
//自报数据回调
@ -542,7 +567,7 @@ namespace HighWayAssemble
// await Task.Delay(1);
// m_EquipClient.Device_BeginIdentify(MsgUtil.ParseToInt(sensorInfo.CallCombineID));//设置读写器连续读
//});
Thread m_bgwWaitingForData = new Thread(() => m_EquipClient.Device_BeginIdentify(MsgUtil.ParseToInt(sensorInfo.CallCombineID)));
Thread m_bgwWaitingForData = new Thread(() => m_EquipClient.Device_BeginIdentify(sensorInfo.CallCombineID));
m_bgwWaitingForData.IsBackground = true;
m_bgwWaitingForData.Start();
//m_EquipClient.Device_BeginIdentify(MsgUtil.ParseToInt(sensorInfo.CallCombineID));//设置读写器连续读
@ -685,6 +710,27 @@ namespace HighWayAssemble
return false;
}
}
public bool InsertRealMesData(string CombID, string data,string response, int type)
{
try
{
RealMesdata realWorkdata = new RealMesdata();
realWorkdata.Combineid = CombID.ToString();
realWorkdata.Data = data;
realWorkdata.Response = response;
realWorkdata.Reportmode = type;
realWorkdata.Tm = DateTime.Now;
realWorkdata.Edittime = DateTime.Now;
realWorkdata.Deleteflag = 0;
var MaterialTypeList = new BaseServices<RealMesdata>().Add1(realWorkdata);
return true;
}
catch (Exception ex)
{
FrmDisplayView.LogInfo.Fatal("插入数据失败" + ex.ToString());
return false;
}
}
/// <summary>
/// 获取汇集软件、适配软件、设备信息数据
/// </summary>
@ -1182,7 +1228,7 @@ namespace HighWayAssemble
}
else
{
await m_EquipClient.Device_MESBeginIdentify(num); //主动盘点
await m_EquipClient.Device_MESBeginIdentify(num.ToString()); //主动盘点
}
//Thread m_bgwWaitingForData = new Thread(() => m_EquipClient.Device_MESBeginIdentify(num));

@ -3,15 +3,18 @@ using Highway.Assemble.common;
using Highway.Assemble.Common;
using Highway.Assemble.EquipClient;
using Highway.Assemble.Sql;
using Highway.Assemble.SqlSugar.serviceImpl;
using log4net;
using Mesnac.DeviceAdapter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using TouchSocket.Rpc;
using TouchSocket.WebApi;
using static System.Windows.Forms.AxHost;
namespace HighWayAssemble.Protocol
{
@ -30,8 +33,9 @@ namespace HighWayAssemble.Protocol
/// </summary>
/// <param name="mesParaData"></param>
/// <returns></returns>
[Router("/[action]")]
[WebApi(Method = HttpMethodType.Post)]
public async Task<ApiResponse<MesParaData>> RFIDcontrol(MesParaData mesParaData)
public async Task<ApiResponse<MesParaData>> autoread()
{
return new ApiResponse<MesParaData>
@ -40,6 +44,7 @@ namespace HighWayAssemble.Protocol
Data = null,
Msg = "sucess",
};
}
/// <summary>
/// 查询设备信息
@ -56,6 +61,7 @@ namespace HighWayAssemble.Protocol
Data = rFIDDeviceInfos,
Msg = "sucess",
};
}
/// <summary>
@ -67,10 +73,14 @@ namespace HighWayAssemble.Protocol
[WebApi(Method = HttpMethodType.Post)]
public async Task<ApiResponse<MesReadRespon>> readAsync(MesReadPara mesReadPara)
{
FrmDisplayView.LogInfo.InfoFormat("接收MES主动读取指令{0},{1}",mesReadPara.EQUID ,mesReadPara.requesttime);
ApiResponse<MesReadRespon> response = new ApiResponse<MesReadRespon>();
int code = 400;
string Msg = "error";
FrmDisplayView.LogInfo.InfoFormat("接收MES主动读取指令{0}", JsonSerializer.Serialize(mesReadPara));
//FrmDisplayView.LogInfo.InfoFormat("接收MES主动读取指令{0},{1}",mesReadPara.EQUID ,mesReadPara.requesttime);
MesReadRespon mesReadRespon = new MesReadRespon();
List<TagInfo> rfid = null;
m_EquipClient.ReadRFID(Int32.Parse(mesReadPara.EQUID), out rfid);
List<TagInfo> rfid = m_EquipClient.ReadRFID(mesReadPara.EQUID);
if (rfid != null && rfid.Count > 0)
{
if (rfid.Count > 1)
@ -78,21 +88,37 @@ namespace HighWayAssemble.Protocol
if (rfid != null && rfid.Any())
{
mesReadRespon.EPCID = string.Join(",", rfid.Select(item => item.EPCstring));
Msg = "multiple EPC";
}
}
else
{
mesReadRespon.EPCID = rfid[0].EPCstring;
code = 200;
Msg = "sucess";
}
mesReadRespon.Respontime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
return new ApiResponse<MesReadRespon>
else
{
Code = 200,
Msg = "nodata";
}
response = new ApiResponse<MesReadRespon>()
{
Code = code,
Data = mesReadRespon,
Msg = "sucess",
Msg = Msg,
};
FrmDisplayView.LogInfo.InfoFormat("发送MES主动读取指令{0}", JsonSerializer.Serialize(response));
InsertRealMesData(mesReadPara.EQUID.ToString(), JsonSerializer.Serialize(mesReadPara), JsonSerializer.Serialize(response), 0);
return response;
//return new ApiResponse<MesReadRespon>
//{
// Code = code,
// Data = mesReadRespon,
// Msg = Msg,
//};
}
@ -104,16 +130,65 @@ namespace HighWayAssemble.Protocol
/// <returns></returns>
[WebApi(Method = HttpMethodType.Post)]
public async Task<ApiResponse<MesParaData>> revresult(MesAlarmLightPara mesAlarmLightPara)
{
FrmDisplayView.LogInfo.InfoFormat("接收MES控制报警灯指令{0},{1}", mesAlarmLightPara.EQUID, mesAlarmLightPara.Sendtime);
{
ApiResponse<MesParaData> response = new ApiResponse<MesParaData>();
m_EquipClient.WriteAlarmLight(Int32.Parse(mesAlarmLightPara.EQUID), mesAlarmLightPara.Code);
return new ApiResponse<MesParaData>
FrmDisplayView.LogInfo.InfoFormat("接收MES控制报警灯指令{0}", JsonSerializer.Serialize(mesAlarmLightPara));
//FrmDisplayView.LogInfo.InfoFormat("接收MES控制报警灯指令{0},{1},{2}", mesAlarmLightPara.EQUID, mesAlarmLightPara.Sendtime, mesAlarmLightPara.Code);
if (mesAlarmLightPara.Code == "0")
{
mesAlarmLightPara.Code = "2";
}
else if (mesAlarmLightPara.Code == "1")
{
mesAlarmLightPara.Code = "3";
}
else
{
mesAlarmLightPara.Code = "1";
}
m_EquipClient.WriteAlarmLight(mesAlarmLightPara.EQUID, mesAlarmLightPara.Code);
response = new ApiResponse<MesParaData>()
{
Code = 200,
Data = null,
Msg = "sucess",
};
FrmDisplayView.LogInfo.InfoFormat("发送MES控制报警灯指令{0}", JsonSerializer.Serialize(response));
InsertRealMesData(mesAlarmLightPara.EQUID.ToString(), JsonSerializer.Serialize(mesAlarmLightPara), JsonSerializer.Serialize(response), 1);
return response;
//return new ApiResponse<MesParaData>
//{
// Code = 200,
// Data = null,
// Msg = "sucess",
//};
}
public bool InsertRealMesData(string CombID, string data, string response, int type)
{
try
{
RealMesdata realWorkdata = new RealMesdata();
realWorkdata.Combineid = CombID.ToString();
realWorkdata.Data = data;
realWorkdata.Response = response;
realWorkdata.Reportmode = type;
realWorkdata.Tm = DateTime.Now;
realWorkdata.Edittime = DateTime.Now;
realWorkdata.Deleteflag = 0;
var MaterialTypeList = new BaseServices<RealMesdata>().Add1(realWorkdata);
return true;
}
catch (Exception ex)
{
FrmDisplayView.LogInfo.Fatal("插入数据失败" + ex.ToString());
return false;
}
}
}
}

@ -35,7 +35,8 @@ namespace HighWayAssemble.Protocol
{
_MeshttpClient = new WebApiClient();
await _MeshttpClient.SetupAsync(new TouchSocketConfig()
.SetRemoteIPHost("127.0.0.1:6001")
.SetRemoteIPHost("172.16.0.106:9880")
//.SetRemoteIPHost("127.0.0.1:9880")
.ConfigurePlugins(a =>
{
@ -55,8 +56,8 @@ namespace HighWayAssemble.Protocol
var requestForPost = new WebApiRequest();
requestForPost.Method = HttpMethodType.Post;
requestForPost.Body = new MesParaData() { EQUID = mesParaData.EQUID, EPCID = mesParaData.EPCID, READSTATUS = mesParaData.READSTATUS, ERRORMSG = mesParaData.ERRORMSG, READTIME = mesParaData.READTIME };
JToken responseValue = _MeshttpClient.InvokeT<JToken>("/ApiServer/RFIDcontrol", null, requestForPost);
FrmDisplayView.LogInfo.Info(JsonSerializer.Serialize(requestForPost.Body));
JToken responseValue = _MeshttpClient.InvokeT<JToken>("/autoread", null, requestForPost);
return MsgUtil.JTokenToEntity<ApiResponse<MesParaData>>(responseValue);
}

@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Adapter.cs" />
<Compile Include="RealMesdata.cs" />
<Compile Include="RFIDDeviceApiResponse.cs" />
<Compile Include="ApiResponse.cs" />
<Compile Include="Collect.cs" />

@ -5,6 +5,6 @@
public string IPAddress { get; set; }
public string EQUID { get; set; }
public string position { get; set; }
public string ApiPort { get; set; }
}
}

@ -0,0 +1,44 @@
using SqlSugar;
using System;
namespace Highway.Assemble.common
{
/// <summary>
///
///</summary>
[SugarTable("real_mesdata")]
public class RealMesdata
{
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "combineid")]
public string Combineid { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "tm")]
public DateTime? Tm { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "data")]
public string Data { get; set; }
[SugarColumn(ColumnName = "response")]
public string Response { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "reportmode")]
public decimal? Reportmode { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "edittime")]
public DateTime? Edittime { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "deleteflag")]
public int? Deleteflag { get; set; }
}
}

@ -112,6 +112,8 @@ namespace Highway.Assemble.common
/// </summary>
public int Readinterval;
public string FilterData;
public System.Threading.Timer m_Timer = null; //根据读取时间间隔设置的定时器
}
}

@ -63,7 +63,7 @@ namespace Mesnac.DeviceAdapterNet
public class AntInfo
{
public int m_iCombineId;
public string m_iCombineId;
/// <summary>
/// 是否超高频读头
/// </summary>

@ -5,6 +5,7 @@ using Mesnac.DeviceAdapterNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
@ -18,9 +19,9 @@ namespace Highway.Assemble.EquipClient
public Action<List<DeviceInfo>> EquipStateAction;
public Action<int, List<TagInfo>> ReadDataAction;
public Action<string, List<TagInfo>> ReadDataAction;
public Action<int, List<TagInfo>> RecSendDataAction;
public Action<string, List<TagInfo>> RecSendDataAction;
public Action<int, int, int> RecGetDataAction;
@ -61,7 +62,7 @@ namespace Highway.Assemble.EquipClient
for (int i = 0; i < m_SensorInfoList.Count; i++)
{
AntInfo a = new AntInfo();
a.m_iCombineId = Convert.ToInt32(m_SensorInfoList[i].combineid);
a.m_iCombineId = m_SensorInfoList[i].combineid;
AntList[i] = a;
}
}
@ -213,7 +214,7 @@ namespace Highway.Assemble.EquipClient
item.m_ConnectState = 1;
break;
case 2:
item.m_ConnectState = 2;
item.m_ConnectState = 0;
item.m_IDeviceAdapter.Device_Destroy();
break;
default:
@ -249,11 +250,11 @@ namespace Highway.Assemble.EquipClient
/// <param name="sensorType"></param>
private void RecvIdentifyDataToMES_Instance(ushort iLen, byte[] pData, byte Antenna, ushort iDeviceId, string strId, string sensorType)
{
uint iCombineId = 0u;
string iCombineId = "";
try
{
iCombineId = GetCombineIdByDeviceIdAndSer(Antenna, iDeviceId, sensorType);
if (iCombineId != 0)
if (iCombineId != "")
{
if (iLen > 0)
{
@ -267,14 +268,14 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("------------------------------------------------------------------------------------------------------");
LogInfo.Info("MES主动读取合并编号[" + iCombineId + "]的第[" + Antenna + "]号传感器自报数据NoData");
LogInfo.Info("------------------------------------------------------------------------------------------------------");
ReadDataAction?.Invoke(Convert.ToInt32(iCombineId), null);
//ReadDataAction?.Invoke(Convert.ToInt32(iCombineId), null);
}
}
}
catch (Exception ex)
{
LogInfo.Info("RecvIdentifyDataToMES_Instance:" + ex.ToString());
ReadDataAction?.Invoke(Convert.ToInt32(iCombineId), null);
//ReadDataAction?.Invoke(Convert.ToInt32(iCombineId), null);
}
}
@ -285,20 +286,40 @@ namespace Highway.Assemble.EquipClient
/// <param name="iDeviceId">设备编号</param>
/// <param name="sensorType">传感器类型</param>
/// <returns></returns>
private uint GetCombineIdByDeviceIdAndSer(byte iSensorSer, ushort iDeviceId, string sensorType)
private string GetCombineIdByDeviceIdAndSer(byte iSensorSer, ushort iDeviceId, string sensorType)
{
uint iCombineId = 0u;
string iCombineId = "";
for (int i = 0; i < m_SensorInfoList.Count; i++)
{
if (iSensorSer == Convert.ToUInt16(m_SensorInfoList[i].sensorser) && iDeviceId == Convert.ToUInt16(m_SensorInfoList[i].deviceId) && sensorType == m_SensorInfoList[i].sensortypeid)
{
iCombineId = Convert.ToUInt32(m_SensorInfoList[i].combineid);
iCombineId = m_SensorInfoList[i].combineid;
break;
}
}
return iCombineId;
}
private string GetFilterDataByDeviceIdAndSer(byte iSensorSer, UInt16 iDeviceId)
{
string FilterData = "";
for (int i = 0; i < m_SensorInfoList.Count; i++)
{
if ((iSensorSer == Convert.ToUInt16(m_SensorInfoList[i].sensorser)) && (iDeviceId == Convert.ToUInt16(m_SensorInfoList[i].deviceId)))
{
FilterData = m_SensorInfoList[i].FilterData;
break;
}
}
return FilterData;
}
private static List<TagInfo> FilterByEPCString(List<TagInfo> tagList, string searchText)
{
return tagList
.Where(tag => tag.EPCstring != null && tag.EPCstring.Contains(searchText))
.ToList();
}
/// <summary>
/// 监听自动上报后数据返回事件
/// </summary>
@ -310,11 +331,13 @@ namespace Highway.Assemble.EquipClient
/// <param name="sensorType">传感器类型</param>
public void RecvIdentifyData_Instance(ushort iLen, List<TagInfo> tagInfos, byte Antenna, ushort iDeviceId, string strId, string sensorType)
{
uint iCombineId = 0u;
string iCombineId = "";
string FilterData = "";
try
{
iCombineId = GetCombineIdByDeviceIdAndSer(Antenna, iDeviceId, sensorType);
if (iCombineId == 0)
FilterData = GetFilterDataByDeviceIdAndSer(Antenna, iDeviceId);
if (iCombineId == "")
{
return;
}
@ -329,8 +352,9 @@ namespace Highway.Assemble.EquipClient
// return;
//}
LogInfo.Info("------------------------------------------------------------------------------------------------------");
//LogInfo.Info("读写器自报合并编号[" + iCombineId + "]的第[" + Antenna + "]号传感器,自报数据:" + Encoding.ASCII.GetString(pData, 0, pData.Length) + ",原始数据:" + bytesToHexStr(pData, pData.Length));
LogInfo.Info("读写器自报合并编号[" + iCombineId + "]的第[" + Antenna + "]号传感器,过滤规则[" + FilterData + "],自报数据:" + string.Join(",", tagInfos.Select(item => item.EPCstring)));
LogInfo.Info("------------------------------------------------------------------------------------------------------");
tagInfos = tagInfos.Where((x, i) => tagInfos.FindIndex(z => z.EPCstring == x.EPCstring) == i).ToList();
AntInfo[] antList = AntList;
foreach (AntInfo item in antList)
{
@ -339,7 +363,11 @@ namespace Highway.Assemble.EquipClient
item.IsReading = false;
item.ReadData = new byte[tagInfos[0].EPC.Length];
Array.Copy(tagInfos[0].EPC, 0, item.ReadData, 0, tagInfos[0].EPC.Length);
RecSendDataAction?.Invoke(Convert.ToInt32(iCombineId), tagInfos);
if (!string.IsNullOrEmpty(FilterData))
{
tagInfos = FilterByEPCString(tagInfos, FilterData);
}
RecSendDataAction?.Invoke(iCombineId, tagInfos);
}
}
}
@ -348,7 +376,7 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("------------------------------------------------------------------------------------------------------");
LogInfo.Info("自报合并编号[" + iCombineId + "]的第[" + Antenna + "]号传感器自报数据NoData");
LogInfo.Info("------------------------------------------------------------------------------------------------------");
RecSendDataAction?.Invoke(Convert.ToInt32(iCombineId), null);
RecSendDataAction?.Invoke(iCombineId, null);
}
}
catch (Exception ex)
@ -356,7 +384,7 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("空间名:" + ex.Source + "\n方法名" + ex.TargetSite?.ToString() + "\n故障点" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + "\n错误提示" + ex.Message);
if (iLen == 0)
{
RecAutoDataAction?.Invoke(Convert.ToInt32(iCombineId), null);
RecSendDataAction?.Invoke(iCombineId, null);
}
}
}
@ -394,7 +422,7 @@ namespace Highway.Assemble.EquipClient
try
{
LogInfo.Info("接收到MES主动读取数据命令合并编号" + num);
pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
//pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
pSensorInfo = GetSensorInfoByCombineId(Convert.ToUInt32(num));
if (pDeviceInfo.m_IDeviceAdapter != null)
{
@ -410,19 +438,19 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("------------------------------------------------------------------------------------------------------");
LogInfo.Info("MES主动读取数据成功合并编号[" + num + "],读取数据:NoData");
LogInfo.Info("------------------------------------------------------------------------------------------------------");
ReadDataAction?.Invoke(num, null);
//ReadDataAction?.Invoke(num, null);
}
}
else
{
LogInfo.Info("MES主动读取失败合并编号" + num);
ReadDataAction?.Invoke(num, null);
//ReadDataAction?.Invoke(num, null);
}
}
catch (Exception ex)
{
LogInfo.Info("MES主动读取异常:" + ex.ToString());
ReadDataAction?.Invoke(num, null);
//ReadDataAction?.Invoke(num, null);
}
}
@ -448,12 +476,12 @@ namespace Highway.Assemble.EquipClient
/// </summary>
/// <param name="iCombineId">传感器编号</param>
/// <returns>设备信息</returns>
private DeviceInfo GetIDeviceInfoByCombineId(uint iCombineId)
private DeviceInfo GetIDeviceInfoByCombineId(string iCombineId)
{
DeviceInfo pDeviceInfo = null;
for (int i = 0; i < m_SensorInfoList.Count; i++)
{
if (iCombineId == Convert.ToUInt32(m_SensorInfoList[i].combineid))
if (iCombineId == m_SensorInfoList[i].combineid)
{
pDeviceInfo = GetDeviceInfoByDeviceId(Convert.ToUInt16(m_SensorInfoList[i].deviceId));
if (pDeviceInfo != null)
@ -525,7 +553,7 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("方法WriteData接收合并编号[" + num + "]的第[" + Antenna + "]路IO打开报警灯闪亮命令");
break;
}
pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
//pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
pSensorInfo = GetSensorInfoByCombineId(Convert.ToUInt32(num));
try
{
@ -558,7 +586,7 @@ namespace Highway.Assemble.EquipClient
byte[] array = null;
try
{
LogInfo.Info("合并编号:" + id + ",识别单次标签命令自报");
//LogInfo.Info("合并编号:" + id + ",识别单次标签命令自报");
//array = GetOneEpcByCombineId(Convert.ToUInt32(id));
if (array != null)
{
@ -572,35 +600,42 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("------------------------------------------------------------------------------------------------------");
LogInfo.Info("识别单次标签成功,合并编号[" + id + "]读取标签数据NoData");
LogInfo.Info("------------------------------------------------------------------------------------------------------");
ReadDataAction?.Invoke(id, null);
//ReadDataAction?.Invoke(id, null);
}
}
catch (Exception ex)
{
LogInfo.Info("Deal_IdentifyOneEpc异常:" + ex.ToString());
ReadDataAction?.Invoke(id, null);
//ReadDataAction?.Invoke(id, null);
}
});
}
public void ReadRFID(int id,out List<TagInfo> rfiddata)
public List<TagInfo> ReadRFID(string id)
{
List<TagInfo> tags = new List<TagInfo>();
byte[] array = null;
rfiddata = null;
string FilterData = "";
try
{
LogInfo.Info("合并编号:" + id + ",识别单次标签命令自报");
tags = GetOneEpcByCombineId(Convert.ToUInt32(id));
//LogInfo.Info("合并编号:" + id + ",识别单次标签命令自报");
FilterData = m_SensorInfoList.Find(x=>x.combineid == id).FilterData;
tags = GetOneEpcByCombineId(id);
if (tags != null)
{
//LogInfo.Info("-------------------------------------------------------------------------------------------------------------");
//LogInfo.Info("识别单次标签成功,合并编号[" + id + "],读取标签数据:" + Encoding.ASCII.GetString(array, 0, array.Length) + ",原始数据:" + bytesToHexStr(array, array.Length));
//LogInfo.Info("-------------------------------------------------------------------------------------------------------------");
//rfiddata = Encoding.ASCII.GetString(array, 0, array.Length);
rfiddata = tags;
//有过滤
LogInfo.Info("-------------------------------------------------------------------------------------------------------------");
LogInfo.Info("识别单次标签成功,合并编号[" + id + "],过滤规则[" + FilterData +"],读取标签数据:" + string.Join(",", tags.Select(item => item.EPCstring)));
LogInfo.Info("-------------------------------------------------------------------------------------------------------------");
tags = tags.Where((x, i) => tags.FindIndex(z => z.EPCstring == x.EPCstring) == i).ToList();
//新增工位过滤
if (!string.IsNullOrEmpty(FilterData))
{
tags = FilterByEPCString(tags, FilterData);
}
ReadDataAction?.Invoke(id, tags);
return tags;
}
else
@ -609,12 +644,14 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("识别单次标签成功,合并编号[" + id + "]读取标签数据NoData");
LogInfo.Info("------------------------------------------------------------------------------------------------------");
ReadDataAction?.Invoke(id, null);
return tags;
}
}
catch (Exception ex)
{
LogInfo.Info("Deal_IdentifyOneEpc异常:" + ex.ToString());
LogInfo.Info("异常:" + ex.ToString());
ReadDataAction?.Invoke(id, null);
return tags;
}
}
@ -624,24 +661,31 @@ namespace Highway.Assemble.EquipClient
/// </summary>
/// <param name="iCombineId">传感器编号</param>
/// <returns>原始数据</returns>
private List<TagInfo> GetOneEpcByCombineId(uint iCombineId)
private List<TagInfo> GetOneEpcByCombineId(string iCombineId)
{
List<TagInfo> tagInfos = null;
byte[] pReturnResult = null;
IDeviceAdapter pDeviceAdapter = null;
byte iEpcLen = 0;
for (int i = 0; i < m_SensorInfoList.Count; i++)
{
if (iCombineId != Convert.ToUInt32(m_SensorInfoList[i].combineid))
if (iCombineId != m_SensorInfoList[i].combineid)
{
continue;
}
pDeviceAdapter = GetDeviceAdapterByDeviceId(Convert.ToUInt16(m_SensorInfoList[i].deviceId));
if (pDeviceAdapter != null)
{
tagInfos = pDeviceAdapter.Device_GetAllIdentifyData(Convert.ToByte(m_SensorInfoList[i].sensorser), Convert.ToUInt16(m_SensorInfoList[i].DelayTime), 1);
if (string.IsNullOrEmpty(m_SensorInfoList[i].readInterval))
{
m_SensorInfoList[i].readInterval = "1000";
}
tagInfos = pDeviceAdapter.Device_GetAllIdentifyData(Convert.ToByte(m_SensorInfoList[i].sensorser), Convert.ToUInt16(m_SensorInfoList[i].readInterval), 1);
if (tagInfos.Count > 0)
{
//新增工位过滤
//if (!string.IsNullOrEmpty(m_SensorInfoList[i].FilterData))
//{
// tagInfos = FilterByEPCString(tagInfos, m_SensorInfoList[i].FilterData);
//}
return tagInfos;
}
return null;
@ -683,12 +727,12 @@ namespace Highway.Assemble.EquipClient
RecGetDataAction = action;
}
public void RecSendData(Action<int, List<TagInfo>> action)
public void RecSendData(Action<string, List<TagInfo>> action)
{
RecSendDataAction = action;
}
public void RetReadData(Action<int, List<TagInfo>> action)
public void RetReadData(Action<string, List<TagInfo>> action)
{
ReadDataAction = action;
}
@ -706,7 +750,7 @@ namespace Highway.Assemble.EquipClient
/// 根据传感器合并编号处理数据
/// </summary>
/// <param name="num">传感器合并编号</param>
private void Deal_Data(int num)
private void Deal_Data(string num)
{
AntInfo[] antList = AntList;
foreach (AntInfo item in antList)
@ -737,12 +781,12 @@ namespace Highway.Assemble.EquipClient
/// 开始连续盘点
/// </summary>
/// <param name="num">传感器合并编号</param>
public void Device_BeginIdentify(int num)
public void Device_BeginIdentify(string num)
{
bool bResult = false;
DeviceInfo pDeviceInfo = null;
Sensor pSensorInfo = null;
pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
//pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
pSensorInfo = GetSensorInfoByCombineId(Convert.ToUInt32(num));
AntInfo[] antList = AntList;
foreach (AntInfo item in antList)
@ -762,13 +806,13 @@ namespace Highway.Assemble.EquipClient
{
if (pDeviceInfo.m_IDeviceAdapter != null)
{
bResult = pDeviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(pSensorInfo.sensorser), Convert.ToInt32(pSensorInfo.timeout), AutoRead: true, num);
//bResult = pDeviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(pSensorInfo.sensorser), Convert.ToInt32(pSensorInfo.timeout), AutoRead: true, num);
if (!bResult)
{
bResult = pDeviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(pSensorInfo.sensorser), Convert.ToInt32(pSensorInfo.timeout), AutoRead: true, num);
//bResult = pDeviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(pSensorInfo.sensorser), Convert.ToInt32(pSensorInfo.timeout), AutoRead: true, num);
if (!bResult)
{
bResult = pDeviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(pSensorInfo.sensorser), Convert.ToInt32(pSensorInfo.timeout), AutoRead: true, num);
//bResult = pDeviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(pSensorInfo.sensorser), Convert.ToInt32(pSensorInfo.timeout), AutoRead: true, num);
}
}
Thread.Sleep(1);
@ -782,7 +826,7 @@ namespace Highway.Assemble.EquipClient
{
item2.IsReading = false;
item2.readType = 0;
DealNoData(num, v: true);
//DealNoData(num, v: true);
item2.ReadData = null;
}
}
@ -815,12 +859,12 @@ namespace Highway.Assemble.EquipClient
if (v)
{
LogInfo.Info("》》》触发读取时间超时返回Nodata合并编号" + num);
RecSendDataAction?.Invoke(Convert.ToInt32(num), null);
//RecSendDataAction?.Invoke(Convert.ToInt32(num), null);
}
else
{
LogInfo.Info("》》》MES主动读取时间超时返回Nodata合并编号" + num);
ReadDataAction?.Invoke(Convert.ToInt32(num), null);
//ReadDataAction?.Invoke(Convert.ToInt32(num), null);
}
Device_StopIdentify(num);
if (!Device_StopIdentify(num))
@ -842,7 +886,7 @@ namespace Highway.Assemble.EquipClient
bool bResult = false;
DeviceInfo pDeviceInfo = null;
Sensor pSensorInfo = null;
pDeviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
//pDeviceInfo = GetIDeviceInfoByCombineId(num);
pSensorInfo = GetSensorInfoByCombineId(Convert.ToUInt32(num));
LogInfo.Info("合并编号:" + num + ",发送停止连续读取标签命令自报");
try
@ -871,14 +915,14 @@ namespace Highway.Assemble.EquipClient
/// </summary>
/// <param name="num">传感器合并编号</param>
/// <returns></returns>
public async Task Device_MESBeginIdentify(int num)
public async Task Device_MESBeginIdentify(string num)
{
await Task.Run(delegate
{
bool flag = false;
DeviceInfo deviceInfo = null;
Sensor sensor = null;
deviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
deviceInfo = GetIDeviceInfoByCombineId(num);
sensor = GetSensorInfoByCombineId(Convert.ToUInt32(num));
LogInfo.Info("合并编号:" + num + ",MES主动发送连续读取标签命令");
AntInfo[] antList = AntList;
@ -899,7 +943,7 @@ namespace Highway.Assemble.EquipClient
{
if (deviceInfo.m_IDeviceAdapter != null)
{
flag = deviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(sensor.sensorser), Convert.ToInt32(sensor.timeout), AutoRead: false, num);
//flag = deviceInfo.m_IDeviceAdapter.Device_BeginIdentify(Convert.ToByte(sensor.sensorser), Convert.ToInt32(sensor.timeout), AutoRead: false, num);
AntInfo[] antList2 = AntList;
foreach (AntInfo item in antList2)
{
@ -909,7 +953,7 @@ namespace Highway.Assemble.EquipClient
}).Wait(Convert.ToInt32(sensor.timeout)))
{
item.IsReading = false;
DealNoData(num, v: false);
//DealNoData(num, v: false);
item.ReadData = null;
}
}
@ -951,25 +995,25 @@ namespace Highway.Assemble.EquipClient
LogInfo.Info("------------------------------------------------------------------------------------------------------");
LogInfo.Info("识别单次标签成功,合并编号[" + id + "]读取标签数据NoData");
LogInfo.Info("------------------------------------------------------------------------------------------------------");
ReadDataAction?.Invoke(id, null);
//ReadDataAction?.Invoke(id, null);
}
}
catch (Exception ex)
{
LogInfo.Info("Deal_IdentifyOneEpc异常:" + ex.ToString());
ReadDataAction?.Invoke(id, null);
//ReadDataAction?.Invoke(id, null);
}
return m_data;
}
public void WriteAlarmLight(int num,string code)
public void WriteAlarmLight(string num,string code)
{
bool flag = false;
try
{
DeviceInfo deviceInfo = null;
//Sensor sensor = null;
deviceInfo = GetIDeviceInfoByCombineId(Convert.ToUInt32(num));
deviceInfo = GetIDeviceInfoByCombineId(num);
//sensor = GetSensorInfoByCombineId(Convert.ToUInt32(num));
if (deviceInfo.m_IDeviceAdapter != null)
{

@ -19,9 +19,9 @@ namespace Highway.Assemble.EquipClient
Task ReadEPC(int id);
void ReadRFID(int id, out List<TagInfo> rfiddata);
List<TagInfo> ReadRFID(string id);
void RecSendData(Action<int, List<TagInfo>> action);
void RecSendData(Action<string, List<TagInfo>> action);
void RecAutoData(Action<int, byte[]> action);
@ -29,20 +29,20 @@ namespace Highway.Assemble.EquipClient
void ReadData(int num, byte filterMembank, ushort filterWordPtr, ushort filterWordCnt, byte[] filterData, byte Membank, ushort WordPtr, ushort WordCnt);
void RetReadData(Action<int, List<TagInfo>> action);
void RetReadData(Action<string, List<TagInfo>> action);
void WriteData(int num, byte filterMembank, ushort filterWordPtr, ushort filterWordCnt, byte[] filterData, byte Membank, ushort WordPtr, ushort WordCnt, byte[] pWriteData, byte Antenna);
void RecGetData(Action<int, int, int> action);
void Device_BeginIdentify(int num);
void Device_BeginIdentify(string num);
bool Device_StopIdentify(int num);
Task Device_MESBeginIdentify(int num);
Task Device_MESBeginIdentify(string num);
string ReadEPCData(int id);
void WriteAlarmLight(int num, string code);
void WriteAlarmLight(string num, string code);
}
}

@ -129,7 +129,7 @@ namespace Highway.Assemble.Sql
//sensorcode.CallAdapter = Convert.ToInt16(row["calladapter"]);
//sensorcode.CallAdapterid = row["calladapterid"].ToString().Trim();
//sensorcode.CallCombineID = row["callcombineid"].ToString().Trim();
// sensorcode.DelayTime = TryToInt(row["DelayTime"].ToString());
sensorcode.FilterData = row["mapid"].ToString().Trim();
sensorcode.mesID = row["MesID"].ToString().Trim();
sensorcode.DelayTime = TryToInt(row["DelayTime"].ToString().Trim());
sensorcode.ReadCounts = TryToInt(row["ReadCounts"].ToString().Trim());
@ -422,7 +422,7 @@ namespace Highway.Assemble.Sql
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;//adapterid ="+mesID+"
dbHelper.CommandText = "";
string sql = "select t1.connectstr, t2.sensorid,t1.addr from base_device_info t1 left join [dbo].[base_sensor_info] t2 on t1.deviceid = t2.deviceid where t1.deleteflag != 1";
string sql = "select t1.connectstr, t2.combineid,t1.addr,t3.port from base_device_info t1 left join [dbo].[base_sensor_info] t2 on t1.deviceid = t2.deviceid left join [dbo].[base_collect_info] t3 on t1.collectid = t3.collectId where t1.deleteflag != 1";
dbHelper.CommandText = sql;
DataTable dt = dbHelper.ToDataTable();
@ -432,10 +432,10 @@ namespace Highway.Assemble.Sql
for (int i = 0; i < dt.Rows.Count; i++)
{
RFIDDeviceInfo mes = new RFIDDeviceInfo();
mes.EQUID = dt.Rows[i]["sensorid"].ToString();
mes.EQUID = dt.Rows[i]["combineid"].ToString();
mes.IPAddress = dt.Rows[i]["connectstr"].ToString();
mes.position = dt.Rows[i]["addr"].ToString();
mes.ApiPort = dt.Rows[i]["port"].ToString();
mesList.Add(mes);
}

@ -38,6 +38,10 @@ namespace Highway.Assemble.Sql
/// <param name="state">设备状态</param>
bool InsertCollectState(string ID, int state);
/// <summary>
/// MES获取设备信息列表
/// </summary>
/// <returns></returns>
List<RFIDDeviceInfo> GetRFIDEquipList();
}

@ -7,8 +7,8 @@
<ProjectGuid>{59C06619-BED8-45D8-85CF-ED55D6516C65}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AUCMA.SCADA.SqlSugar</RootNamespace>
<AssemblyName>AUCMA.SCADA.SqlSugar</AssemblyName>
<RootNamespace>Highway.Assemble.SqlSugar</RootNamespace>
<AssemblyName>Highway.Assemble.SqlSugar</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>

@ -18,8 +18,8 @@ namespace Highway.Assemble.SqlSugar.serviceImpl
{
_dbBase = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "server = 119.45.202.115; uid = sa; pwd = haiwei@123; database = XJMIDDBTOMES",
//ConnectionString = "server = 127.0.0.1; uid = sa; pwd = 123456; database = WLDB",
//ConnectionString = "server = 119.45.202.115; uid = sa; pwd = haiwei@123; database = XJMIDDBTOMES",
ConnectionString = "server = 127.0.0.1; uid = sa; pwd = 123456; database = WLDB",
DbType = DbType.SqlServer,
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样我就不多解释了

@ -115,7 +115,7 @@ namespace Mesnac.DeviceAdapter.RFly_I160
}
catch (Exception ex)
{
LogInfo.Info("连接读写器异常:" + ex.Message);
LogInfo.Fatal("IP" + m_strIp + "端口号:" + m_iPort + "连接读写器异常:" + ex.Message);
return false;
}
return true;
@ -141,7 +141,8 @@ namespace Mesnac.DeviceAdapter.RFly_I160
}
else
{
LogInfo.Info("Device_Connect:连接失败");
//LogInfo.Info("设备初始化成功IP" + m_strIp + "端口号:" + m_iPort);
LogInfo.Fatal("IP" + m_strIp + "端口号: " + m_iPort + ",Device_Connect:连接失败");
return false;
}
}
@ -169,7 +170,7 @@ namespace Mesnac.DeviceAdapter.RFly_I160
public bool Device_ReConnect()
{
LogInfo.Info("Device_Connect 调用重连函数!");
LogInfo.Fatal("IP" + m_strIp + "端口号: " + m_iPort + ",Device_ReConnect:调用重连函数");
return Device_Connect();
}
#endregion
@ -309,14 +310,14 @@ namespace Mesnac.DeviceAdapter.RFly_I160
}
else //超时
{
LogInfo.Info("发送心跳报文超时。");
//LogInfo.Info("发送心跳报文超时。");
iResult = 2; //通讯连接器正常,读写器故障
};
}
else
{
//通讯连接器失败或网络故障
LogInfo.Info("发送心跳报文失败,通讯故障。");
//LogInfo.Info("发送心跳报文失败,通讯故障。");
iResult = 3;
}
}
@ -432,7 +433,7 @@ namespace Mesnac.DeviceAdapter.RFly_I160
}
else
{
LogInfo.Info("Device_GetOneIdentifyData长度不正确");
//LogInfo.Info("Device_GetOneIdentifyData长度不正确");
m_OneEpcDataLen = 0;
m_OneEpcAntenna = 254;
iResult = 0;
@ -445,7 +446,7 @@ namespace Mesnac.DeviceAdapter.RFly_I160
m_OneEpcDataLen = 0;
m_OneEpcAntenna = 254;
m_ReadDataSuccessful = false;
LogInfo.Info("Device_GetOneIdentifyData超时");
//LogInfo.Info("Device_GetOneIdentifyData超时");
}
}
else
@ -525,7 +526,7 @@ namespace Mesnac.DeviceAdapter.RFly_I160
}
else
{
LogInfo.Info("Device_GetOneIdentifyData长度不正确");
//LogInfo.Info("Device_GetOneIdentifyData长度不正确");
m_OneEpcDataLen = 0;
m_OneEpcAntenna = 254;
iResult = 0;

Loading…
Cancel
Save