Reacting on events from IO.Port on WebSite

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
 
M

Maciej Sondej

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 said:
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 said:
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
 
E

Eliyahu Goldin

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 said:
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 said:
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 said:
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
 
M

Maciej Sondej

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 said:
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 said:
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 said:
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


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
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top