ASP.NET Tutorial/Development/Serial Port

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Writing text to the serial port (C#)

   <source lang="csharp">

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> System.IO.Ports.SerialPort SerialPort1 = new System.IO.Ports.SerialPort();

protected void Page_Load(object sender, EventArgs e) {

   this.SerialPort1.PortName = "COM1";
   if (!this.SerialPort1.IsOpen)
   {
       this.SerialPort1.Open();
   }
   this.SerialPort1.Write("Hello World");
   this.SerialPort1.Close();

} </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Untitled Page</title>

</head> <body>

   <form id="form1" runat="server">
 
   </form>

</body> </html></source>


Writing text to the serial port (VB)

   <source lang="csharp">

<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">

   Dim SerialPort1 As New System.IO.Ports.SerialPort()
   
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
       
       Me.SerialPort1.PortName = "COM1"
       If (Not Me.SerialPort1.IsOpen) Then
           Me.SerialPort1.Open()
       End If
       Me.SerialPort1.Write("Hello World")
       Me.SerialPort1.Close()
   End Sub

</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Untitled Page</title>

</head> <body>

   <form id="form1" runat="server">
   </form>

</body> </html></source>