/// <summary> /// inicia la escucha del puerto COM /// seleccionado. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void iniciarLoggerToolStripMenuItem_Click(object sender, EventArgs e) { COMPort.PortName = Properties.Settings.Default.COMPort; COMPort.NewDataReceived += new SerialCommunication.DataReceivedEventHandler(onSerialPortDataReceived); COMPort.Open(); }
public void ThrowsExceptionOnNonExistingSerial() { Mock <ILibc> mock = new Mock <ILibc>(); mock.Setup(o => o.Open(It.IsAny <string>(), It.IsAny <Libc.OpenFlags>())).Returns(-1); SerialCommunication serial = new SerialCommunication(mock.Object); Assert.Throws <SerialNotFoundException>(() => serial.Open("dummy")); }
public void RunsWithExistingSerial() { Mock <ILibc> mock = new Mock <ILibc>(); mock.Setup(o => o.Open(It.IsAny <string>(), It.IsAny <Libc.OpenFlags>())).Returns(1); SerialCommunication serial = new SerialCommunication(mock.Object); Assert.DoesNotThrow(() => serial.Open("dummy")); }
public void Connect() { this.connectingTimer.Start(); this.connState = CONN_STATE.CONNECTING; this.ConnStateChanged(this, EventArgs.Empty); if (!serial.Open()) { this.connState = CONN_STATE.DISCONNECTED; this.ConnStateChanged(this, EventArgs.Empty); disconnectedTimer.Start(); } }
public void Connect() { this.connectingTimer.Start(); if (!serial.Open()) { if (this.connState != CONN_STATE.DISCONNECTED) { this.connState = CONN_STATE.DISCONNECTED; this.ConnectionStateChanged(connState); } this.connState = CONN_STATE.DISCONNECTED; disconnectedTimer.Start(); } else { this.connState = CONN_STATE.CONNECTED; } }
public void ReadsData() { string targetString = "OK"; byte[] bytes = Encoding.ASCII.GetBytes(targetString + '\0'); Mock <ILibc> mock = new Mock <ILibc>(); mock.Setup(o => o.Read(It.IsAny <int>(), It.IsAny <IntPtr>(), It.IsAny <IntPtr>())) .Returns(new IntPtr(1)) .Callback <int, IntPtr, IntPtr>((i, p, c) => Marshal.Copy(bytes, 0, p, bytes.Length)); SerialCommunication serial = new SerialCommunication(mock.Object); serial.Open("dummy"); string received = serial.ReadOnce(); Assert.AreEqual(targetString, received); }
private void buttonConnect_Click(object sender, EventArgs e) { Int32 baudRate = 0; try { baudRate = Int32.Parse(textBaudRate.Text); } catch (Exception) { MessageBox.Show("Invalid Baud Rate."); return; } try { serialComm = new SerialCommunication(textPortName.Text, baudRate); serialComm.AddReceiveHandler(SerialDataReceived); serialComm.Open(); if (serialComm.Connected == false) { throw new Exception(); } } catch (Exception) { MessageBox.Show("Cannot connect to " + textPortName.Text); serialComm.Dispose(); serialComm = null; return; } keyBuffers[0] = keyBuffers[1] = 0xFF; buttonConnect.Enabled = false; buttonDisconnect.Enabled = true; buttonRequest.Enabled = true; checkAutorequest.Enabled = true; }