Rob

Rob

  • NA
  • 1
  • 0

Serial Port Event

Nov 14 2006 2:27 AM
Hi everyone, I'm having a lot of trouble with the events of my serial com port. This is the peace of code I wrote: using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; using System.Windows.Forms; namespace Demo.Device.NetworkLayer.Stack { public class BTPortControl { SerialPort SPCOM1 = new SerialPort(); public BTPortControl() { SPCOM1.PortName = "COM1"; SPCOM1.BaudRate = 115200; SPCOM1.Parity = Parity.None; SPCOM1.DataBits = 8; SPCOM1.StopBits = StopBits.One; SPCOM1.Handshake = Handshake.RequestToSend; SPCOM1.DtrEnable = false; SPCOM1.ReadBufferSize = 4096; SPCOM1.WriteBufferSize = 2048; SPCOM1.ParityReplace = 63; //Enable Event handler SPCOM1.DataReceived += new serialDataReceivedEventHandler(COM1_DataReceived); } public void COM1Open() { SPCOM1.Open(); } public void COM1Close() { SPCOM1.Close(); } public void COM1_DataReceived(object sender, SerialDataReceivedEventArgs e) { Mainwindow.Instance.UpdateStatusBox(SPCOM1.ReadExisting()); } } } When I send data to the serialport, I wait for a response, the COM1_DataReceived event is raised once, so I only see one line of data in my Status Box. After that, I don't receive any more data from that event. Can someone tell me what i'm doing wrong? Thanks guys! :D

Answers (1)