|
@@ -25,6 +25,7 @@ using TeamAAS_VP.Resources.Languages;
|
|
|
using TeamAAS_VP.ViewModels;
|
|
using TeamAAS_VP.ViewModels;
|
|
|
using TeamAAS_VP.ViewModels.Home;
|
|
using TeamAAS_VP.ViewModels.Home;
|
|
|
using TouchSocket.Core;
|
|
using TouchSocket.Core;
|
|
|
|
|
+using TouchSocket.SerialPorts;
|
|
|
using TouchSocket.Sockets;
|
|
using TouchSocket.Sockets;
|
|
|
|
|
|
|
|
namespace TeamAAS_VP.Core
|
|
namespace TeamAAS_VP.Core
|
|
@@ -37,6 +38,7 @@ namespace TeamAAS_VP.Core
|
|
|
IContainerProvider _container;
|
|
IContainerProvider _container;
|
|
|
IConfigService _configService;
|
|
IConfigService _configService;
|
|
|
IRobotService _robotService;
|
|
IRobotService _robotService;
|
|
|
|
|
+ IScannerService _scannerService;
|
|
|
ICameraService _cameraService;
|
|
ICameraService _cameraService;
|
|
|
IFeederService _feederService;
|
|
IFeederService _feederService;
|
|
|
IPlcService _plcService;
|
|
IPlcService _plcService;
|
|
@@ -58,6 +60,8 @@ namespace TeamAAS_VP.Core
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 属性
|
|
#region 属性
|
|
|
|
|
+ private Guid _defaultScannerId = Guid.Empty;
|
|
|
|
|
+ private volatile TaskCompletionSource<string> _scanTcs; // 最简单:只支持单通道“当前一次扫
|
|
|
public string[] CsvData = new string[50];
|
|
public string[] CsvData = new string[50];
|
|
|
public int[] ResultData = new int[200];
|
|
public int[] ResultData = new int[200];
|
|
|
public string code = "";
|
|
public string code = "";
|
|
@@ -65,8 +69,20 @@ namespace TeamAAS_VP.Core
|
|
|
private ObservableCollection<ShowRender> _Renders;
|
|
private ObservableCollection<ShowRender> _Renders;
|
|
|
private double _CTtime;
|
|
private double _CTtime;
|
|
|
public int ResultDataCount;
|
|
public int ResultDataCount;
|
|
|
|
|
+ // 扫码结果
|
|
|
|
|
+ private string ScanValue = "";
|
|
|
|
|
+ // 扫码完成事件
|
|
|
|
|
+ private readonly ManualResetEventSlim _scanDoneEvent = new ManualResetEventSlim(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ private SerialPortClient _Scan_Client;
|
|
|
|
|
+
|
|
|
|
|
+ public SerialPortClient Scan_Client
|
|
|
|
|
+ {
|
|
|
|
|
+ get { return _Scan_Client; }
|
|
|
|
|
+ set { _Scan_Client = value; }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private bool _ShowMes_Query;
|
|
private bool _ShowMes_Query;
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 显示查询结果
|
|
/// 显示查询结果
|
|
@@ -199,7 +215,7 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
|
|
public Management(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IConfigService configService,
|
|
public Management(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IConfigService configService,
|
|
|
IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService, IProductService productService,
|
|
IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService, IProductService productService,
|
|
|
- ICalibrationService calibrationService, IRemoteCommandService remoteCommandService, ISystemDatabaseService systemDatabaseService, ILightManagerService lightManagerService, IMesService mesService)
|
|
|
|
|
|
|
+ ICalibrationService calibrationService, IRemoteCommandService remoteCommandService, ISystemDatabaseService systemDatabaseService, ILightManagerService lightManagerService, IMesService mesService, IScannerService scannerService)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
_regionManager = regionManager;
|
|
_regionManager = regionManager;
|
|
@@ -207,6 +223,7 @@ namespace TeamAAS_VP.Core
|
|
|
_container = container;
|
|
_container = container;
|
|
|
_configService = configService;
|
|
_configService = configService;
|
|
|
_robotService = robotService;
|
|
_robotService = robotService;
|
|
|
|
|
+ _scannerService = scannerService;
|
|
|
_cameraService = cameraService;
|
|
_cameraService = cameraService;
|
|
|
_feederService = feederService;
|
|
_feederService = feederService;
|
|
|
_plcService = plcService;
|
|
_plcService = plcService;
|
|
@@ -297,6 +314,44 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 初始化扫码枪
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public async Task<(bool IsSucceed, string Msg)> InitScanners()
|
|
|
|
|
+ {
|
|
|
|
|
+ var scanners = _configService.GetAllScanners();
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
+ foreach (var item in scanners)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scannerService.CreateScanner(item.Id, item);
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ Status.Add(new StatusInfo(item.Id, item.ScannerName + $"{Lang.未连接}", new SolidColorBrush(Colors.Red)));
|
|
|
|
|
+ var scanner = _scannerService.GetScanner(item.Id);
|
|
|
|
|
+ scanner.ReceivedEvent += Management_ScannerReceivedEvent;
|
|
|
|
|
+ scanner.SendEvent += Management_ScannerSendEvent;
|
|
|
|
|
+ scanner.ConnectedEvent += Management_ScannerConnectedEvent;
|
|
|
|
|
+ scanner.DisconnectedEvent += Management_ScannerDisconnectedEvent;
|
|
|
|
|
+ await scanner.ConnectAsync(); //连接Scanner
|
|
|
|
|
+ SendTaskMessage($"{item.ScannerName}{Lang.已连接}!", MessageLevel.Debug);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ sb.AppendLine($"{item.ScannerName}:{Lang.断开连接}![{ex.Message}]");
|
|
|
|
|
+ SendTaskMessage($"{item.ScannerName}{Lang.断开连接}!", MessageLevel.Alarm);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sb.Length == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return (true, "");
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ return (false, sb.ToString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 初始化PLC
|
|
/// 初始化PLC
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -621,11 +676,73 @@ namespace TeamAAS_VP.Core
|
|
|
LogHelper.WriteLogError("连接电批时出错!", ex);
|
|
LogHelper.WriteLogError("连接电批时出错!", ex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public async Task InitScan()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!File.Exists(FilePath.ScanRS232ConfigPath))
|
|
|
|
|
+ {
|
|
|
|
|
+ var scan = new ScanRs232ConfigModel();
|
|
|
|
|
+ FileHelper.WriteJsonFile(scan, FilePath.ScanRS232ConfigPath);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ var res = FileHelper.ReadJsonFile<ScanRs232ConfigModel>(FilePath.ScanRS232ConfigPath);
|
|
|
|
|
+ if (res != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ Scan_Client = new SerialPortClient();
|
|
|
|
|
+ Scan_Client.Connecting = (client1, e) => { return EasyTask.CompletedTask; };//即将连接到端口
|
|
|
|
|
+ Scan_Client.Connected = (client1, e) => { return EasyTask.CompletedTask; };//成功连接到端口
|
|
|
|
|
+ Scan_Client.Closing = (client1, e) => { return EasyTask.CompletedTask; };//即将从端口断开连接。此处仅主动断开才有效。
|
|
|
|
|
+ Scan_Client.Closed = (client1, e) => { return EasyTask.CompletedTask; };//从端口断开连接,当连接不成功时不会触发。
|
|
|
|
|
+ Scan_Client.Received = async (c, e) =>
|
|
|
|
|
+ {
|
|
|
|
|
+ //await Console.Out.WriteLineAsync(Encoding.UTF8.GetString(e.ByteBlock.Buffer));
|
|
|
|
|
+ await Console.Out.WriteLineAsync(e.ByteBlock.Span.ToString(Encoding.ASCII));
|
|
|
|
|
+ };
|
|
|
|
|
+ Scan_Client.Received = Scan_DataReceived;
|
|
|
|
|
+
|
|
|
|
|
+ await Scan_Client.SetupAsync(new TouchSocketConfig()
|
|
|
|
|
+ .SetSerialPortOption(new SerialPortOption()
|
|
|
|
|
+ {
|
|
|
|
|
+ BaudRate = res.BaudRate,//波特率
|
|
|
|
|
+ DataBits = res.DataBits,//数据位
|
|
|
|
|
+ Parity = res.Parity,//校验位
|
|
|
|
|
+ PortName = res.PortName,//COM
|
|
|
|
|
+ StopBits = res.StopBits//停止位
|
|
|
|
|
+ })
|
|
|
|
|
+ .SetSerialDataHandlingAdapter(() => new PeriodPackageAdapter() { CacheTimeout = TimeSpan.FromMilliseconds(100) })
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ await Scan_Client.ConnectAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (Scan_Client.Online)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage(Lang.扫码机已连接, MessageLevel.Debug);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage(Lang.扫码机未连接, MessageLevel.Debug);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage(Lang.请设置扫码机串口, MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("初始化扫码枪时出错!", ex);
|
|
|
|
|
+ SendTaskMessage(Lang.初始化扫码枪时出错 + ex.Message, MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 机器人指令执行
|
|
#region 机器人指令执行
|
|
|
|
|
|
|
|
public Dictionary<Guid, CancellationTokenSource> RobotTCPCollection = new Dictionary<Guid, CancellationTokenSource>();
|
|
public Dictionary<Guid, CancellationTokenSource> RobotTCPCollection = new Dictionary<Guid, CancellationTokenSource>();
|
|
|
|
|
+ public Dictionary<Guid, CancellationTokenSource> ScannerTCPCollection = new Dictionary<Guid, CancellationTokenSource>();
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 机器人TCP接收
|
|
/// 机器人TCP接收
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -684,6 +801,70 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 扫码枪TCP接收
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="arg1"></param>
|
|
|
|
|
+ /// <param name="arg2"></param>
|
|
|
|
|
+ /// <param name="arg3"></param>
|
|
|
|
|
+ private async void Management_ScannerReceivedEvent(Guid scannerid, object arg2, TouchSocket.Sockets.ReceivedDataEventArgs e)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!ScannerTCPCollection.ContainsKey(scannerid))
|
|
|
|
|
+ ScannerTCPCollection.Add(scannerid, new CancellationTokenSource());
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ScannerTCPCollection[scannerid].IsCancellationRequested)
|
|
|
|
|
+ {
|
|
|
|
|
+ ScannerTCPCollection[scannerid] = new CancellationTokenSource();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ var scanner = await _scannerService.GetScannerAsync(scannerid);
|
|
|
|
|
+ //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
|
|
|
|
|
+ var buffer = e.ByteBlock.Span.ToString(scanner.GetEncoding());
|
|
|
|
|
+ var reply = (buffer ?? string.Empty).Trim();
|
|
|
|
|
+ SendTaskMessage($"{scanner.Name}Received:{reply}", MessageLevel.Info);
|
|
|
|
|
+ // 只要有人在等扫码结果,就先完成等待(避免被下面 ExecuteAsync 干扰)
|
|
|
|
|
+ var tcs = _scanTcs;
|
|
|
|
|
+ if (tcs != null && !string.IsNullOrWhiteSpace(reply))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 只完成一次
|
|
|
|
|
+ tcs.TrySetResult(reply);
|
|
|
|
|
+ }
|
|
|
|
|
+ var _ = _remoteCommandService.ExecuteAsync(buffer, ScannerTCPCollection[scannerid].Token, async msg =>
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (scanner.ConnectType == TCPConnectType.Client)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (scanner.IsConnected)
|
|
|
|
|
+ {
|
|
|
|
|
+ await scanner.SendAsync($"{msg}");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ var cient = (ITcpSessionClient)arg2;
|
|
|
|
|
+ if (cient.Online)
|
|
|
|
|
+ {
|
|
|
|
|
+ await scanner.SendAsync(cient, $"{msg}");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("TCP发送数据时出错!", ex);
|
|
|
|
|
+ SendTaskMessage(ex.Message, MessageLevel.Alarm);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("处理扫码枪接收的命令时出错!", ex);
|
|
|
|
|
+ SendTaskMessage(ex.Message, MessageLevel.Alarm);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 机器人&Feeder&相机连接状态事件
|
|
#region 机器人&Feeder&相机连接状态事件
|
|
@@ -700,6 +881,19 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"{r.Name}Send:{arg3}", MessageLevel.Info);
|
|
SendTaskMessage($"{r.Name}Send:{arg3}", MessageLevel.Info);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 扫码枪发送事件
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="arg1"></param>
|
|
|
|
|
+ /// <param name="arg2"></param>
|
|
|
|
|
+ /// <param name="arg3"></param>
|
|
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
+ private void Management_ScannerSendEvent(Guid scannerid, object arg2, string arg3)
|
|
|
|
|
+ {
|
|
|
|
|
+ var r = _scannerService.GetScanner(scannerid);
|
|
|
|
|
+ SendTaskMessage($"{r.Name}Send:{arg3}", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 机器人断开连接时
|
|
/// 机器人断开连接时
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -746,6 +940,51 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 扫码枪断开连接时
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="arg1"></param>
|
|
|
|
|
+ /// <param name="arg2"></param>
|
|
|
|
|
+ /// <param name="arg3"></param>
|
|
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
+ private void Management_ScannerDisconnectedEvent(Guid scannerid, object arg2, ClosedEventArgs arg3)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ScannerTCPCollection.ContainsKey(scannerid))
|
|
|
|
|
+ {
|
|
|
|
|
+ ScannerTCPCollection[scannerid].Cancel();
|
|
|
|
|
+ }
|
|
|
|
|
+ var r = _configService.GetScanner(scannerid);
|
|
|
|
|
+ if (r.ConnectType == TCPConnectType.Server)
|
|
|
|
|
+ {
|
|
|
|
|
+ ITcpSessionClient socketClient = arg2 as ITcpSessionClient;
|
|
|
|
|
+ SendTaskMessage($"{r.ScannerName}[{socketClient.Id}:{socketClient.IP}]{Lang.断开连接}!", MessageLevel.Error);
|
|
|
|
|
+ var scanner = _scannerService.GetScanner(scannerid);
|
|
|
|
|
+ if (scanner.TcpService.Count < 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ var sta = Status.FirstOrDefault(s => s.ID == scannerid);
|
|
|
|
|
+ App.Current.Dispatcher.Invoke(new
|
|
|
|
|
+ Action(() =>
|
|
|
|
|
+ {
|
|
|
|
|
+ sta.Message = $"{r.ScannerName}{Lang.未连接}";
|
|
|
|
|
+ sta.Background = new SolidColorBrush(Colors.Red);
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"{r.ScannerName}{Lang.断开连接}!", MessageLevel.Error);
|
|
|
|
|
+ var sta = Status.FirstOrDefault(s => s.ID == scannerid);
|
|
|
|
|
+ App.Current.Dispatcher.Invoke(new
|
|
|
|
|
+ Action(() =>
|
|
|
|
|
+ {
|
|
|
|
|
+ sta.Message = $"{r.ScannerName}{Lang.断开连接}";
|
|
|
|
|
+ sta.Background = new SolidColorBrush(Colors.Red);
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 机器人连接成功时
|
|
/// 机器人连接成功时
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -788,6 +1027,47 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 扫码枪连接成功时
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="arg1"></param>
|
|
|
|
|
+ /// <param name="arg2"></param>
|
|
|
|
|
+ /// <param name="arg3"></param>
|
|
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
+ private void Management_ScannerConnectedEvent(Guid scannerid, object arg2, ConnectedEventArgs arg3)
|
|
|
|
|
+ {
|
|
|
|
|
+ var r = _configService.GetScanner(scannerid);
|
|
|
|
|
+ if (r.ConnectType == TCPConnectType.Server)
|
|
|
|
|
+ {
|
|
|
|
|
+ ITcpSessionClient socketClient = arg2 as ITcpSessionClient;
|
|
|
|
|
+ SendTaskMessage($"{r.ScannerName}[{socketClient.Id}:{socketClient.IP}]{Lang.已连接}!", MessageLevel.Debug);
|
|
|
|
|
+ var scanner = _scannerService.GetScanner(scannerid);
|
|
|
|
|
+ if (scanner.TcpService.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ var sta = Status.FirstOrDefault(s => s.ID == scannerid);
|
|
|
|
|
+ App.Current.Dispatcher.Invoke(new
|
|
|
|
|
+ Action(() =>
|
|
|
|
|
+ {
|
|
|
|
|
+ sta.Message = $"{r.ScannerName}{Lang.已连接}";
|
|
|
|
|
+ sta.Background = new SolidColorBrush(Colors.Green);
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"{r.ScannerName}{Lang.已连接}!", MessageLevel.Debug);
|
|
|
|
|
+ var sta = Status.FirstOrDefault(s => s.ID == scannerid);
|
|
|
|
|
+ App.Current.Dispatcher.Invoke(new
|
|
|
|
|
+ Action(() =>
|
|
|
|
|
+ {
|
|
|
|
|
+ sta.Message = $"{r.ScannerName}{Lang.已连接}";
|
|
|
|
|
+ sta.Background = new SolidColorBrush(Colors.Green);
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// Feeder连接状态改变时
|
|
/// Feeder连接状态改变时
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -1307,6 +1587,164 @@ namespace TeamAAS_VP.Core
|
|
|
if (targetPoint.CameraProcedureId8 != Guid.Empty && !procIds.Contains(targetPoint.CameraProcedureId8)) procIds.Add(targetPoint.CameraProcedureId8);
|
|
if (targetPoint.CameraProcedureId8 != Guid.Empty && !procIds.Contains(targetPoint.CameraProcedureId8)) procIds.Add(targetPoint.CameraProcedureId8);
|
|
|
}
|
|
}
|
|
|
catch { }
|
|
catch { }
|
|
|
|
|
+ var sysConfig = _configService.GetSystemConfiguration();
|
|
|
|
|
+ if (sysConfig.ScannerUse == true && cameraIndex == 1 && sysConfig.CodeUse2 == true)
|
|
|
|
|
+ {
|
|
|
|
|
+ ScanValue = "";
|
|
|
|
|
+ _scanDoneEvent.Reset(); // 重要:先关门
|
|
|
|
|
+
|
|
|
|
|
+ await Scan_Client.SendAsync("T\r\n");
|
|
|
|
|
+
|
|
|
|
|
+ // 等待扫码结果,最多 3 秒
|
|
|
|
|
+ bool scanOk = await Task.Run(() => _scanDoneEvent.Wait(3000));
|
|
|
|
|
+
|
|
|
|
|
+ if (!scanOk || ScanValue.IsNullOrWhiteSpace())
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage("二维码拍照失败或超时", MessageLevel.Alarm);
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (short)3);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ code = ScanValue;
|
|
|
|
|
+ SendTaskMessage($"扫码成功,SN:{code}", MessageLevel.Info);
|
|
|
|
|
+ //这里缺少从MES获取产品配方的内容,需要补充
|
|
|
|
|
+ _LastMesCheckTime[0] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
|
|
|
+ //_LastMesCheckTime[1] = DateTime.Now;
|
|
|
|
|
+ LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
|
|
|
+ SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
|
|
|
+ (bool isSuccess, string response) = await _mesService.StationGetAsync(code, "", 2);//询问mes
|
|
|
|
|
+
|
|
|
|
|
+ if (isSuccess)
|
|
|
|
|
+ {
|
|
|
|
|
+ //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
|
|
+
|
|
|
|
|
+ LogHelper.WriteLogMes($"询问mes成功");
|
|
|
|
|
+ SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
|
|
|
|
|
+ if (response != "MES功能未启用!")
|
|
|
|
|
+ {
|
|
|
|
|
+ string[] items = response.Split('\n');
|
|
|
|
|
+ if (items[3].Contains("sn="))
|
|
|
|
|
+ {
|
|
|
|
|
+ ProductMainSN = items[3].Replace("sn=", "");
|
|
|
|
|
+ _productService.CurrentProductCode = ProductMainSN;
|
|
|
|
|
+ }
|
|
|
|
|
+ SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
|
|
+ if (items[5].Contains("wo="))
|
|
|
|
|
+ {
|
|
|
|
|
+ wo = items[5].Replace("wo=", "");
|
|
|
|
|
+ }
|
|
|
|
|
+ SendTaskMessage($"产品wo:{wo}", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+ LogHelper.WriteLogMes($"【mes结束QUERY】");
|
|
|
|
|
+ SendTaskMessage($"mes结束QUERY", MessageLevel.Info);
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
|
|
+
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
|
|
+
|
|
|
|
|
+ LogHelper.WriteLogMes($"询问mes失败");
|
|
|
|
|
+ SendTaskMessage($"询问mes失败:{response}", MessageLevel.Error);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (sysConfig.ScannerUse == true && cameraIndex == 1 && sysConfig.CodeUse == true)
|
|
|
|
|
+ {
|
|
|
|
|
+ ScanValue = "";
|
|
|
|
|
+ _scanDoneEvent.Reset(); // 重要:先关门
|
|
|
|
|
+
|
|
|
|
|
+ await Scan_Client.SendAsync("T\r\n");
|
|
|
|
|
+
|
|
|
|
|
+ // 等待扫码结果,最多 3 秒
|
|
|
|
|
+ bool scanOk = await Task.Run(() => _scanDoneEvent.Wait(3000));
|
|
|
|
|
+
|
|
|
|
|
+ if (!scanOk || ScanValue.IsNullOrWhiteSpace())
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage("二维码拍照失败或超时", MessageLevel.Alarm);
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (short)3);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ code = ScanValue;
|
|
|
|
|
+ SendTaskMessage($"扫码成功,SN:{code}", MessageLevel.Info);
|
|
|
|
|
+ //这里缺少从MES获取产品配方的内容,需要补充
|
|
|
|
|
+ _LastMesCheckTime[0] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
|
|
|
+ LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
|
|
|
+ SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
|
|
|
+ //(bool isSuccess, string response) = await _mesService.StationGetAsync(code, "", 2);//询问mes
|
|
|
|
|
+ (bool isSuccess, string response) = await _mesService.StationGetExAsync(code, "", 2);//基于电池的SN获取产品SN,询问mes
|
|
|
|
|
+ if (isSuccess)
|
|
|
|
|
+ {
|
|
|
|
|
+ //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ string ProductMainSN_Temp = "";
|
|
|
|
|
+ LogHelper.WriteLogMes($"询问mes成功");
|
|
|
|
|
+ SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
|
|
|
|
|
+
|
|
|
|
|
+ if (response != "MES功能未启用!")
|
|
|
|
|
+ {
|
|
|
|
|
+ string[] item = response.Split('\n');
|
|
|
|
|
+ if (item[2].Contains("sn="))
|
|
|
|
|
+ {
|
|
|
|
|
+ ProductMainSN_Temp = item[2].Replace("sn=", "");
|
|
|
|
|
+ SendTaskMessage($"sn:{ProductMainSN_Temp}", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ LogHelper.WriteLogMes($"询问mes成功");
|
|
|
|
|
+ SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
|
|
|
|
|
+
|
|
|
|
|
+ //20260214,特别版(电池组装)
|
|
|
|
|
+ (bool isSuccess2, string response2) = await _mesService.StationGetAsync(ProductMainSN_Temp, "", 2);//询问mes
|
|
|
|
|
+ if (isSuccess2)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogMes($"询问mes成功");
|
|
|
|
|
+ SendTaskMessage($"询问mes成功:{response2}", MessageLevel.Debug);
|
|
|
|
|
+
|
|
|
|
|
+ if (response2 != "MES功能未启用!")
|
|
|
|
|
+ {
|
|
|
|
|
+ string[] item = response2.Split('\n');
|
|
|
|
|
+ if (item[3].Contains("sn="))
|
|
|
|
|
+ {
|
|
|
|
|
+ ProductMainSN = item[3].Replace("sn=", "");
|
|
|
|
|
+ _productService.CurrentProductCode = ProductMainSN;
|
|
|
|
|
+ SendTaskMessage($"产品主sn:{ProductMainSN}", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (item[5].Contains("wo="))
|
|
|
|
|
+ {
|
|
|
|
|
+ wo = item[5].Replace("wo=", "");
|
|
|
|
|
+ SendTaskMessage($"产品主wo:{wo}", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ LogHelper.WriteLogMes($"第二次询问mes成功");
|
|
|
|
|
+ SendTaskMessage($"第二次询问mes成功:{response2}", MessageLevel.Debug);
|
|
|
|
|
+
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogMes($"第二次询问mes失败");
|
|
|
|
|
+ SendTaskMessage($"第二次询问mes失败:{response2}", MessageLevel.Error);
|
|
|
|
|
+
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
|
|
|
|
|
+
|
|
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
|
|
+
|
|
|
|
|
+ LogHelper.WriteLogMes($"询问mes失败");
|
|
|
|
|
+ SendTaskMessage($"询问mes失败:{response}", MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if (procIds.Count == 0)
|
|
if (procIds.Count == 0)
|
|
|
{
|
|
{
|
|
@@ -1337,7 +1775,7 @@ namespace TeamAAS_VP.Core
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var sysConfig = _configService.GetSystemConfiguration();
|
|
|
|
|
|
|
+
|
|
|
if (sysConfig.CodeUse==true && cameraIndex == 1)
|
|
if (sysConfig.CodeUse==true && cameraIndex == 1)
|
|
|
{
|
|
{
|
|
|
var cts = new CancellationTokenSource();
|
|
var cts = new CancellationTokenSource();
|
|
@@ -1458,7 +1896,6 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"扫码失败", MessageLevel.Alarm);
|
|
SendTaskMessage($"扫码失败", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1553,12 +1990,8 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"扫码失败", MessageLevel.Alarm);
|
|
SendTaskMessage($"扫码失败", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)3);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
foreach (var prcId in procIds)
|
|
foreach (var prcId in procIds)
|
|
|
{
|
|
{
|
|
|
if (Is3D(prcId))
|
|
if (Is3D(prcId))
|
|
@@ -1675,7 +2108,11 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
|
//这里缺少从MES获取产品配方的内容,需要补充
|
|
//这里缺少从MES获取产品配方的内容,需要补充
|
|
|
_LastMesCheckTime[i] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
_LastMesCheckTime[i] = (await _mesService.GetServerTimeAsync(code, 2)).Now;
|
|
|
-
|
|
|
|
|
|
|
+ if (homeview.IsNoCode == false)
|
|
|
|
|
+ {
|
|
|
|
|
+ var device = _configService.GetDeviceInfo();
|
|
|
|
|
+ code = device.XnSN;
|
|
|
|
|
+ }
|
|
|
LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
LogHelper.WriteLogMes($"【mes开始QUERY】");
|
|
|
SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
SendTaskMessage($"mes开始QUERY", MessageLevel.Info);
|
|
|
ShowMes_Query = false;
|
|
ShowMes_Query = false;
|
|
@@ -1954,7 +2391,18 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
|
|
string[] strpoints1 = visionResult.Items[i].Split(',');
|
|
string[] strpoints1 = visionResult.Items[i].Split(',');
|
|
|
lockResult1.PhotoName = strpoints1[0];
|
|
lockResult1.PhotoName = strpoints1[0];
|
|
|
- lockResult1.ResultData = strpoints1[1];
|
|
|
|
|
|
|
+ string[] body1 = strpoints1[1].Split(";");
|
|
|
|
|
+ string body2 = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (body1.Length == 8)
|
|
|
|
|
+ {
|
|
|
|
|
+ body2 = $"{body1[0]},{body1[2]},{body1[4]},{body1[6]}";
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ body2 = strpoints1[1];
|
|
|
|
|
+ }
|
|
|
|
|
+ lockResult1.ResultData = body2;
|
|
|
lockResult1.PhotoCode = ProductMainSN;
|
|
lockResult1.PhotoCode = ProductMainSN;
|
|
|
var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
|
if (globalParam != null)
|
|
if (globalParam != null)
|
|
@@ -2113,7 +2561,18 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
|
|
string[] strpoints1 = visionResult.Items[i].Split(',');
|
|
string[] strpoints1 = visionResult.Items[i].Split(',');
|
|
|
lockResult1.PhotoName = strpoints1[0];
|
|
lockResult1.PhotoName = strpoints1[0];
|
|
|
- lockResult1.ResultData = strpoints1[1];
|
|
|
|
|
|
|
+ string[] body1 = strpoints1[1].Split(";");
|
|
|
|
|
+ string body2 = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (body1.Length == 8)
|
|
|
|
|
+ {
|
|
|
|
|
+ body2 = $"{body1[0]},{body1[2]},{body1[4]},{body1[6]}";
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ body2 = strpoints1[1];
|
|
|
|
|
+ }
|
|
|
|
|
+ lockResult1.ResultData = body2;
|
|
|
lockResult1.PhotoCode = ProductMainSN;
|
|
lockResult1.PhotoCode = ProductMainSN;
|
|
|
var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
var globalParam = currentProduct.GlobalParamListCollection.FirstOrDefault(p => p.Name == strpoints1[0]);
|
|
|
if (globalParam != null)
|
|
if (globalParam != null)
|
|
@@ -2560,6 +3019,70 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
|
|
// return true;
|
|
// return true;
|
|
|
//}
|
|
//}
|
|
|
|
|
+ // ====== 新增:最简等待:TCS + 超时(比 SemaphoreSlim + CurrentCount 轮询更轻、更可靠)======
|
|
|
|
|
+ private async Task<string> ScanT1Async(int timeoutMs)
|
|
|
|
|
+ {
|
|
|
|
|
+ var scannerId = GetDefaultScannerId();
|
|
|
|
|
+ if (scannerId == Guid.Empty) return null;
|
|
|
|
|
+
|
|
|
|
|
+ var scanner = _scannerService.GetScanner(scannerId);
|
|
|
|
|
+ if (scanner == null || !scanner.IsConnected) return null;
|
|
|
|
|
+
|
|
|
|
|
+ // 关键:先注册等待,再发送 T1,避免“回包先到”导致丢信号
|
|
|
|
|
+ var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
|
|
|
+ _scanTcs = tcs;
|
|
|
|
|
+
|
|
|
|
|
+ await scanner.SendAsync("T1").ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
+ var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs)).ConfigureAwait(false);
|
|
|
|
|
+ if (completed != tcs.Task)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 超时:清掉本次等待,避免下次误用
|
|
|
|
|
+ if (ReferenceEquals(_scanTcs, tcs)) _scanTcs = null;
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var reply = await tcs.Task.ConfigureAwait(false);
|
|
|
|
|
+ if (ReferenceEquals(_scanTcs, tcs)) _scanTcs = null;
|
|
|
|
|
+ return reply;
|
|
|
|
|
+ }
|
|
|
|
|
+ private Guid GetDefaultScannerId()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_defaultScannerId != Guid.Empty) return _defaultScannerId;
|
|
|
|
|
+
|
|
|
|
|
+ var scannerInfo = _configService.GetAllScanners()
|
|
|
|
|
+ .OrderBy(s => s.ScannerNo)
|
|
|
|
|
+ .FirstOrDefault();
|
|
|
|
|
+
|
|
|
|
|
+ _defaultScannerId = scannerInfo == null ? Guid.Empty : scannerInfo.Id;
|
|
|
|
|
+ return _defaultScannerId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private async Task Scan_DataReceived(ISerialPortClient client, ReceivedDataEventArgs e)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // 串口名
|
|
|
|
|
+ string portName = client.MainSerialPort.PortName;
|
|
|
|
|
+ // 注意:DataReceived 可能一次收到多段/包含回车换行
|
|
|
|
|
+ string data = e.ByteBlock.Span.ToString(Encoding.ASCII);
|
|
|
|
|
+ await Console.Out.WriteLineAsync(data);
|
|
|
|
|
+ // 取第一段(到 \r 之前),并去掉首尾空白
|
|
|
|
|
+ string response = data.Split('\r')[0].Trim();
|
|
|
|
|
+ // 过滤:空数据不要当成一次有效扫码
|
|
|
|
|
+ if (string.IsNullOrWhiteSpace(response))
|
|
|
|
|
+ return;
|
|
|
|
|
+ SendTaskMessage($"扫码机:{portName} Receive:{response}", MessageLevel.Info);
|
|
|
|
|
+ // 写入结果
|
|
|
|
|
+ ScanValue = response;
|
|
|
|
|
+ // 通知等待方继续执行(PLC 逻辑里 Wait 的地方)
|
|
|
|
|
+ _scanDoneEvent.Set();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("扫码枪接收信息时出错!", ex);
|
|
|
|
|
+ SendTaskMessage(Lang.扫码枪接收信息时出错 + ex.Message, MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|