469,592 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Reacting on events from IO.Port on WebSite

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

May 2 '07 #1
5 1586
Where is the port you want to read from, on the client or on the server?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Maciej Sondej" <ma***********@onet.euwrote in message
news:f1**********@news.onet.pl...
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



May 2 '07 #2
Of course on the server. I want to react on messages from IO.Port(which is
conneted to server) so I could update some object on the website.

BR
Maciek
Użytkownik "Eliyahu Goldin" <RE**************************@mMvVpPsS.org>
napisał w wiadomości news:ur**************@TK2MSFTNGP02.phx.gbl...
Where is the port you want to read from, on the client or on the server?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Maciej Sondej" <ma***********@onet.euwrote in message
news:f1**********@news.onet.pl...
>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




May 2 '07 #3
A web application will run only in response to a client request. When the
application runs, it can read the port in the same way as the console
application. You can make a code library with all port access methods and
call it from your web page code-behind. You will have a textbox on your page
and will assign to it value as

myTextBox.Text = myCodeLibrary.myMethodThatGetsDataFromThePort();

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Maciej Sondej" <ma***********@onet.euwrote in message
news:f1**********@news.onet.pl...
Of course on the server. I want to react on messages from IO.Port(which is
conneted to server) so I could update some object on the website.

BR
Maciek
Użytkownik "Eliyahu Goldin" <RE**************************@mMvVpPsS.org>
napisał w wiadomości news:ur**************@TK2MSFTNGP02.phx.gbl...
>Where is the port you want to read from, on the client or on the server?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Maciej Sondej" <ma***********@onet.euwrote in message
news:f1**********@news.onet.pl...
>>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





May 2 '07 #4
Hi,
Thank you for your response. It isn't exactly what I wanted, but this
solution is also good.

BR
Maciek

Użytkownik "Eliyahu Goldin" <RE**************************@mMvVpPsS.org>
napisał w wiadomości news:O1**************@TK2MSFTNGP06.phx.gbl...
>A web application will run only in response to a client request. When the
application runs, it can read the port in the same way as the console
application. You can make a code library with all port access methods and
call it from your web page code-behind. You will have a textbox on your
page and will assign to it value as

myTextBox.Text = myCodeLibrary.myMethodThatGetsDataFromThePort();

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Maciej Sondej" <ma***********@onet.euwrote in message
news:f1**********@news.onet.pl...
>Of course on the server. I want to react on messages from IO.Port(which
is conneted to server) so I could update some object on the website.

BR
Maciek
Użytkownik "Eliyahu Goldin" <RE**************************@mMvVpPsS.org>
napisał w wiadomości news:ur**************@TK2MSFTNGP02.phx.gbl...
>>Where is the port you want to read from, on the client or on the server?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Maciej Sondej" <ma***********@onet.euwrote in message
news:f1**********@news.onet.pl...
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_DataReceive d);

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





May 2 '07 #5
you need to change your model a little bit. the client can only poll the
server, not recieve events. this means you need a background thread that
monitors the serial port and buffers the input. the web page request can
then look at the buffered data.

you probably want this thread in a service rather an an asp.net thread,
as asp.net applications do not start until a request, and auto shutdown
after a timeout.

-- bruce (sqlwork.com)

Maciej Sondej wrote:
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


May 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Marco Martin | last post: by
reply views Thread by BigAl.NZ | last post: by
reply views Thread by guyarkam | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.