| | |
| | | using System.Drawing.Imaging; |
| | | using System.IO.Ports; |
| | | using System.Linq; |
| | | using System.Net.WebSockets; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using HslCommunication.WebSocket; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using SqlSugar; |
| | | using StackExchange.Profiling.Internal; |
| | | using WIDESEA_ISerialPortRepository; |
| | | using WIDESEA_SerialPortRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | [DisallowConcurrentExecution] |
| | | public class SerialPortJob : JobBase, IJob, IDisposable |
| | | public class SerialPortJob : JobBase, IJob,IDisposable |
| | | { |
| | | public void Dispose() |
| | | { |
| | |
| | | public enum CommandType |
| | | { |
| | | None = 0, |
| | | Get = 1, |
| | | Set = 2, |
| | | Get = 1,//åä¿¡å· |
| | | Set = 2,//è®¾å¼ |
| | | } |
| | | |
| | | public enum CommandResult |
| | | { |
| | | SetOK = 0, |
| | | GetOK = 1, |
| | | GetError = 2, |
| | | SetOK = 0,//parseok |
| | | GetOK = 1,//03 |
| | | GetError = 2,//04 |
| | | } |
| | | private readonly IPutakeRepository _putakeRepository; |
| | | private readonly IProcessRepository _processRepository; |
| | | private readonly ITorqueOpRepository _orqueOpRepository; |
| | | public SerialPortJob(IPutakeRepository putakeRepository, IProcessRepository processRepository, ITorqueOpRepository torqueOpRepository) |
| | | private WebSocketServer _webSocketContext; |
| | | |
| | | public SerialPortJob(IPutakeRepository putakeRepository, IProcessRepository processRepository, ITorqueOpRepository torqueOpRepository, WebSocketServer webSocketContext) |
| | | { |
| | | _putakeRepository = putakeRepository; |
| | | _processRepository = processRepository; |
| | | _orqueOpRepository = torqueOpRepository; |
| | | _webSocketContext = webSocketContext; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | |
| | | SerialPortDevice serialPortDevice = (SerialPortDevice)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (serialPortDevice != null) |
| | | { |
| | | |
| | | List<DeviceProDTO> deviceProDTOs = serialPortDevice.DeviceProDTOs; |
| | | foreach (var item in deviceProDTOs) |
| | | { |
| | |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandType) && x.ProtocolDetailType == nameof(CommandType.Set)); |
| | | if (deviceProtocolDetail != null) |
| | | { |
| | | //æè¦å端è¿åç»æä¸ä¸ªç»å«ï¼åä»»å¡id |
| | | //å
æ¥ç¶æåç»ï¼ææ¶é´éåº |
| | | string group = "çµæ°"; |
| | | |
| | | |
| | | //è¿é夿ç»å«ä¸ä¸ªçæ¯é£ä¸ªï¼å°±æ¥é£ä¸ªå·¥èºè¡¨çå¼ |
| | | if (group=="çµæ°") |
| | | # region Setvalue |
| | | string group = item.DeviceProDataBlock; |
| | | if (group == "çµæ°") |
| | | { |
| | | |
| | | //å
çå·¥èºè¡¨ä¸æ¥éª¤ä¸ä¸è¦æç弿å¤å°ä¸ª 忥çDt_TorqueOpè¡¨ä¸æ¯å¦æè¯¥ä»»å¡å·idåæ¥éª¤æ»æ°æ¯å¦æ»¡è¶³å·¥èºè¡¨ |
| | | // æ¥è¯¢ææå·¥èºæ°æ®ï¼æç
§æ¥éª¤å· SetpNum éå¢æåº |
| | | var processList = _processRepository.QueryData(x => x.CraftType == group) |
| | | .OrderBy(x => x.SetpNum) |
| | | .ToList(); |
| | | |
| | | foreach (var process in processList) |
| | | { |
| | | float torqueone = process.TorqueOne;//读å°å¼äº |
| | | float torquetow = process.TorqueTwo; |
| | | if (torqueone!=0) |
| | | { |
| | | serialPortDevice.Communicator.Write(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (torqueone * 1000).ToString().PadLeft(7, '0')) + "\r"); |
| | | } |
| | | if (torquetow != 0) |
| | | { |
| | | serialPortDevice.Communicator.Write(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (torquetow * 1000).ToString().PadLeft(7, '0')) + "\r"); |
| | | } |
| | | |
| | | // 计ç®å½åæ¥éª¤æéç Torque æ»æ° |
| | | int requiredTorqueCount = process.TorqueOneQuantity + process.TorqueTwoQuantity; |
| | | |
| | | // æ¥è¯¢å½åæ¥éª¤ç TorqueOp è®°å½ï¼å¹é
ProcessSteåç»ï¼æ£æ¥æ¯å¦è¾¾å°è¦æ± |
| | | int torqueCount = _orqueOpRepository.QueryData(x => x.ProcessSte == process.SetpNum&& x.GroupOp== group).Count(); |
| | | |
| | | if (torqueCount < requiredTorqueCount) |
| | | { |
| | | // 妿æ°é䏿»¡è¶³ï¼åæ¢è¯»å |
| | | |
| | | break; |
| | | } |
| | | //符åè¦æ±ï¼ç»§ç»è¯»åä¸ä¸æ¥ |
| | | |
| | | } |
| | | |
| | | //æ¥çæ¥éª¤ |
| | | var com = item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (5 * 1000).ToString().PadLeft(7, '0'))+"\r"; |
| | | serialPortDevice.Communicator.Write(com+"\r"); |
| | | //æå¼ä¸²å£æ¶å
è®¾å¼ |
| | | |
| | | |
| | | } |
| | | if (group == "æºæ¢°") |
| | | { |
| | | |
| | | } |
| | | if (group == "å°æ²") |
| | | { |
| | | |
| | | } |
| | | //æå¼ä¸²å£æ¶å
è®¾å¼ |
| | | #endregion |
| | | item.DeviceProParamName = CommandType.Set.ToString(); |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandResult) && x.ProtocolDetailType == nameof(CommandResult.GetOK)); |
| | | //03æå |
| | | |
| | | if (deviceProtocolDetail != null && receiveData.Contains(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue)) |
| | | { |
| | | //è¿éæåä¹åï¼è¦åå¨å°çDt_TorqueOpï¼åä»»å¡å·ï¼ç»ï¼å¼ï¼ |
| | | string group = ""; |
| | | |
| | | string group = item.DeviceProDataBlock; // è®¾å¤æå±ç»å« |
| | | if (group == "çµæ°") |
| | | { |
| | | var putake = _putakeRepository.QueryData(x => x.Pustatus == 2 && x.Grouptype == group).OrderByDescending(x => x.Dispatchtime).FirstOrDefault();//æ¯æ¬¡é½æ¿ææ©ç飿¡ |
| | | var punjid = putake.ID; |
| | | var Nj = new Dt_TorqueOp() |
| | | { |
| | | TakeId = putake.Njtakeid, |
| | | GroupOp = group, |
| | | //ProcessSte= processList |
| | | TorqueSize = receiveData |
| | | |
| | | }; |
| | | _orqueOpRepository.AddData(Nj); |
| | | |
| | | } |
| | | if (group == "æºæ¢°") |
| | | { |
| | | |
| | | } |
| | | if (group == "å°æ²") |
| | | |
| | | |
| | | item.DeviceProParamName = CommandType.Set.ToString(); |
| | | |
| | | } |
| | | } |
| | | else if (item.DeviceProParamName == CommandType.Get.ToString()) |
| | | { |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandResult) && x.ProtocolDetailType == nameof(CommandResult.GetError)); |
| | | if (deviceProtocolDetail != null && receiveData.Contains(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue)) |
| | | { |
| | | item.DeviceProParamName = CommandType.Set.ToString(); |
| | | } |
| | | else if (item.DeviceProParamName == CommandType.Get.ToString()) |
| | | { |
| | | //DeviceProtocolDetailDTO? deviceProtocolDetail = serialPortDevice.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CommandResult) && x.ProtocolDetailType == nameof(CommandResult.GetError)); |
| | | //if (deviceProtocolDetail != null && receiveData.Contains(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue)) |
| | | //{ |
| | | // item.DeviceProParamName = CommandType.Set.ToString(); |
| | | |
| | | |
| | | |
| | | //} |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //建ä¸ä¸ªå¯¹è±¡å°å
¶ä¼ ç»å端 |
| | | string data = JsonConvert.SerializeObject(serialPortDevice);//è¿éserialPortDeviceæ¯å设æè¿ä¸ªå¯¹è±¡ |
| | | _webSocketContext.PublishAllClientPayload(data); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | WriteDebug("CommonConveyorLineJob", "test"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |