本帖最后由 jjfkkk 于 2009-12-11 14:05:48 编辑

解决方案 »

  1.   

    回楼上的,不操作客户端串口。    我的目的就是远程控制家里的设备,设备连接PC,PC机做web服务器,然后登录页面远程控制设备。
      

  2.   

    不能在客户端做的!除非用ActiveX!
    你有没发现要串口的基本都要装一个东西的!就用ActiveX做吧!在ActiveX做和winform做一样的,再引用下就好了!然后让人家安装下就好了
      

  3.   


    楼上的朋友,我不是在客户端做的。就在本地服务端做。
    智能设备通过串口连接PC机——PC机读取串口数据——在该PC机架设WEB服务器——静态IP指向到该PC机——域名绑定到目标静态IP——访问域名,远程控制设备。我只是想实现这样的一个功能而已。
      

  4.   

    这些天,我也在查看如何实现近似你的功能,不过,我的代码应该可以满足你的要求。
    1、<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="rs232.aspx.cs" Inherits="mytestWEB.rs232" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:DropDownList ID="cbxPortName" runat="server">
            </asp:DropDownList>
            <asp:Button ID="btnOpenPort" runat="server" onclick="btnOpenPort_Click" 
                Text="连接" />
            <asp:Button ID="btnClose" runat="server" Text="断开" onclick="btnClose_Click" />
            <br />
            <asp:TextBox ID="txtSendMsg" runat="server" Width="100px"></asp:TextBox>
            <asp:Button ID="btnSend" runat="server" Text="发送" onclick="btnSend_Click" />
            <br />
            <asp:TextBox ID="txtReceive" runat="server" Height="49px" Width="112px"></asp:TextBox>
            <asp:Button ID="btnReceive" runat="server" Text="接收" 
                onclick="btnReceive_Click" />
            <br />
            <asp:Label ID="lbStatus" runat="server" Text="Label"></asp:Label>
        
        </div>
        </form>
    </body>
    </html>
    2、
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.VisualBasic.Devices;namespace mytestWEB
    {
        public partial class rs232 : System.Web.UI.Page
        {
            public static  System.IO.Ports.SerialPort com=new System.IO.Ports.SerialPort ();   
           
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack )
                {
                    
                    //获取所有的串口   
                    Microsoft.VisualBasic.Devices.Computer pc = new Microsoft.VisualBasic.Devices.Computer();
                    foreach (string s in pc.Ports.SerialPortNames)
                    {
                        this.cbxPortName.Items.Add(s);
                    }   
                }        }        protected void btnOpenPort_Click(object sender, EventArgs e)
            {
                if (cbxPortName.SelectedItem != null)
                {
                    com.Close();
                    com.PortName = cbxPortName.SelectedItem.ToString();
                    com.Open();
                    if (com.IsOpen)
                    {
                        btnClose.Enabled = true;
                        lbStatus.Text = "串口" + cbxPortName.SelectedItem.ToString() + "已经连接";
                    }
                }
                else
                {
                    Response.Write("hello");//MessageBox.Show("请选择串口!");
                }
            }        protected void btnClose_Click(object sender, EventArgs e)
            {
                com.Close();
                if (!com.IsOpen)
                {
                    btnClose.Enabled = false;
                }
            }        protected void btnSend_Click(object sender, EventArgs e)
            {
                if (com.IsOpen)
                {
                    com.WriteLine(txtSendMsg.Text);
                }
                else
                {
                    //MessageBox.Show("请先连接串口!");
                }
            }        protected void btnReceive_Click(object sender, EventArgs e)
            {
                txtReceive.Text = "";
                if (com.IsOpen)
                {
                    try
                    {
                        com.ReadTimeout = 5000;
                        txtReceive.Text = com.ReadLine();
                    }
                    catch
                    {                    //MessageBox.Show("读取数据超时!");
                    }            }
                else
                {
                    //MessageBox.Show("请先连接串口!");
                }
            }      
          
        }
    }
    designer.cs 就不发给你了。你右键根目录,轮换成WEB程序,就会自动建立 。
      

  5.   

    5楼的~~~你这个差远了~~哪里是ASP。NET串口通迅啊~~
      

  6.   

    这好象是C井不是ASP的吧
    网页串口偶都没用过了!
      

  7.   

    可以实现,使用.net的SerialPort类,但是只能操作服务器串口
      

  8.   

    ASP.net 用SerialPort类的源文件