最好有实例

解决方案 »

  1.   

    to vs2003
    http://www.codeproject.com/dotnet/DotNetComPorts.aspto vs2005
    http://www.codeproject.com/csharp/serialcommunication.asp
      

  2.   

    一般都用C++ http://www.gjwtech.com/serialcomm.htm
      

  3.   

    Knight94(愚翁) 老兄
    您能否把读串口的程序整理一下,在测试一番,弟兄们会非常感激!
    您的红四星让我有信任感
      

  4.   

    我用vs2005的串口控件:
    写:
    private void button1_Click(object sender, EventArgs e)
            {
                if (!sp.IsOpen)
                {
                    if (textBox1.Text != "")
                    {
                        this.sp.Open();
                        byte[] buf = Encoding.ASCII.GetBytes(textBox1.Text.ToString());
                        sp.Write(buf,0,buf.Length);
                        textBox1.Text = "";
                        toolStripStatusLabel1.Text = "发送成功!";
                        sp.Close();
                    }  
                }
            }读:
            byte[] by = new byte[1024];
            private  delegate void SetTexts();
            public ClientForm()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                if (!sp2.IsOpen)
                {
                    sp2.Open();
                }
                
            }        private void sp2_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {            
               
               
                sp2.Read(by, 0, by.Length);           
                this.Invoke(new SetTexts(SetText));
                       
            }
            public void SetText()
            {
                textBox1.Text=null;
                textBox1.Text += Encoding.ASCII.GetString(by);
             }