123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958 |
- using ProjectBase.Data.BaseDAL;
- using ProjectBase.Data.Logs;
- using ProjectBase.Data.Redis;
- using ProjectBase.Util;
- using SIMDP.BLL;
- using SIMDP.Device;
- using SIMDP.Model;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- namespace SIMDP.Project
- {
- public class MXComponent_FEM02 : PlcMXComponent
- {
- #region 设备空间 寄存器定义&继承成员
- private static string ip1 = "";
- private static int port1 = 0;
- private static string ip2 = "";
- private static int port2 = 0;
- private void InitScannerParams()
- {
- bool res1 = BLLFactory<BlPlcInfo>.Instance.GetScannerParams("Cammer1", out ip1, out port1);
- bool res2 = BLLFactory<BlPlcInfo>.Instance.GetScannerParams("Cammer2", out ip2, out port2);
- if (!res1 || !res2)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("当前扫码相机未配置,无法通信", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- public static bool SkipHeadScan = false;
- public static bool SkipFEMScan = false;
- public MXComponent_FEM02()
- {
- InitScannerParams();//初始化相机参数;
- FormCurrentTask.manualForceMatchSuccess += new FormCurrentTask.delegateResetVertify2(ManualForceMatchSuccess);
- FormCurrentTask.manualForceReleaseEmpty += new FormCurrentTask.delegateResetVertify2(ManualForceReleaseEmpty);
- FormCurrentTask.manualForceWrite2Tighting += new FormCurrentTask.delegateResetVertify3(ManualForceWrite2Tighting);
- }
- public override void actionConnected()
- {
- //复位PLC写入PLC的信号
- Write("SRS数据传输异常信号", false);
- Write("读取FEM二维码成功", false);
- Write("读取FEM二维码失败", false);
- Write("读取车头纸二维码成功", false);
- Write("读取车头纸二维码失败", false);
- Write("拧紧工位数据写入成功", false);
- Write("VIN匹配失败信号", false);
- Write("读取拧紧结果完成", false);
- }
- private bool pcHeartBeat = false;
- public override void actionTimer()
- {
- try
- {
- pcHeartBeat = !pcHeartBeat;
- if (!Write("PC心跳", pcHeartBeat))
- {
- isConnect = false;
- return;
- }
- //SRS报警
- if (SysEnvironment.warn_AS400)
- {
- Write("SRS数据传输异常信号", true);
- SysEnvironment.warn_AS400 = false;
- }
- foreach (MXComponentDataPointInfo p in monitorPoints)
- {
- if (!Read(p, out object value))
- {
- isConnect = false;
- return;
- }
- if (!value.Equals(p.value))
- {
- p.value = value;
- if (p.proc != null)
- p.proc.Invoke(this, new object[] { value });
- }
- }
- redis.Publish(SysEnvironment.OpcDataChannel, "");
- }
- catch (Exception ex)
- {
- isConnect = false;
- LogHelper.log.Error($"actionTimer()异常,即将重连PLC: {ex.Message}");
- }
- }
- internal class ProductionData
- {
- internal List<string> keys = new List<string>();
- internal Dictionary<string, string> dict = new Dictionary<string, string>();
- internal MoProductData model = new MoProductData();
- internal ProductionData()
- {
- model.RuleId = BLLFactory<BLL.BlRule>.Instance.GetRuleIdByName("FEM");
- keys.Add("型号");
- keys.Add("颜色");
- keys.Add("VIN");
- keys.Add("FEM");
- keys.Add("VIN2");
- keys.Add("力矩1");
- keys.Add("角度1");
- keys.Add("状态1");
- keys.Add("力矩2");
- keys.Add("角度2");
- keys.Add("状态2");
- keys.Add("力矩3");
- keys.Add("角度3");
- keys.Add("状态3");
- keys.Add("力矩4");
- keys.Add("角度4");
- keys.Add("状态4");
- keys.Add("生产完成");
- foreach (var key in keys)
- {
- dict.Add(key, "");
- }
- }
- internal string Dict2String()
- {
- StringBuilder builder = new StringBuilder();
- foreach (var d in dict)
- {
- if (builder.Length > 0)
- builder.Append(",");
- builder.Append(d.Value);
- }
- return builder.ToString();
- }
- internal MoProductData toModel()
- {
- model.DataValue = this.Dict2String();
- return model;
- }
- internal void LoadData(MoProductData data)
- {
- model.DataId = data.DataId;
- model.DataValue = data.DataValue;
- model.RuleId = data.RuleId;
- model.RuleTime = data.RuleTime;
- model.Batchid = data.Batchid;
- string[] values = model.DataValue.Split(',');
- if (values.Length > keys.Count)
- return;
- for (int i = 0; i < keys.Count; i++)
- {
- dict[keys[i]] = values[i];
- }
- }
- }
- public static class SuperQueueScanner
- {
- internal static RedisHelper redis = new RedisHelper(0);
- internal static Queue<string> HeadScanQueue = new Queue<string>(HeadScanQueueLength);
- internal static Queue<string> FEMScanQueue = new Queue<string>(FEMScanQueueLength);
- //1:匹配成功 0:不匹配 -1:空车架 -2:匹配中(两车间隙、未扫完) -3 未连锁 不匹配
- internal static int Scanning_Match_Result { get; set; } = -3;
- internal static int HeadScanQueueLength { get; } = 1;
- internal static int FEMScanQueueLength { get; } = 1;
- internal static int HeadScanCount { get { return HeadScanQueue.Count; } }
- internal static int FEMScanCount { get { return FEMScanQueue.Count; } }
- internal static void ClrearQueue()
- {
- HeadScanQueue.Clear();
- FEMScanQueue.Clear();
- }
- internal static string HeadScanEnqueue(string forceEnqueue = "")
- {
- if (forceEnqueue == "")
- forceEnqueue = Scanner.CameraScanner(ip2, port2, 3).Trim();
- //压入扫码站
- HeadScanQueue.Enqueue(forceEnqueue);
- redis.Publish(SysEnvironment.redis_Scanning_HeadCode, forceEnqueue);
- SysEnvironment.Global_Scanning_HeadCode = forceEnqueue;
- //缓存容量限制
- string dequeue = "";
- while (HeadScanQueue.Count > HeadScanQueueLength)
- {
- dequeue = HeadScanQueue.Dequeue();
- }
- return forceEnqueue;
- }
- internal static string HeadScanDequeue()
- {
- string dequeueStr = "";
- try
- {
- dequeueStr = HeadScanQueue.Dequeue();
- }
- catch { }
- return dequeueStr;
- }
- internal static string FEMScanEnqueue(string forceEnqueue = "")
- {
- if (forceEnqueue == "")
- forceEnqueue = Scanner.CameraScanner(ip1, port1, 3).Trim();
- FEMScanQueue.Enqueue(forceEnqueue);
- redis.Publish(SysEnvironment.redis_Scanning_FEMCode, forceEnqueue);
- SysEnvironment.Global_Scanning_FEMCode = forceEnqueue;
- //缓存容量限制
- string dequeue = "";
- while (FEMScanQueue.Count > FEMScanQueueLength)
- {
- dequeue = FEMScanQueue.Dequeue();
- }
- return forceEnqueue;
- }
- internal static string FEMScanDequeue()
- {
- string dequeueStr = "";
- try
- {
- dequeueStr = FEMScanQueue.Dequeue();
- }
- catch { }
- return dequeueStr;
- }
- /// <summary>
- /// 如果生成了匹配结果(匹配结果不为-3),则返回true;
- /// </summary>
- /// <returns></returns>
- internal static bool GenMatchResult()
- {
- LogHelper.log.Info($"匹配逻辑开始,车头扫码SkipHeadScan = {SkipHeadScan},FEM扫码SkipFEMScan = {SkipFEMScan}");
- if (SkipHeadScan && SkipFEMScan)
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return false;
- }
- else if (SkipHeadScan && !SkipFEMScan)
- {
- if (FEMScanQueue.Count < 1)
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return false;
- }
- string str2 = FEMScanQueue.Dequeue();
- if (!SysEnvironment.CheckVINRule(str2))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- if (!string.Equals(str2, SysEnvironment.Global_Scanning_Pointer))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- }
- else if (!SkipHeadScan && SkipFEMScan)
- {
- if (HeadScanQueue.Count < 1)
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return false;
- }
- string str1 = HeadScanQueue.Dequeue();
- if (!SysEnvironment.CheckVINRule(str1))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- if (!string.Equals(str1, SysEnvironment.Global_Scanning_Pointer))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- }
- else
- {
- if (FEMScanQueue.Count < 1 && HeadScanQueue.Count < 1)
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return false;
- }
- else if (FEMScanQueue.Count < 1)
- {
- SuperQueueScanner.Scanning_Match_Result = -2;//匹配中
- return false;//此处要注意
- }
- else if (HeadScanQueue.Count < 1)
- {
- SuperQueueScanner.Scanning_Match_Result = -2;//匹配中
- return true;
- }
- string str1 = HeadScanQueue.Dequeue();
- string str2 = FEMScanQueue.Dequeue();
- if (!SysEnvironment.CheckVINRule(str1) || !SysEnvironment.CheckVINRule(str2))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- if (!string.Equals(str1, str2))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- if (!string.Equals(str1, SysEnvironment.Global_Scanning_Pointer))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return true;
- }
- }
- //匹配成功,写入数据库扫码结果
- SuperQueueScanner.Scanning_Match_Result = 1;
- StoreScanningResult();
- return true;
- }
- }
- private static void StoreScanningResult()
- {
- try
- {
- MoMtocData task = BLLFactory<BlMtocData>.Instance.FindPointerModel(SysEnvironment.Global_Scanning_Pointer);
- if (task == null)
- {
- //不用报警
- LogHelper.log.Error($"存储车号 {SysEnvironment.Global_Scanning_Pointer}扫码数据异常:找不到车号的MTOC数据 ");
- return;
- }
- ProductionData data = new ProductionData();
- data.dict["型号"] = task.Model.ToString();
- data.dict["颜色"] = task.Color.ToString();
- data.dict["VIN"] = task.Vin;
- data.dict["VIN2"] = task.Vin;
- data.dict["FEM"] = task.Vin;
- data.model.Batchid = task.Vin;
- data.model.RuleTime = DateTime.Now;
- BLLFactory<BlProductData>.Instance.Insert(data.toModel());
- LogHelper.log.Info($"存储车号 {SysEnvironment.Global_Scanning_Pointer}扫码数据成功");
- }
- catch (Exception ex)
- {
- //不用报警
- LogHelper.log.Error($"存储车号 {SysEnvironment.Global_Scanning_Pointer}扫码数据异常: {ex.Message} ");
- }
- }
- #endregion
- #region PLC信号响应函数
- public void 联机模式(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (signal)
- {
- // SysEnvironment.sign_OnlineMode = true;
- //221104 重新联机后,强制复位PLC请求和PC状态
- actionConnected();
- }
- else
- {
- // SysEnvironment.sign_OnlineMode = false;
- SuperQueueScanner.ClrearQueue();
- }
- }
- public void 连锁信号(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (signal)
- {
- //////连锁第一时间进行匹配并处理结果
- //if (SuperQueueScanner.GenMatchResult()) SysEnvironment.Global_ScannerBlock = true;
- //redis.Publish(SysEnvironment.redis_ScannerBlock, SysEnvironment.Global_ScannerBlock);
- //TackleMatchResult();
- }
- else
- {
- //切除时,清空写入过的车型
- List<MoMtocData> list = new List<MoMtocData>();
- MoMtocData model = new MoMtocData() { Vin = "", Model = 0, Color = 0, };
- for (int i = 0; i < 10; i++)
- {
- list.Add(model);
- }
- if (WriteFromD4001(list))
- {
- redis.Publish(SysEnvironment.redis_Tighting_Pointer, "");
- redis.Publish(SysEnvironment.redis_Tighting_Model, "");
- redis.Publish(SysEnvironment.redis_Tighting_Color, "");
- }
- }
- }
- /// <summary>
- /// 这个函数永远都在 刚刚给出匹配结果的时侯后调用
- /// </summary>
- private void TackleMatchResult()
- {
- redis.Publish(SysEnvironment.redis_ScanningMatchRes, SuperQueueScanner.Scanning_Match_Result);
- if (SuperQueueScanner.Scanning_Match_Result == 0)
- Write("VIN匹配失败信号", true);
- else if (SuperQueueScanner.Scanning_Match_Result == -2)
- Write("VIN匹配失败信号", true);
- else if (SuperQueueScanner.Scanning_Match_Result == -1)
- Write("VIN匹配失败信号", false);
- else if (SuperQueueScanner.Scanning_Match_Result == 1)
- Write("VIN匹配失败信号", false);
- Read("请求拧紧工位数据写入", out bool delayWrite);
- if (delayWrite) 请求拧紧工位数据写入(true);
- }
- public void 手自动模式切换(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- //if (signal)
- //{
- // // SysEnvironment.sign_AutoMode = true;
- //}
- //else
- //{
- // // SysEnvironment.sign_AutoMode = false;
- // redis.Publish(SysEnvironment.redis_Tighting_Pointer, "");
- // redis.Publish(SysEnvironment.redis_Tighting_Model, "");
- // redis.Publish(SysEnvironment.redis_Tighting_Color, "");
- //}
- }
- public void 预约停止状态切换(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- //if (signal)
- //{
- // SysEnvironment.sign_OrderStop = true;
- // LogHelper.log.Debug("预约停止状态已设置!");
- //}
- //else
- //{
- // SysEnvironment.sign_OrderStop = false;
- // LogHelper.log.Debug("预约停止状态已取消");
- //}
- }
- public void 扫描车头纸二维码请求(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("读取车头纸二维码成功", false);
- Write("读取车头纸二维码失败", false);
- return;
- }
- //if (SysEnvironment.Global_ScannerBlock) return;///没写入之前不扫新的
- string HeadBarcode = SuperQueueScanner.HeadScanEnqueue();
- LogHelper.log.Info($"触发车头纸扫码:{HeadBarcode}");
- Write("读取车头纸二维码成功", true);
- Read("连锁信号", out bool bChain);
- if (bChain)
- {
- if (SuperQueueScanner.GenMatchResult()) SysEnvironment.Global_ScannerBlock = true;
- redis.Publish(SysEnvironment.redis_ScannerBlock, SysEnvironment.Global_ScannerBlock);
- TackleMatchResult();
- }
- else
- {
- //切除状态下,扫码跳指针
- MoMtocData model2Scan = BLLFactory<BlMtocData>.Instance.FindPointerNextModel(SysEnvironment.Global_Scanning_Pointer);
- SysEnvironment.Global_Scanning_Pointer = model2Scan == null ? "" : model2Scan.Vin;
- redis.Publish(SysEnvironment.redis_Scanning_Pointer, SysEnvironment.Global_Scanning_Pointer);
- LogHelper.log.Info($"切除状态,强制跳指针到:{SysEnvironment.Global_Scanning_Pointer}");
- SuperQueueScanner.Scanning_Match_Result = -3;
- redis.Publish(SysEnvironment.redis_ScanningMatchRes, SuperQueueScanner.Scanning_Match_Result);
- }
- }
- public void 扫描FEM二维码请求(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("读取FEM二维码成功", false);
- Write("读取FEM二维码失败", false);
- return;
- }
- if (SysEnvironment.Global_ScannerBlock) return;///没写入之前不扫新的
- string FEMBarcode = SuperQueueScanner.FEMScanEnqueue();
- LogHelper.log.Info($"触发FEM扫码:{FEMBarcode}");
- Write("读取FEM二维码成功", true);
- Read("连锁信号", out bool bChain);//其实不连锁也不会触发扫码
- if (bChain)
- {
- if (SuperQueueScanner.GenMatchResult()) SysEnvironment.Global_ScannerBlock = true;
- redis.Publish(SysEnvironment.redis_ScannerBlock, SysEnvironment.Global_ScannerBlock);
- TackleMatchResult();
- }
- }
- public void ManualForceMatchSuccess()
- {
- SuperQueueScanner.Scanning_Match_Result = 1;
- TackleMatchResult();
- }
- public void ManualForceReleaseEmpty()
- {
- //SuperQueueScanner.Scanning_Match_Result = -1;
- //TackleMatchResult();
- }
- public void ManualForceWrite2Tighting(short model, short color, string vin)
- {
- if (WriteD4001(model, color, vin))
- {
- Write("拧紧工位数据写入成功", true);
- SysEnvironment.Global_ScannerBlock = false;
- redis.Publish(SysEnvironment.redis_ScannerBlock, SysEnvironment.Global_ScannerBlock);
- ///车型已写入,可以进入下一轮扫码,先扫车身的(因为不会阻塞)
- Read("扫描车头纸二维码请求", out bool bscanHead);
- if (bscanHead) 扫描车头纸二维码请求(true);
- Read("扫描FEM二维码请求", out bool bscanFEM);
- if (bscanFEM) 扫描FEM二维码请求(true);
- SysEnvironment.Global_Tighting_Pointer = vin;
- SysEnvironment.Global_Tighting_Model = model;
- SysEnvironment.Global_Tighting_Color = color;
- redis.Publish(SysEnvironment.redis_Tighting_Pointer, vin);
- redis.Publish(SysEnvironment.redis_Tighting_Model, model);
- redis.Publish(SysEnvironment.redis_Tighting_Color, color);
- }
- //保险复位一下
- Read("请求拧紧工位数据写入", out bool res);
- if (!res)
- {
- Write("拧紧工位数据写入成功", false);
- }
- }
- /// <summary>
- /// 主链发车,PLC要车型,此信号发出前,PC应保证匹配已经结束,如果未匹配完成则应将M1128持续置1
- /// 如果接收此信号时,匹配结果<1,将直接返回(设计上只有第一台车允许这样)。
- /// </summary>
- /// <param name="value"></param>
- public void 请求拧紧工位数据写入(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("拧紧工位数据写入成功", false);
- return;
- }
- //非连锁禁止触发
- Read("连锁信号", out bool bChain);
- if (!bChain) return;
- //清空拧紧工位所有的信息,包括 PLC PC UI
- SysEnvironment.Global_Tighting_Pointer = "";
- SysEnvironment.Global_Tighting_Model = 0;
- SysEnvironment.Global_Tighting_Color = 0;
- redis.Publish(SysEnvironment.redis_Tighting_Pointer, "");
- redis.Publish(SysEnvironment.redis_Tighting_Model, "");
- redis.Publish(SysEnvironment.redis_Tighting_Color, "");
- //只要PLC要数据,就先给置成0
- if (!WriteD4001(0, 0, "")) return;
- ////空车架/插车 -1
- //if (SuperQueueScanner.Scanning_Match_Result == -1)
- //{
- // ///此处UI更新不完善,但不再更改,因为后续弃用空车架逻辑
- // Write("拧紧工位数据写入成功", true);
- // bWritten = true;
- // redis.Publish(SysEnvironment.redis_Tighting_Pointer, "空车架/插车");
- // redis.Publish(SysEnvironment.redis_Tighting_Model, "0");
- // redis.Publish(SysEnvironment.redis_Tighting_Color, "0");
- // return;
- //}
- //匹配失败0、没匹配完-2 切除状态不匹配 -3
- else if (SuperQueueScanner.Scanning_Match_Result < 1)
- {
- ///设计上不允许出现的情况!!只有第一台车有这个可能
- LogHelper.log.Error($"非正常情况!发车时(M1118触发时),匹配结果为 {SuperQueueScanner.Scanning_Match_Result} !!");
- return;
- }
- // == 1 进入匹配成功逻辑
- LogHelper.log.Info($"进入匹配成功逻辑:当前指针 {SysEnvironment.Global_Scanning_Pointer}");
- List<MoMtocData> listMtoc = BLLFactory<BlMtocData>.Instance.FindFromThis(SysEnvironment.Global_Scanning_Pointer, 10);
- if (listMtoc == null || listMtoc.Count < 1)
- {
- LogHelper.log.Error($"找不到指针所指车型信息!!");
- return;
- }
- ///清空所有扫码工位信息
- SysEnvironment.Global_Scanning_HeadCode = "";
- SysEnvironment.Global_Scanning_FEMCode = "";
- SuperQueueScanner.Scanning_Match_Result = -3;
- redis.Publish(SysEnvironment.redis_Scanning_HeadCode, SysEnvironment.Global_Scanning_HeadCode);
- redis.Publish(SysEnvironment.redis_Scanning_FEMCode, SysEnvironment.Global_Scanning_FEMCode);
- redis.Publish(SysEnvironment.redis_ScanningMatchRes, SuperQueueScanner.Scanning_Match_Result);
- if (WriteFromD4001(listMtoc))
- {
- Write("拧紧工位数据写入成功", true);
- SysEnvironment.Global_ScannerBlock = false;
- redis.Publish(SysEnvironment.redis_ScannerBlock, SysEnvironment.Global_ScannerBlock);
- ///车型已写入,可以进入下一轮扫码,先扫车身的(因为不会阻塞)
- Read("扫描车头纸二维码请求", out bool bscanHead);
- if (bscanHead) 扫描车头纸二维码请求(true);
- Read("扫描FEM二维码请求", out bool bscanFEM);
- if (bscanFEM) 扫描FEM二维码请求(true);
- }
- UpdateTightingInfo(listMtoc[0]);
- MoveScanningPointer();
- }
- private bool WriteFromD4001(List<MoMtocData> list)
- {
- int length = list.Count;
- string startDevice_Type = "D4001";
- string startDevice_Color = "D6001";
- string startDevice_VIN = "D8010";
- short[] data1 = new short[length];
- short[] data2 = new short[length];
- short[] data3 = new short[length * 10];
- for (int i = 0; i < list.Count; i++)
- {
- data1[i] = Convert.ToInt16(list[i].Model);
- data2[i] = Convert.ToInt16(list[i].Color);
- int tmpCount = 0;
- short[] tmpShorts = String2Shorts(list[i].Vin);
- for (int j = i * 10; j < i * 10 + 10; j++)
- {
- data3[j] = tmpShorts[tmpCount];
- tmpCount++;
- }
- }
- int res1 = actEasyIF.WriteDeviceBlock2(startDevice_Type, length, ref data1[0]);
- int res2 = actEasyIF.WriteDeviceBlock2(startDevice_Color, length, ref data2[0]);
- int res3 = actEasyIF.WriteDeviceBlock2(startDevice_VIN, length * 10, ref data3[0]);
- return res1 == 0 && res2 == 0 && res3 == 0;
- }
- private bool WriteD4001(short model, short color, string vin)
- {
- string startDevice_Type = "D4001";
- string startDevice_Color = "D6001";
- string startDevice_VIN = "D8010";
- short[] data1 = new short[1] { model };
- short[] data2 = new short[1] { color };
- short[] data3 = new short[10];
- short[] tmpShorts = String2Shorts(vin);
- for (int i = 0; i < 10; i++)
- {
- data3[i] = tmpShorts[i];
- }
- int res1 = actEasyIF.WriteDeviceBlock2(startDevice_Type, 1, ref data1[0]);
- int res2 = actEasyIF.WriteDeviceBlock2(startDevice_Color, 1, ref data2[0]);
- int res3 = actEasyIF.WriteDeviceBlock2(startDevice_VIN, 10, ref data3[0]);
- return res1 == 0 && res2 == 0 && res3 == 0;
- }
- /// <summary>
- /// 更新本地拧紧工位信息
- /// </summary>
- /// <param name="modelScanned"></param>
- public void UpdateTightingInfo(MoMtocData modelScanned)
- {
- LogHelper.log.Info($"【更新本地拧紧工位数据】");
- //拧紧工位数据变更
- SysEnvironment.Global_Tighting_Pointer = modelScanned.Vin;
- SysEnvironment.Global_Tighting_Model = modelScanned.Model;
- SysEnvironment.Global_Tighting_Color = modelScanned.Color;
- redis.Publish(SysEnvironment.redis_Tighting_Pointer, modelScanned.Vin);
- redis.Publish(SysEnvironment.redis_Tighting_Model, modelScanned.Model);
- redis.Publish(SysEnvironment.redis_Tighting_Color, modelScanned.Color);
- }
- public void MoveScanningPointer()
- {
- LogHelper.log.Info($"【跳扫码工位指针】");
- //扫码工位指针变更
- MoMtocData model2Scan = BLLFactory<BlMtocData>.Instance.FindPointerNextModel(SysEnvironment.Global_Scanning_Pointer);
- SysEnvironment.Global_Scanning_Pointer = model2Scan == null ? "" : model2Scan.Vin;
- redis.Publish(SysEnvironment.redis_Scanning_Pointer, SysEnvironment.Global_Scanning_Pointer);
- LogHelper.log.Info($"扫码工位跳指针到 {SysEnvironment.Global_Scanning_Pointer}");
- }
- public void 读取拧紧结果请求(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("读取拧紧结果完成", false);
- return;
- }
- Read("拧紧结果1", out short itightRes1);
- Read("拧紧结果2", out short itightRes2);
- Read("拧紧结果3", out short itightRes3);
- Read("拧紧结果4", out short itightRes4);
- Read("拧紧力矩1", out float moment1);
- Read("拧紧力矩2", out float moment2);
- Read("拧紧力矩3", out float moment3);
- Read("拧紧力矩4", out float moment4);
- Read("拧紧角度1", out float angle1);
- Read("拧紧角度2", out float angle2);
- Read("拧紧角度3", out float angle3);
- Read("拧紧角度4", out float angle4);
- try
- {
- string curerntVIN = SysEnvironment.Global_Tighting_Pointer;
- int currentModel = SysEnvironment.Global_Tighting_Model;
- int curerntColor = SysEnvironment.Global_Tighting_Color;
- MoProductData model_data = BLLFactory<BlProductData>.Instance.Find2Bind(curerntVIN);
- if (model_data == null)
- {
- ProductionData data = new ProductionData();
- data.dict["型号"] = currentModel.ToString();
- data.dict["颜色"] = curerntColor.ToString();
- data.dict["VIN"] = curerntVIN;
- data.dict["FEM"] = curerntVIN;
- data.dict["VIN2"] = curerntVIN;
- data.dict["状态1"] = GetTightResult(itightRes1);
- data.dict["状态2"] = GetTightResult(itightRes2);
- data.dict["状态3"] = GetTightResult(itightRes3);
- data.dict["状态4"] = GetTightResult(itightRes4);
- data.dict["力矩1"] = moment1.ToString();
- data.dict["力矩2"] = moment2.ToString();
- data.dict["力矩3"] = moment3.ToString();
- data.dict["力矩4"] = moment4.ToString();
- data.dict["角度1"] = angle1.ToString();
- data.dict["角度2"] = angle2.ToString();
- data.dict["角度3"] = angle3.ToString();
- data.dict["角度4"] = angle4.ToString();
- data.dict["生产完成"] = "1";
- data.model.Batchid = curerntVIN;
- data.model.RuleTime = DateTime.Now;
- BLLFactory<BlProductData>.Instance.Insert(data.toModel());
- Write("读取拧紧结果完成", true);
- }
- else
- {
- ProductionData data = new ProductionData();
- data.LoadData(model_data);
- data.dict["状态1"] = GetTightResult(itightRes1);
- data.dict["状态2"] = GetTightResult(itightRes2);
- data.dict["状态3"] = GetTightResult(itightRes3);
- data.dict["状态4"] = GetTightResult(itightRes4);
- data.dict["力矩1"] = moment1.ToString();
- data.dict["力矩2"] = moment2.ToString();
- data.dict["力矩3"] = moment3.ToString();
- data.dict["力矩4"] = moment4.ToString();
- data.dict["角度1"] = angle1.ToString();
- data.dict["角度2"] = angle2.ToString();
- data.dict["角度3"] = angle3.ToString();
- data.dict["角度4"] = angle4.ToString();
- data.dict["生产完成"] = "1";
- data.model.RuleTime = DateTime.Now;
- BLLFactory<BlProductData>.Instance.Update(data.toModel(), data.model.DataId);
- Write("读取拧紧结果完成", true);
- }
- }
- catch (Exception ex)
- {
- //报警!!
- LogHelper.log.Error($"存储拧紧数据异常: {ex.Message} ");
- return;
- }
- }
- #endregion
- #region 私有方法
- private bool WriteDevice(List<MoMtocData> list, int length, bool writeD8000 = false)
- {
- string startDevice_Type = "D4001";
- string startDevice_Color = "D6001";
- string startDevice_VIN = "D8010";
- if (writeD8000)
- {
- startDevice_Type = "D4000";
- startDevice_Color = "D6000";
- startDevice_VIN = "D8000";
- }
- short[] data1 = new short[length];
- short[] data2 = new short[length];
- short[] data3 = new short[length * 10];
- for (int i = 0; i < list.Count; i++)
- {
- data1[i] = Convert.ToInt16(list[i].Model);
- data2[i] = Convert.ToInt16(list[i].Color);
- int tmpCount = 0;
- short[] tmpShorts = String2Shorts(list[i].Vin);
- for (int j = i * 10; j < i * 10 + 10; j++)
- {
- data3[j] = tmpShorts[tmpCount];
- tmpCount++;
- }
- }
- int res1 = actEasyIF.WriteDeviceBlock2(startDevice_Type, length, ref data1[0]);
- int res2 = actEasyIF.WriteDeviceBlock2(startDevice_Color, length, ref data2[0]);
- int res3 = actEasyIF.WriteDeviceBlock2(startDevice_VIN, length * 10, ref data3[0]);
- return res1 == 0 && res2 == 0 && res3 == 0;
- }
- private short[] String2Shorts(string ss, int minimumLength = 10)
- {
- char[] cc = ss.ToCharArray();
- short[] ii = new short[cc.Length];
- if (cc.Length < minimumLength)
- ii = new short[minimumLength];
- for (int i = 0; i < cc.Length; i += 2)
- {
- if (i + 1 == cc.Length)
- ii[i / 2] = (short)cc[i];
- else
- ii[i / 2] = (short)(cc[i + 1] * 256 + cc[i]);
- }
- return ii;
- }
- /// <summary>
- /// 清空PLC数据展示地址数据
- /// </summary>
- private void ClearPLC()
- {
- try
- {
- int length = 12;
- string startDevice_Type = "D4000";
- short[] data1 = new short[length];
- int res1 = actEasyIF.WriteDeviceBlock2(startDevice_Type, length, ref data1[0]);
- string startDevice_Color = "D6000";
- short[] data2 = new short[length];
- int res2 = actEasyIF.WriteDeviceBlock2(startDevice_Color, length, ref data2[0]);
- string startDevice_VIN = "D8000";
- //short[] data3 = Enumerable.Repeat<short>(Convert.ToInt16( '\0'), length).ToArray();;
- //int res3 = actEasyIF.WriteDeviceBlock2(startDevice_VIN, length, ref data3[0]);//多此一举
- short[] data3 = new short[length * 10];
- int res3 = actEasyIF.WriteDeviceBlock2(startDevice_VIN, length * 10, ref data3[0]);
- // SysEnvironment.SignTrrigerScanPLCData = res1 == 0 && res2 == 0 && res3 == 0;//用于监控节点界面刷新显示
- }
- catch (Exception ex)
- {
- LogHelper.log.Error($"ClearPLC()出错: {ex.Message}");
- }
- }
- private string GetTightResult(int ires)
- {
- switch (ires)
- {
- case 1:
- return "OK";
- case 2:
- return "NG";
- case 0:
- return "未拧紧";
- default:
- return ires.ToString();
- }
- }
- #endregion
- }
- }
|