public void SelectPortAsync(ISerialPortContainer portContainer, Action <Exception> comPortOpenedCallbackAction) { //_logger.Log("Закрытие ранее открытого порта (если был открыт) и открытие нового: " + portContainer, null); _backgroundWorker.AddWork(() => { Exception exception; try { if (_portContainer != null && _portContainer.IsOpen) { ClosePortSyncUnsafe(); } _portContainer = portContainer; _portContainer.Open(); _sendAbility = portContainer; _portContainerWithProgress = _portContainer as ISerialPortContainerWithProgress; exception = null; } catch (Exception ex) { exception = ex; } if (comPortOpenedCallbackAction != null) { _notifyWorker.AddWork(() => comPortOpenedCallbackAction(exception)); } }); }
private void SerialChannelOnCommandHearedWithReplyPossibility(ICommandPart commandPart, ISendAbility sendAbility) { // TODO: RecordVm or not? //RecordVm.ReceiveCommand(commandPart.Address, commandPart.CommandCode, commandPart.ReplyBytes); }
private void SerialChannelOnCommandHearedWithReplyPossibility(ICommandPart commandPart, ISendAbility sendability) { if (commandPart.Address == 20) { if (commandPart.CommandCode == 33 && commandPart.ReplyBytes.Length == 8) { ReplyAcceptor.AcceptReply(commandPart.ReplyBytes); var reply = ReplyGenerator.GenerateReply(); sendability.Send(reply); //Console.WriteLine("Sended reply"); } } }