M
Maciej Sondej
Hi,
I have problem. I want to react on event which come from IO.Port(RS232). I
have a class that works on console application
class Program
{
static void Main(string[] args)
{
SerialPortProgram s = new SerialPortProgram();
}
internal static void Run()
{
while(true)
// do nothing
}
}
class SerialPortProgram
{
private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8,
StopBits.One);
public SerialPortProgram()
{
string text1 = "A";
Console.WriteLine("Incoming Data:");
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
WriteToPort(text1);
Program.Run(); // ---- the thread is running so I could recive data from
IO.Port ----
}
[STAThread]
public int WriteToPort(string s)
{
port.Write(s);
return 1;
}
public void ClosePort()
{
port.Close();
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine(port.ReadExisting());
}
}
[STAThread]
public int WriteToPort(string s)
{
port.Write(s);
return 1;
}
public void ClosePort()
{
port.Close();
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine(port.ReadExisting());
}
}
And I don't know how to display recived data from the
port(port.ReadExisting()) for egzample in asp:TextBox.
Can anyone help me?
Thanks for any insight,
Maciek
I have problem. I want to react on event which come from IO.Port(RS232). I
have a class that works on console application
class Program
{
static void Main(string[] args)
{
SerialPortProgram s = new SerialPortProgram();
}
internal static void Run()
{
while(true)
// do nothing
}
}
class SerialPortProgram
{
private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8,
StopBits.One);
public SerialPortProgram()
{
string text1 = "A";
Console.WriteLine("Incoming Data:");
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
WriteToPort(text1);
Program.Run(); // ---- the thread is running so I could recive data from
IO.Port ----
}
[STAThread]
public int WriteToPort(string s)
{
port.Write(s);
return 1;
}
public void ClosePort()
{
port.Close();
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine(port.ReadExisting());
}
}
[STAThread]
public int WriteToPort(string s)
{
port.Write(s);
return 1;
}
public void ClosePort()
{
port.Close();
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine(port.ReadExisting());
}
}
And I don't know how to display recived data from the
port(port.ReadExisting()) for egzample in asp:TextBox.
Can anyone help me?
Thanks for any insight,
Maciek