internal ComPortCommunicator() { copyFileCommandExecutor = new CopyFileCommandExecutor(); ComPortConfigurationBuilder builder = new ComPortConfigurationBuilder(); Configuration = builder.BuildComPort(); serialPort = new SerialPort(); serialPort.BaudRate = Configuration.BaudRate; serialPort.DataBits = Configuration.DataBits; serialPort.Handshake = Configuration.Handshake; serialPort.Parity = Configuration.Parity; serialPort.PortName = Configuration.PortName; serialPort.StopBits = Configuration.StopBits; try { serialPort.DtrEnable = true; } catch { } try { serialPort.RtsEnable = true; } catch { } serialPort.ReadTimeout = Configuration.ReadTimeOut; serialPort.WriteTimeout = Configuration.WriteTimeOut; serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); }
//TODO: Just for testing purpose. internal void SendHelloWorld() { SerialPort com1Port = new SerialPort(); ComPortConfigurationBuilder builder = new ComPortConfigurationBuilder(); Configuration = builder.BuildComPort(); serialPort = new SerialPort(); com1Port.BaudRate = Configuration.BaudRate; com1Port.DataBits = Configuration.DataBits; com1Port.Handshake = Configuration.Handshake; com1Port.Parity = Configuration.Parity; com1Port.PortName = "COM1"; com1Port.StopBits = Configuration.StopBits; try { com1Port.DtrEnable = true; } catch { } try { com1Port.RtsEnable = true; } catch { } com1Port.ReadTimeout = Configuration.ReadTimeOut; com1Port.WriteTimeout = Configuration.WriteTimeOut; if (com1Port.IsOpen == false) com1Port.Open(); com1Port.Write("data"); com1Port.Close(); }