G
G-Oker
Guest
Hello,
I'm trying to listen to a telephone system connected to a usb-to-serial connector.
Using ReadExisting I can see every char, but I would like every line (so I can then extrapolate the data out of it).
I have tried ReadLine instead, but my interface dosn't display any data.
I think this is because the feed isn't sending a \r\n (or 0x0d 0x0a)to represent an EoL (so , its listening to find an end of a call, but dosn't find the delimiter).
NB: Manuals on the phone system seem hard to find (to locate what the EoL char is )
is this the correct way, or is there a better way of getting the data "per line" ?
I am currently using this code:
class Program
{
public static void Main()
{
/// create serial port to listen to
SerialPort mySerialPort = new SerialPort("COM4");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.XOnXOff;
mySerialPort.RtsEnable = true;
/// Intercept data method
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
/// Open (above) port
//mySerialPort.DtrEnable = true;
mySerialPort.Open();
/// Close the port
Console.WriteLine("Press any key to stop listening...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
/// "Reads all immediately available bytes, based on the encoding, in both the stream and the input buffer of the SerialPort object" - MS.
string indata = sp.ReadExisting();
/// doesn't work (no \r\n?). - "ReadLine() method will return when the port receives a carriage return and line feed byte combination by default on Windows. Or \r\n, or 0x0d 0x0a if you prefer." - SO
//string indata = sp.ReadLine();
Console.Write(indata);
}
}
Thank you
Continue reading...
I'm trying to listen to a telephone system connected to a usb-to-serial connector.
Using ReadExisting I can see every char, but I would like every line (so I can then extrapolate the data out of it).
I have tried ReadLine instead, but my interface dosn't display any data.
I think this is because the feed isn't sending a \r\n (or 0x0d 0x0a)to represent an EoL (so , its listening to find an end of a call, but dosn't find the delimiter).
NB: Manuals on the phone system seem hard to find (to locate what the EoL char is )
is this the correct way, or is there a better way of getting the data "per line" ?
I am currently using this code:
class Program
{
public static void Main()
{
/// create serial port to listen to
SerialPort mySerialPort = new SerialPort("COM4");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.XOnXOff;
mySerialPort.RtsEnable = true;
/// Intercept data method
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
/// Open (above) port
//mySerialPort.DtrEnable = true;
mySerialPort.Open();
/// Close the port
Console.WriteLine("Press any key to stop listening...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
/// "Reads all immediately available bytes, based on the encoding, in both the stream and the input buffer of the SerialPort object" - MS.
string indata = sp.ReadExisting();
/// doesn't work (no \r\n?). - "ReadLine() method will return when the port receives a carriage return and line feed byte combination by default on Windows. Or \r\n, or 0x0d 0x0a if you prefer." - SO
//string indata = sp.ReadLine();
Console.Write(indata);
}
}
Thank you
Continue reading...