I am reading data from a police scanner using C# and serial ports (USB to Serial). When I view the data in a different program there's no problem. When I use the following code I get repeat (duplicate) lines for everything. What am I doing wrong?
SerialPort _sp = new SerialPort();
_sp.BaudRate = 115000;
_sp.DataBits = 8;
_sp.Parity = Parity.None;
_sp.StopBits = StopBits.One;
and the function to start serial port reading...
public void StartSerial()
{
_sp.PortName = comboPorts.SelectedItem.ToString();
_sp.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
_sp.Open();
}
and the read function...
private void serialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
String strLine = _sp.ReadLine();
// Handle Data
}
catch { }
}
The manual states the following is required:
To view CCDump data, connect the radio to a personal computer using the USB PC/IF cable. Start a terminal program or your third party application software. Configure the communications parameters for “115200, N, 8, 1” as follows:
COM Port: The COM port number assigned to the USB cable by your computer. If you are running a Windows operating system, you can find this information under “Ports” in the Device Manager.
Parity: None
Baud Rate: 115,000 bits per second
Word: 8 bits
Stop Bits: 1