| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 625 人关注过本帖
标题:大家帮忙看看怎么读不出数据呢?读取部分和李江全老师的例子一样啊
只看楼主 加入收藏
一切在变
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-4-22
收藏
 问题点数:0 回复次数:0 
大家帮忙看看怎么读不出数据呢?读取部分和李江全老师的例子一样啊
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using


namespace firstprogram
{
    public partial class form : Form
    {
        string data;
        public form()
        {
           
            InitializeComponent();
            this.pictureBox2.Hide();
           this.pictureBox1.Show();
            

        }

       private void serialPort1_DataReceived(object sender, e)
        {
            this.txtsend.Text = "1234";
            data = serialPort1.ReadExisting();
            this.Invoke(new EventHandler(DisplayText));
           
            
      }
        private void DisplayText(object sender, EventArgs e)
        {
            this.txtsend.Text = "1234";
            recievedsend.Text = recievedsend.Text + data;
        }
      
      private void InitCom()
      {

          foreach (string port in ())
          {
              this.cmbportname.Items.Add(port);
              cmbportname.SelectedIndex = 0;

          }
      }

     
        private void quitbtn_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void clearbtn_Click(object sender, EventArgs e)
        {

            this.txtsend.Clear();
        }

        private void openbtn_Click(object sender, EventArgs e)
        {
            try
            {      if(this.serialPort1.IsOpen )
                      {
                       this.serialPort1 .Close ();
                       }
                   else
                        {
         
                            this.serialPort1.PortName = this.cmbportname.Text;
                            this.serialPort1.BaudRate = int.Parse(cmbbaudrate.Text);
                            this.serialPort1.DataBits = int.Parse(cmbdatabits.Text);
                            this.serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cmbstopbit.Text);
                            this.serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), cmbparty.Text);
                            this.serialPort1.Open();
                           }
                                sendbtn.Enabled = this.serialPort1.IsOpen;
                                cmbportname.Enabled = cmbbaudrate.Enabled =
                                cmbdatabits.Enabled = cmbstopbit.Enabled =
                                cmbparty.Enabled =!this.serialPort1.IsOpen;
                                autosend.Enabled = this.serialPort1.IsOpen;
                        if (this.serialPort1.IsOpen)
                        {
                            this.pictureBox2.Show();
                            this.pictureBox1.Hide();
                            this.openbtn.Text = "关闭窗口";
                           
                        }
                        else
                        {
                            this.pictureBox2.Hide();
                            this.pictureBox1.Show();
                            this.openbtn.Text = "打开串口";
                           
                        }
            
            
            }   
                catch
                {
                    MessageBox.Show("打开失败");
                   this.timer1.Enabled = false;
                }
        }

        private void sendbtn_Click(object sender, EventArgs e)
        {  for (int i=0;i<txtsend.Lines.Count();i++)
            this.serialPort1.Write(txtsend.Lines[i]);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            for (int i=0; i < txtsend.Lines.Count(); i++)
                this.serialPort1.Write(txtsend.Lines[i]);
        }
      
      

        private void autosend_CheckedChanged(object sender, EventArgs e)
        {
            if (this.autosend.Checked)
               this.timer1.Enabled = true;
                 //this.serialPort1.Write("12334");
               // this.txtsend.Text = "1234";
            else
            {
                this.timer1.Enabled = false;
               // this.txtsend.Text = "5678";
            }
        }  
}}
        
搜索更多相关主题的帖子: namespace 看看 private public 
2013-04-22 07:33
快速回复:大家帮忙看看怎么读不出数据呢?读取部分和李江全老师的例子一样啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023584 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved