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



串口通信问题


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


串口通信问题[已结贴,结贴人:chouky]
发表于:2007-04-10 18:25:38 楼主
函数如下:

public   bool   openport(string   lpfilename,int   baudrate,byte   parity,  
byte   bytesize,   byte   stopbits)  
{  
//   open   the   comm   port.  
hcomm   =   createfile(lpfilename   ,generic_read   ¦   generic_write,   0,   0,  
open_existing,   0,   0);  
//   if   the   port   cannot   be   opened,   bail   out.  
if(hcomm   ==   invalid_handle_value)  
{  
return   false;  
}  
}

调用时的参数设置:
gps.openport( "com1 ",9600,0,8,0);

问hcomm的值一直是-1

是什么问题?/??
发表于:2007-04-10 20:05:541楼 得分:5
c#下用不着createfile这个api
2.0中的serialport类很好用了

可能是你的com1不存在咯,其他参数都没什么问题
发表于:2007-04-10 20:15:442楼 得分:0
我是用1.1的

我的计算机串口在的啊,那这个串口名应该是什么呢?
发表于:2007-04-10 21:42:383楼 得分:5
换个方法,到网上去搜个东西
justio这个控件,用着还可以
发表于:2007-04-11 09:51:454楼 得分:10
http://blog.csdn.net/imliujie/archive/2007/03/19/1533243.aspx
vb/c++/c#串口通信源代码+详细注释


快速检索

最新资讯
热门点击