public IoTSendStringAsyncSocket(INetworkBaseWrapper networkWrapper, IoTControlServiceData serviceData, CancellationToken?cancelToken, int timeOutMs = 4000) : base(cancelToken, timeOutMs) { _serviceData = serviceData; _networkWrapper = networkWrapper; _networkWrapper.DataReceived += NetworkWrapper_DataReceived; }
public async Task <WcfResultInfo> ControlDevice(IoTControlServiceData serviceData) { var task = await DispatcherHelper.UIDispatcher.InvokeAsync(async() => { var mainViewModel = (MainViewModel)DataContext; var ioTSocketInfo = mainViewModel.IoTSocketInfos.FirstOrDefault(s => s.SignName == serviceData.SignName); if ((ioTSocketInfo != null) && !ioTSocketInfo.IsOpenScoket) { return(new WcfResultInfo { ErrorMsg = SendWcfCommandHelper.ErrorInfoForNotOpenSocketPort }); } var plc = ioTSocketInfo?.IoTInfos.FirstOrDefault(s => s.DeviceNumber == serviceData.DeviceNumber); if (plc != null) { var result = await plc.ControlPLC(serviceData); return(new WcfResultInfo { Data = result }); } return(new WcfResultInfo { ErrorMsg = SendWcfCommandHelper.ErrorInfoForNoDevices }); }); return(task.Result); }
public void RegistControlDeviceEx(string key, IoTControlServiceData serviceData, ITLAutoDevicePushCallback callBack) { DispatcherHelper.CheckBeginInvokeOnUI(() => { var mainViewModel = (MainViewModel)DataContext; var ioTSocketInfo = mainViewModel.IoTSocketInfos.FirstOrDefault(s => s.SignName == serviceData.SignName); if ((ioTSocketInfo != null) && ioTSocketInfo.IsOpenScoket) { ioTSocketInfo.Add(key, serviceData, callBack); } }); }
public static async Task <WcfResultInfo> Send(IoTControlServiceData serviceData) { var sendWcfCommand = new SendWcfCommandEx(IoTDeviceService.GetIoTDeviceService().WcfServiceAddress); sendWcfCommand.Error += SendWcfCommand_Error; sendWcfCommand.CommunicationError += SendWcfCommand_CommunicationError; sendWcfCommand.TimeoutError += SendWcfCommand_TimeoutError; var result = await sendWcfCommand.SendEx(IoTDeviceService.Key, serviceData.ToBytes()); sendWcfCommand.Error -= SendWcfCommand_Error; sendWcfCommand.CommunicationError -= SendWcfCommand_CommunicationError; sendWcfCommand.TimeoutError -= SendWcfCommand_TimeoutError; return(result); }