123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929 |
- 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.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 class ScanResClass
- {
- public string ScanResult { get; set; }
- public DateTime ScanTime { get; set; }
- }
- public static class SuperQueueScanner
- {
- internal static RedisHelper redis = new RedisHelper();
- internal static List<ScanResClass> HeadCodeList = new List<ScanResClass>();
- internal static int HeadCodeListMaxMun = 2;
- internal static string ScanHeadCode()
- {
- string scanRes = Scanner.CameraScanner(ip2, port2, 3).Trim();
- LogHelper.log.Info($"触发车头纸扫码:{scanRes}");
- HeadCodeList.Add(new ScanResClass { ScanResult = scanRes, ScanTime = DateTime.Now });
- while (HeadCodeList.Count > HeadCodeListMaxMun)
- {
- HeadCodeList.RemoveAt(0);
- }
- return scanRes;
- }
- internal static List<ScanResClass> FEMCodeList = new List<ScanResClass>();
- internal static int FEMCodeListMaxMun = 3;
- internal static string ScanFEMCode()
- {
- string scanRes = Scanner.CameraScanner(ip1, port1, 3).Trim();
- LogHelper.log.Info($"触发FEM扫码:{scanRes}");
- FEMCodeList.Add(new ScanResClass { ScanResult = scanRes, ScanTime = DateTime.Now });
- while (FEMCodeList.Count > FEMCodeListMaxMun)
- {
- FEMCodeList.RemoveAt(0);
- }
- return scanRes;
- }
- internal static int Scanning_Match_Result = -3;
- internal static void GenMatchResult()
- {
- LogHelper.log.Info($"匹配逻辑开始,车头扫码SkipHeadScan = {SkipHeadScan},FEM扫码SkipFEMScan = {SkipFEMScan}");
- try
- {
- if (SkipHeadScan && SkipFEMScan)
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return;
- }
- else if (SkipHeadScan && !SkipFEMScan)
- {
- if (SysEnvironment.Global_FEM_Pointer == "")
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return;
- }
- string str2 = SysEnvironment.Global_FEM_Pointer; //FEMCodeList[0].ScanResult;
- if (!SysEnvironment.CheckVINRule(str2))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- if (!string.Equals(str2, SysEnvironment.Global_Scanning_Pointer))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- }
- else if (!SkipHeadScan && SkipFEMScan)
- {
- if (SysEnvironment.Global_Head_Pointer == "")
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return;
- }
- string str1 = SysEnvironment.Global_Head_Pointer; //HeadCodeList[0].ScanResult;
- if (!SysEnvironment.CheckVINRule(str1))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- if (!string.Equals(str1, SysEnvironment.Global_Scanning_Pointer))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- }
- else
- {
- if (SysEnvironment.Global_Head_Pointer == "" && SysEnvironment.Global_FEM_Pointer == "")
- {
- SuperQueueScanner.Scanning_Match_Result = -3;
- return;
- }
- else if (SysEnvironment.Global_FEM_Pointer == "")
- {
- SuperQueueScanner.Scanning_Match_Result = -2;//匹配中
- return;
- }
- else if (SysEnvironment.Global_Head_Pointer == "")
- {
- SuperQueueScanner.Scanning_Match_Result = -2;//匹配中
- return;
- }
- string str1 = SysEnvironment.Global_Head_Pointer;//HeadCodeList[0].ScanResult;
- string str2 = SysEnvironment.Global_FEM_Pointer;// FEMCodeList[0].ScanResult;
- if (!SysEnvironment.CheckVINRule(str1) || !SysEnvironment.CheckVINRule(str2))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- if (!string.Equals(str1, str2))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- if (!string.Equals(str1, SysEnvironment.Global_Scanning_Pointer))
- {
- SuperQueueScanner.Scanning_Match_Result = 0;
- return;
- }
- }
- //匹配成功,写入数据库扫码结果
- SuperQueueScanner.Scanning_Match_Result = 1;
- StoreScanningResult();
- }
- finally
- {
- LogHelper.log.Info($"匹配结果为{SuperQueueScanner.Scanning_Match_Result}");
- }
- }
- }
- 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;
- actionConnected();
- }
- else
- {
- // SysEnvironment.sign_OnlineMode = false;
- }
- }
- public void 连锁信号(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (signal)
- {
- //SuperQueueScanner.GenMatchResult();
- //TackleMatchResult();
- }
- else
- {
- //清除扫码工位变量
- SysEnvironment.Global_Head_Pointer = "";
- SysEnvironment.Global_FEM_Pointer = "";
- SuperQueueScanner.Scanning_Match_Result = -3;
- //清空写入过的车型
- 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);
- }
- public void 扫描车头纸二维码请求(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("读取车头纸二维码成功", false);
- Write("读取车头纸二维码失败", false);
- return;
- }
- string res = SuperQueueScanner.ScanHeadCode();
- Write("读取车头纸二维码成功", true);
- Read("连锁信号", out bool bChain);
- if (bChain)
- {
- if (SysEnvironment.Global_Head_Pointer == "" && !SkipHeadScan)
- {
- SysEnvironment.Global_Head_Pointer = res;
- redis.Publish(SysEnvironment.redis_Scanning_HeadCode_Pointer, SysEnvironment.Global_Head_Pointer);
- LogHelper.log.Info($"车头指针跳至 {SysEnvironment.Global_Head_Pointer}");
- SuperQueueScanner.GenMatchResult();
- TackleMatchResult();
- }
- }
- else//切除状态下,扫码跳指针
- {
- MoveScanningPointer();
- }
- }
- public void 扫描FEM二维码请求(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("读取FEM二维码成功", false);
- Write("读取FEM二维码失败", false);
- return;
- }
- string res = SuperQueueScanner.ScanFEMCode();
- Write("读取FEM二维码成功", true);
- if (SysEnvironment.Global_FEM_Pointer == "" && !SkipFEMScan)
- {
- SysEnvironment.Global_FEM_Pointer = res;
- redis.Publish(SysEnvironment.redis_Scanning_FEMCode_Pointer, SysEnvironment.Global_FEM_Pointer);
- LogHelper.log.Info($"FEM指针跳至 {SysEnvironment.Global_FEM_Pointer}");
- SuperQueueScanner.GenMatchResult();
- TackleMatchResult();
- //手动匹配及FEM来慢的时侯,读取M1118
- Read("请求拧紧工位数据写入", out bool delayWrite);
- if (delayWrite) 请求拧紧工位数据写入(true);
- }
- }
- /// <summary>
- ///手动匹配会读取M1118(如果M1118已经发出的话)
- ///因此要匹配之前调好指针,这样进入下一次匹配时,才不至于又失败
- /// </summary>
- public void ManualForceMatchSuccess()
- {
- SuperQueueScanner.Scanning_Match_Result = 1;
- TackleMatchResult();
- //手动匹配及FEM来慢的时侯,读取M1118
- Read("请求拧紧工位数据写入", out bool delayWrite);
- if (delayWrite) 请求拧紧工位数据写入(true);
- }
- 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_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 bwrite);
- if (!bwrite)
- Write("拧紧工位数据写入成功", false);
- }
- public void 请求拧紧工位数据写入(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("拧紧工位数据写入成功", false);
- return;
- }
- RefreshTightingUI(null);
- if (!WriteD4001(0, 0, "")) return;
- //匹配失败0、没匹配完-2 切除状态不匹配 -3
- if (SuperQueueScanner.Scanning_Match_Result < 1)
- {
- LogHelper.log.Error($"匹配失败,无法写入车型。当前指针 {SysEnvironment.Global_Scanning_Pointer}");
- 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;
- }
- if (!WriteFromD4001(listMtoc))
- {
- return;
- }
- Write("拧紧工位数据写入成功", true);
- //230214 更新拧紧工位显示之前,进行TightingMonitor的数据更新
- UpdateFormMonitorTightenData();
- RefreshTightingUI(listMtoc[0]);
- //AS400指针下调
- //车头指针下调(最多两个,如果是第二个就不调)
- //FEM指针下调(最多三个,如果是第三个就不调)
- //匹配下一台车
- MoveScanningPointer();
- MoveHeadPointer();
- MoveFEMPointer();
- SuperQueueScanner.GenMatchResult();
- TackleMatchResult();
- }
- 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 RefreshTightingUI(MoMtocData modelScanned)
- {
- if (modelScanned == null)
- {
- 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, "");
- }
- else
- {
- 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()
- {
- 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 MoveHeadPointer()
- {
- int index = SuperQueueScanner.HeadCodeList.FindIndex(t => t.ScanResult == SysEnvironment.Global_Head_Pointer);
- if (index + 1 >= SuperQueueScanner.HeadCodeList.Count) SysEnvironment.Global_Head_Pointer = "";
- else SysEnvironment.Global_Head_Pointer = SuperQueueScanner.HeadCodeList[index + 1].ScanResult;
- redis.Publish(SysEnvironment.redis_Scanning_HeadCode_Pointer, SysEnvironment.Global_Head_Pointer);
- LogHelper.log.Info($"车头指针跳至 {SysEnvironment.Global_Head_Pointer}");
- }
- public void MoveFEMPointer()
- {
- int index = SuperQueueScanner.FEMCodeList.FindIndex(t => t.ScanResult == SysEnvironment.Global_FEM_Pointer);
- if (index + 1 >= SuperQueueScanner.FEMCodeList.Count) SysEnvironment.Global_FEM_Pointer = "";
- else SysEnvironment.Global_FEM_Pointer = SuperQueueScanner.FEMCodeList[index + 1].ScanResult;
- redis.Publish(SysEnvironment.redis_Scanning_FEMCode_Pointer, SysEnvironment.Global_FEM_Pointer);
- LogHelper.log.Info($"FEM指针跳至 {SysEnvironment.Global_FEM_Pointer}");
- }
- public static short itightRes1 = 0;
- public static short itightRes2 = 0;
- public static short itightRes3 = 0;
- public static short itightRes4 = 0;
- public static float torque1 = 0.0f;
- public static float torque2 = 0.0f;
- public static float torque3 = 0.0f;
- public static float torque4 = 0.0f;
- public static float angle1 = 0.0f;
- public static float angle2 = 0.0f;
- public static float angle3 = 0.0f;
- public static float angle4 = 0.0f;
- public static short old_itightRes1 = 0;
- public static short old_itightRes2 = 0;
- public static short old_itightRes3 = 0;
- public static short old_itightRes4 = 0;
- public static float old_torque1 = 0.0f;
- public static float old_torque2 = 0.0f;
- public static float old_torque3 = 0.0f;
- public static float old_torque4 = 0.0f;
- public static float old_angle1 = 0.0f;
- public static float old_angle2 = 0.0f;
- public static float old_angle3 = 0.0f;
- public static float old_angle4 = 0.0f;
- public static string oldVIN = "";
- public static string newVIN = "";
- public void UpdateFormMonitorTightenData()
- {
- oldVIN = SysEnvironment.Global_Tighting_Pointer;//这个是发车后,刚刚拧紧完的 (搬出的)
- old_itightRes1 = itightRes1;
- old_itightRes2 = itightRes2;
- old_itightRes3 = itightRes3;
- old_itightRes4 = itightRes4;
- old_torque1 = torque1;
- old_torque2 = torque2;
- old_torque3 = torque3;
- old_torque4 = torque4;
- old_angle1 = angle1;
- old_angle2 = angle2;
- old_angle3 = angle3;
- old_angle4 = angle4;
- newVIN = SysEnvironment.Global_Scanning_Pointer; //这个是发车后,从扫码位置过来的,还没拧的
- itightRes1 = 0;
- itightRes2 = 0;
- itightRes3 = 0;
- itightRes4 = 0;
- torque1 = 0;
- torque2 = 0;
- torque3 = 0;
- torque4 = 0;
- angle1 = 0;
- angle2 = 0;
- angle3 = 0;
- angle4 = 0;
- }
- public void 读取拧紧结果请求(object value)
- {
- bool signal = Convert.ToBoolean(value);
- LogHelper.log.Info($"signal = {signal}");
- if (!signal)
- {
- Write("读取拧紧结果完成", false);
- return;
- }
- Read("拧紧结果1", out itightRes1);
- Read("拧紧结果2", out itightRes2);
- Read("拧紧结果3", out itightRes3);
- Read("拧紧结果4", out itightRes4);
- Read("拧紧力矩1", out torque1);
- Read("拧紧力矩2", out torque2);
- Read("拧紧力矩3", out torque3);
- Read("拧紧力矩4", out torque4);
- Read("拧紧角度1", out angle1);
- Read("拧紧角度2", out angle2);
- Read("拧紧角度3", out angle3);
- Read("拧紧角度4", out 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"] = torque1.ToString();
- data.dict["力矩2"] = torque2.ToString();
- data.dict["力矩3"] = torque3.ToString();
- data.dict["力矩4"] = torque4.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"] = torque1.ToString();
- data.dict["力矩2"] = torque2.ToString();
- data.dict["力矩3"] = torque3.ToString();
- data.dict["力矩4"] = torque4.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
- }
- }
|