| 发表于: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(); } |
|
|
|
|