您的位置:程序门 -> .net技术 -> vc.net



多天没有解决的问题,没时间在自己研究了,各位哥哥帮帮忙吧,进进进。。。。


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


多天没有解决的问题,没时间在自己研究了,各位哥哥帮帮忙吧,进进进。。。。[无满意答案结贴,结贴人:liyunpeng_111]
发表于:2007-12-12 10:14:20 楼主
public:   void   receivedevent(object^   sender,system::io::ports::serialdatareceivedeventargs^   e)
{

messagebox::show("hello1");
try
{
byte   firstbyte=convert::tobyte(serialport1-> readbyte());//执行到这句话,就会关闭串口,去怀疑是超时的原因,可是msdn的解释是超时的默认是永不超时。
int   bytesread=serialport1-> bytestoread;
bytesdata=new   byte[bytesread];
bytesdata[0]=firstbyte;

for(int   i=0;i <=bytesread;i++)

bytesdata[i]=convert::tobyte(serialport1-> readbyte());
       
listdata=convert::tostring(bytesdata);
listbox-> text=listdata;


}
catch(system::exception^   e)
{
messagebox::show(convert::tostring(e));
}


}

public:     void   synreceivedata()
{

form1^   start1=gcnew   form1;
serialport1-> datareceived+=gcnew   serialdatareceivedeventhandler(this-> serialport1,&form1::receivedevent);//引用原型参数1:是object类型的表示一个serialport。但是如果这么写会报错:c3754:   委托构造函数:   成员函数“comm::form1::receivedevent”不能在类型“system::io::ports::serialport   ^”的实例上调用。
                                                [color=#ff0000]/*在网上看到许多例子,在此处的引用是serialport1-> datareceived+=gcnew   serialdatareceivedeventhandler(receivedevent);但是这样写还是报错:error   c3867:   “comm::form1::receivedevent”:   函数调用缺少参数列表;请使用“&comm::form1::receivedevent”创建指向成员的指针
error   c3350:   “system::io::ports::serialdatareceivedeventhandler”:   委托构造函数需要   2   个参数*/[/color]不知什么原因请大家帮忙。

messagebox::show("hello");


}

void   threadreceive()
{
form1^   start=gcnew   form1;
thread^   threadreceive=gcnew   thread(gcnew   threadstart(start,&form1::synreceivedata));
threadreceive-> start();

}  
发表于:2007-12-12 10:39:231楼 得分:0
serialport1->   datareceived+=gcnew       serialdatareceivedeventhandler(this->   serialport1,&form1::receivedevent)
这句话在编译时,并没有错误,可是debug一下,并没有正常执行&form1::receivedevent函数。
谢谢大家了。
发表于:2007-12-12 11:43:122楼 得分:0
如用这句:   serialport1-> datareceived+=gcnew   serialdatareceivedeventhandler(this,&form1::receivedevent);
运行后,当button_click事件发生后,会弹出异常警告:未将对象引用设置到对象的实例。
发表于:2007-12-12 12:41:133楼 得分:0
不要沉


快速检索

最新资讯
热门点击