u2envy1
December 11th, 2007, 03:22 AM
How do I check if a device is connected to a serialport COM1.
This is my code.....
try
{
//bool scannerStatus = sp.DsrHolding;
byte[] buffer = new byte[10];
using (SerialPort sp = new SerialPort("COM1", 19200))
{
sp.Open();
sp.RtsEnable = true;
//sp.ReadTimeout = 8000;
//read directly
sp.Read(buffer, 0, (int)buffer.Length);
//read using a Stream
sp.BaseStream.Read(buffer, 0, (int)buffer.Length);
string scannerStatus = sp.Handshake.ToString();
//bool scannerStatus = sp.DtrEnable;
//sp.Close();
if (buffer[0] != 0)
{
txtScanner.Text = "Working";
}
}
}
catch (Exception ex)
{
string Error = ex.ToString();
}
finally
{
SerialPort sp = new SerialPort("COM1", 19200);
sp.Close();
}
This is my code.....
try
{
//bool scannerStatus = sp.DsrHolding;
byte[] buffer = new byte[10];
using (SerialPort sp = new SerialPort("COM1", 19200))
{
sp.Open();
sp.RtsEnable = true;
//sp.ReadTimeout = 8000;
//read directly
sp.Read(buffer, 0, (int)buffer.Length);
//read using a Stream
sp.BaseStream.Read(buffer, 0, (int)buffer.Length);
string scannerStatus = sp.Handshake.ToString();
//bool scannerStatus = sp.DtrEnable;
//sp.Close();
if (buffer[0] != 0)
{
txtScanner.Text = "Working";
}
}
}
catch (Exception ex)
{
string Error = ex.ToString();
}
finally
{
SerialPort sp = new SerialPort("COM1", 19200);
sp.Close();
}