|
|
|
|
@ -38,7 +38,12 @@ namespace ConsoleApp
|
|
|
|
|
private string _workAskAddress;
|
|
|
|
|
//PLC工作完成放行请求地址
|
|
|
|
|
private string _completeAskAddress;
|
|
|
|
|
|
|
|
|
|
//PLC产品码地址
|
|
|
|
|
private string _productBarcode;
|
|
|
|
|
//PLC支线码1地址
|
|
|
|
|
private string _semiBarcode1;
|
|
|
|
|
//PLC支线码2地址
|
|
|
|
|
private string _semiBarcode2;
|
|
|
|
|
|
|
|
|
|
public MainCentralControl(IHost host)
|
|
|
|
|
{
|
|
|
|
|
@ -68,11 +73,16 @@ namespace ConsoleApp
|
|
|
|
|
case "S130-1":
|
|
|
|
|
_plcHeartBeatAddress = "D7777";
|
|
|
|
|
_completeAskAddress = "D7703";
|
|
|
|
|
_productBarcode = "";
|
|
|
|
|
_semiBarcode1 = "D7701";
|
|
|
|
|
break;
|
|
|
|
|
case "S130-2":
|
|
|
|
|
_plcHeartBeatAddress = "D7777";
|
|
|
|
|
_workAskAddress = "";
|
|
|
|
|
_completeAskAddress = "";
|
|
|
|
|
_workAskAddress = "D7803";
|
|
|
|
|
_completeAskAddress = "D7804";
|
|
|
|
|
_productBarcode = "";
|
|
|
|
|
_semiBarcode1 = "D7801";
|
|
|
|
|
_semiBarcode2 = "D7802";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -117,12 +127,6 @@ namespace ConsoleApp
|
|
|
|
|
//根据转子码查询上工位是否合格
|
|
|
|
|
SelectStationQuality(Plc);
|
|
|
|
|
}
|
|
|
|
|
//读取PLC放行请求
|
|
|
|
|
if (Plc.readInt16ByAddress(_completeAskAddress) == 1)
|
|
|
|
|
{
|
|
|
|
|
Plc.writeInt16ByAddress(_completeAskAddress, 0);
|
|
|
|
|
//存盘
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -138,6 +142,27 @@ namespace ConsoleApp
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
private void BarCodeRelationShipBinding(PlcAbsractFactory Plc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//前盖码
|
|
|
|
|
byte[] _QGBarcode = Plc.readValueByAddress(_semiBarcode2, 20);
|
|
|
|
|
string QGBarCode = ByteTransform.TransString(_QGBarcode, 0, 20, Encoding.ASCII);
|
|
|
|
|
_logger.Info("前盖码:"+ QGBarCode);
|
|
|
|
|
|
|
|
|
|
//转子码
|
|
|
|
|
byte[] _ZZBarcode = Plc.readValueByAddress(_semiBarcode1, 20);
|
|
|
|
|
string ZZBarCode = ByteTransform.TransString(_ZZBarcode, 0, 20, Encoding.ASCII);
|
|
|
|
|
_logger.Info("转子码:" + QGBarCode);
|
|
|
|
|
//下发PLC
|
|
|
|
|
Plc.writeInt16ByAddress(_completeAskAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error($"BarCodeRelationShipBinding方法异常:" + ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断数据库表是否已存在条码数据,存在则更新,不存在则插入
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -148,7 +173,6 @@ namespace ConsoleApp
|
|
|
|
|
Datastation datastation = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SqlSugarClient.Queryable<Datastation>().Any(x => x.Partsns.Contains(ProductBarCode));
|
|
|
|
|
datastation = SqlSugarClient.Queryable<Datastation>().First(it => it.Partsns.Contains(ProductBarCode));
|
|
|
|
|
if (datastation != null)
|
|
|
|
|
{
|
|
|
|
|
@ -169,7 +193,7 @@ namespace ConsoleApp
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{ //主线码
|
|
|
|
|
byte[] SemBarCode = Plc.readValueByAddress("D7701", 20);
|
|
|
|
|
byte[] SemBarCode = Plc.readValueByAddress(_semiBarcode1, 20);
|
|
|
|
|
string barcode = ByteTransform.TransString(SemBarCode, 0, 20, Encoding.ASCII);
|
|
|
|
|
partsns partsns = new partsns();
|
|
|
|
|
partsns.sn.Add(barcode);
|
|
|
|
|
@ -285,22 +309,46 @@ namespace ConsoleApp
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
byte[] SemBarCode = Plc.readValueByAddress("D7701", 20);
|
|
|
|
|
byte[] SemBarCode = Plc.readValueByAddress(_semiBarcode1, 20);
|
|
|
|
|
string ZZBarCode = ByteTransform.TransString(SemBarCode, 0, 20, Encoding.ASCII);
|
|
|
|
|
_logger.Info("转子码:" + ZZBarCode);
|
|
|
|
|
Datastation datastation = IsExistData(ZZBarCode);
|
|
|
|
|
if (datastation != null)
|
|
|
|
|
{
|
|
|
|
|
if (datastation.Ng != 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("上工位不合格");
|
|
|
|
|
//下发PLC上工位不合格
|
|
|
|
|
Plc.writeInt16ByAddress("", 1);
|
|
|
|
|
Plc.writeInt16ByAddress(_completeAskAddress, 2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//存盘
|
|
|
|
|
//前盖码
|
|
|
|
|
byte[] _QGBarcode = Plc.readValueByAddress(_semiBarcode2, 20);
|
|
|
|
|
string QGBarCode = ByteTransform.TransString(_QGBarcode, 0, 20, Encoding.ASCII);
|
|
|
|
|
_logger.Info("前盖码:" + QGBarCode);
|
|
|
|
|
//根据前盖码查询Productid
|
|
|
|
|
SqlSugarClient.Queryable<Dipsn>().Any(x => x.Sn == QGBarCode);
|
|
|
|
|
var Dipsn = SqlSugarClient.Queryable<Dipsn>().First(it => it.Sn == QGBarCode);
|
|
|
|
|
if (Dipsn != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int id = SqlSugarClient.Insertable(datastation).ExecuteReturnIdentity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//下发PLC上工位合格
|
|
|
|
|
Plc.writeInt16ByAddress(_completeAskAddress, 1);
|
|
|
|
|
//BarCodeRelationShipBinding(Plc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//上工位无数据
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("上工位不合格");
|
|
|
|
|
//下发PLC上工位不合格
|
|
|
|
|
Plc.writeInt16ByAddress("", 1);
|
|
|
|
|
Plc.writeInt16ByAddress(_completeAskAddress, 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|