123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using PhihongEv.Lib;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MesAdaptor
- {
- public class SajectConnectSajet2 : ISajetConnect
- {
- private enum CMD
- {
- Signin = 1,
- SnCheck = 2,
- Report = 3,
- ValueReport = 4,
- }
- private readonly string _MechineCode;
- public SajectConnectSajet2(string MechineCode)
- {
- if (string.IsNullOrEmpty(MechineCode))
- {
- throw new Exception("MechineCode cannot not be empty");
- }
- _MechineCode = MechineCode;
- }
- public bool SajetTransStart() => SajetConnectAdapter.SajetTransStart();
- public bool SajetTransClose() => SajetConnectAdapter.SajetTransClose();
- private string userId = "";
- public bool SajetTransSignIn(ref string data)
- {
- var attemptId = data;
- var msg = data + ";";
- if (SajetTransData(CMD.Signin, ref data))
- {
- if (string.IsNullOrEmpty(data) || data.StartsWith("NG"))
- {
- userId = "";
- return false;
- }
- else
- {
- userId = attemptId;
- return true;
- }
- }
- userId = "";
- return false;
- }
- [Obsolete]
- public bool SajetTransWoCheck(ref string workOrder)
- {
- return true;
- }
- //private SystemID systemID;
- string modelName;
- string serialNumber;
- public bool SajetTransSnCheck(ref string serialNumber)
- {
- if (!SystemID.TryLooseParse(serialNumber, out var id))
- {
- return false;
- }
- this.modelName = null;
- this.serialNumber = null;
- var result = SajetTransSnCheck(ref serialNumber, id.ModelName.ToString());
- if (result)
- {
- this.modelName = id.ModelName.ToString();
- this.serialNumber = serialNumber;
- }
- return result;
- //var msg = string.Format("{0};{1};;", id.ModelName.ToString(), id.ToString());
- //if (SajetTransData(CMD.SnCheck, ref msg))
- //{
- // if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
- // {
- // systemID = null;
- // return false;
- // }
- // systemID = id;
- // return true;
- //}
- //systemID = null;
- //return false;
- }
- public bool SajetTransSnCheck(ref string sn, string model)
- {
- var msg = string.Format("{0};{1};;", model, sn);
- this.serialNumber = null;
- this.modelName = null;
- if (SajetTransData(CMD.SnCheck, ref msg))
- {
- if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
- {
- return false;
- }
- this.serialNumber = sn;
- this.modelName = model;
- return true;
- }
- return false;
- }
- //public bool SajetTransSnCheck(string partNO,string sn)
- //{
- // var msg = string.Format("{0};{1};;", partNO, sn);
- // if (SajetTransData(CMD.SnCheck, ref msg))
- // {
- // if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
- // {
- // return false;
- // }
- // return true;
- // }
- // return false;
- //}
- public bool SajetTranFinishSuccess()
- {
- //File.AppendAllText("debug.txt", string.Format("userId:{0}", userId));
- //File.AppendAllText("debug.txt", string.Format("modelName:{0}", modelName));
- //File.AppendAllText("debug.txt", string.Format("serialNumber:{0}", serialNumber));
- if (string.IsNullOrEmpty(userId))
- return false;
- if (modelName == null)
- return false;
- if (serialNumber == null)
- return false;
- //string msg = userId + ";" + systemID.ToString() + ";";
- string msg = string.Format("{0};{1};{2};{3}:0;", userId, _MechineCode, modelName, serialNumber);
- if (string.IsNullOrEmpty(msg))
- return false;
- return SajetTransData(CMD.Report, ref msg);
- }
- //public bool SajetTranFinishSuccess(string partNO, string sn)
- //{
- // if (string.IsNullOrEmpty(userId))
- // return false;
- // //string msg = userId + ";" + systemID.ToString() + ";";
- // string msg = string.Format("{0};{1};{2};{3}:0;", userId, _MechineCode, partNO, sn);
- // if (string.IsNullOrEmpty(msg))
- // return false;
- // return SajetTransData(CMD.Report, ref msg);
- //}
- public bool SajetTranFinishFail(MesErrorCode errorCode)
- {
- if (string.IsNullOrEmpty(userId))
- return false;
- if (modelName == null)
- return false;
- if (serialNumber == null)
- return false;
- //string msg = userId + ";" + systemID.ToString() + ";";
- string msg = string.Format("{0};{1};{2};{3}:1:", userId, _MechineCode, modelName, serialNumber);
- if (string.IsNullOrEmpty(msg))
- return false;
- msg += $"{GetMesCodeString(errorCode)};"; //E114
- return SajetTransData(CMD.Report, ref msg);
- }
- //public bool SajetTranFinishFail(string partNO, string sn, MesErrorCode errorCode)
- //{
- // if (string.IsNullOrEmpty(userId))
- // return false;
- // //string msg = userId + ";" + systemID.ToString() + ";";
- // string msg = string.Format("{0};{1};{2};{3}:1:", userId, _MechineCode, partNO, sn);
- // if (string.IsNullOrEmpty(msg))
- // return false;
- // msg += $"{errorCode};"; //E114
- // return SajetTransData(CMD.Report, ref msg);
- //}
- [Obsolete]
- public string SajetTransRegisterHeader(string model, string header)
- {
- return "";
- }
- public bool SajetTransReport(ValueReportDatas reportDatas)
- {
- if (string.IsNullOrEmpty(userId))
- return false;
- if (modelName == null)
- return false;
- if (serialNumber == null)
- return false;
- var totalResult = true;
- foreach (var data in reportDatas)
- {
- var key = data.Key;
- var value = data.Val;
- var isSuccess = data.IsSuccess;
- value = value.Trim();
- var det = isSuccess ? "0" : "1";
- if (string.IsNullOrEmpty(value))
- {
- value = "empty";
- }
- else if (value.ToLower() == "fail")
- {
- value = "0";
- }
- else if (value.ToLower() == "success")
- {
- value = "1";
- }
- var msg = string.Format("{0};{1};{2};{3};{4}:{5}:{6};", userId, _MechineCode, modelName, serialNumber, key, value, det);
- var result = SajetTransData(CMD.ValueReport, ref msg);
- totalResult &= result;
- }
- return totalResult;
- }
- //public bool SajetTransReport(string partNO, string no, Dictionary<string, string> reportPair)
- //{
- // if (string.IsNullOrEmpty(userId))
- // return false;
- // var totalResult = true;
- // foreach (var pair in reportPair)
- // {
- // var msg = string.Format("{0};{1};{2};{3};{4}:{5};", userId, _MechineCode, partNO, no, pair.Key, pair.Value);
- // var result = SajetTransData(CMD.ValueReport, ref msg);
- // totalResult &= result;
- // }
- // return totalResult;
- //}
- [Obsolete]
- public bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
- {
- return true;
- }
- [Obsolete]
- public bool SajetTransReport(Dictionary<string, string> resultPair, Dictionary<string, string> codePair)
- {
- return true;
- }
- [Obsolete]
- public bool SajetTransLog(string data)
- {
- return true;
- }
- private bool SajetTransData(CMD command, ref string data)
- {
- return SajetConnectAdapter.SajetTransData((int)command, ref data);
- }
- private string GetMesCodeString(MesErrorCode mesError)
- {
- switch (mesError)
- {
- case MesErrorCode.ChargerConnectFail:
- return "A081";
- case MesErrorCode.ModelNameUpadateFail:
- return "A082";
- case MesErrorCode.SerilaNumberUpadateFail:
- return "A083";
- case MesErrorCode.UtcDatetimeUpdateFail:
- return "A084";
- case MesErrorCode.FourthGenModelVersionMismatch:
- return "A085";
- case MesErrorCode.FourthGenSimInstartionMismatch:
- return "A086";
- case MesErrorCode.FourthGenSimInfoMismatch:
- return "A087";
- case MesErrorCode.WifiModeNotClient:
- return "A088";
- case MesErrorCode.WifiRssiLow:
- return "A089";
- case MesErrorCode.FirmwareUploadFail:
- return "A090";
- case MesErrorCode.FirmwareUpdateTimeout:
- return "A091";
- case MesErrorCode.FirmwareVersionCheckFail:
- return "A092";
- case MesErrorCode.EmergencyButtonTestFail:
- return "A093";
- case MesErrorCode.GreenButtonTestFail:
- return "A094";
- case MesErrorCode.BlueButtonTestFail:
- return "A095";
- case MesErrorCode.FactoryResetFail:
- return "A096";
- case MesErrorCode.SetOptionsFail:
- return "ST001";
- case MesErrorCode.ProgramFail:
- return "ST002";
- case MesErrorCode.RestFail:
- return "ST003";
- case MesErrorCode.ProgramCheckFail:
- return "ST004";
- case MesErrorCode.GetCheckSumFail:
- return "ST005";
- }
- return "A081";
- }
- }
- }
|