| | |
| | | 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 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 = ""; |
| | | var putake = _putakeRepository.QueryFirst(x => x.Grouptype == group); |
| | | //è¿é夿ç»å«ä¸ä¸ªçæ¯é£ä¸ªï¼å°±æ¥é£ä¸ªå·¥èºè¡¨çå¼ |
| | | if (group=="çµæ°") |
| | | # region Setvalue |
| | | string group = item.DeviceProDataBlock; |
| | | if (group == "çµæ°") |
| | | { |
| | | //å
çå·¥èºè¡¨ä¸æ¥éª¤ä¸ä¸è¦æç弿å¤å°ä¸ª 忥çDt_TorqueOpè¡¨ä¸æ¯å¦æè¯¥ä»»å¡å·idåæ¥éª¤æ»æ°æ¯å¦æ»¡è¶³å·¥èºè¡¨ |
| | | var proces = _processRepository.QueryData(x => x.CraftType == group); |
| | | |
| | | //æ¥çæ¥éª¤ |
| | | var com = item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (5 * 1000).ToString().PadLeft(7, '0'))+"\r"; |
| | | serialPortDevice.Communicator.Write(com+"\r"); |
| | | //æå¼ä¸²å£æ¶å
è®¾å¼ |
| | | |
| | | |
| | | } |
| | | if (group == "æºæ¢°") |
| | | { |
| | | |
| | | } |
| | | if (group == "å°æ²") |
| | | { |
| | | |
| | | } |
| | | //gå·¥èºè¡¨çæåå¼ |
| | | |
| | | double num = 4.5;//0005000 |
| | | |
| | | serialPortDevice.Communicator.Write(item.DeviceChildCode + deviceProtocolDetail.ProtocalDetailValue.Replace("[setNum]", (num* 1000).ToString().PadLeft(7,'0'))+"\r");//æå¼ä¸²å£æ¶å
è®¾å¼ |
| | | #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 = item.DeviceProDataBlock; // è®¾å¤æå±ç»å« |
| | | 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(); |
| | | |
| | | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |