public TestSymmetricCommunicationChannel(Configuration configuration) { _receiver = new TestBaseSimmetricEncryptedCommunicationChannelReceiver(configuration); _receiver.OpenPortRequestReceived += (sender, data) => ReceivedRequest = data.Request; _sender = new TestBaseSimmetricEncryptedCommunicationChannelSender(_receiver, d => SentData = d); }
/// <summary> /// Open Serial port configurations /// </summary> public OpenPortResponse OpenPort(OpenPortRequest request) { try { request.Device.SerialPort.PortName = request.Device.DeviceInfo.ComPortName; //COM1 request.Device.SerialPort.BaudRate = Settings.BaudRate; //9600 || 115200 -> default request.Device.SerialPort.DataBits = 8; //8 -> default request.Device.SerialPort.StopBits = StopBits.One; //1 -> default request.Device.SerialPort.Parity = Parity.None; //None -> default request.Device.SerialPort.ReadTimeout = Settings.ReadTimeout; //300 -> default request.Device.SerialPort.WriteTimeout = Settings.WriteTimeout; //300 -> default request.Device.SerialPort.Encoding = Encoding.GetEncoding("iso-8859-1"); request.Device.SerialPort.DataReceived += PortDataReceived; request.Device.SerialPort.Open(); request.Device.SerialPort.DtrEnable = true; request.Device.SerialPort.RtsEnable = true; } catch (Exception ex) { throw new SerialPortException("SerialPort Open Error", ex); } OpenPortResponse response = new OpenPortResponse(); response.CompleteRunAfter(request); return(response); }
public OpenPortResponse OpenPort(OpenPortRequest request) { Stopwatch cron = new Stopwatch(); cron.Start(); OpenPortResponse response = new OpenPortResponse(); try { // double value = 23.0 / 0.0; response.Content = System.IO.File.ReadAllBytes(request.Filename); response.Success = true; } catch (Exception ex) { //response.Exception = ex; response.ExceptionMessage = ex.Message; response.Success = false; var errDto = new ErrorDto(); errDto.Message = ex.Message; errDto.Severity = 2; errDto.StackTrace = ex.StackTrace; throw new FaultException <ErrorDto>(errDto, new FaultReason(ex.Message)); } finally { cron.Stop(); response.Interval = cron.Elapsed; } return(response); }
public void ShouldOpenComPort() { //Arrange string comPortName = "COM10"; OpenPortRequest request = new OpenPortRequest { Device = new Device { DeviceInfo = new DeviceInfo { ComPortName = comPortName } } }; IATCommandService service = new ATCommandService(); //Act try { service.OpenPort(request); //Assert Assert.IsTrue(true); } catch (Exception) { //Assert Assert.Fail(); } }
internal void SendOpenPortRequest(OpenPortRequest openPortRequest, string password) { _sender.SendOpenPortRequest(openPortRequest, password); }
private void DataReceived(object sender, OpenPortRequestEventArgs e) { ReceivedRequest = e.Request; }