标题:是否需要声明?该怎么声明?
取消只看楼主
骨子里的认真
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-9-17
结帖率:0
已结贴  问题点数:10 回复次数:2 
是否需要声明?该怎么声明?
public void InitClient()  //窗体控件已在初始化
        {
            interfaceUpdateHandle = new HandleInterfaceUpdateDelegate(btnSend_Click);  //实例化委托对象

            spSend.Open();  //SerialPort对象在程序结束前必须关闭,在此说明

            spReceive.DataReceived += Ports.SerialDataReceivedEventHandler(spReceive_DataReceived);

            spReceive.ReceivedBytesThreshold = 1;

            spReceive.Open();
        }
显示错误为

错误    1    当前上下文中不存在名称“Ports”    ,不知道怎么改
搜索更多相关主题的帖子: public 上下文 
2013-10-17 11:41
骨子里的认真
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-9-17
得分:0 
谢谢,这个问题解决了,但居然没出来结果,怎么会没反应呢?您看看这样可以吗?
        private void spReceive_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            interfaceUpdateHandle = new HandleInterfaceUpdateDelegate(btnSend_Click);  //实例化委托对象

            spSend.Open();

            spReceive.DataReceived += new (spReceive_DataReceived);

            spReceive.DataReceived += spReceive_DataReceived;

            spReceive.ReceivedBytesThreshold = 1;

            spReceive.Open();

            byte[] readBuffer = new byte[spReceive.ReadBufferSize];

            spReceive.Read(readBuffer, 0, readBuffer.Length);

            this.Invoke(interfaceUpdateHandle, new string[] { Encoding.Unicode.GetString(readBuffer) });

        }
        private void UpdateTextBox(string text)
        {
            txtReceive.Text = text;
            MessageBox.Show("数据接收成功!", "系统提示");
        }
2013-10-17 20:21
骨子里的认真
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-9-17
得分:0 
一个还是不行,不过还是非常谢谢您,谢谢啦
2013-10-18 12:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-422046-1-1.html




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

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