pb串口编程问题
我在网上找了一个pb调用串口的控件,控件通过调用windows的API打开串口,但是这个程序只能对COM3和COM5有效,而我需要的端口COM15,代码是这样的
if PortOpen then
messagebox("错误","端口已处于打开状态",StopSign!)
return false
end if
dcb lst_dcb
PortOpen = true
//打开串口
iu_file = CreateFileA(ls_com,3221225472,0,0,3,128,0)//3221225472表示读和写方式访问串口资源,3标识该资源必须存在,128以重叠I/O操作创建串口
if (iu_file < 0) then
messagebox("错误","无法打开" + ls_com + " #" + string(getlasterror ( )),StopSign!)
if PortOpen then closehandle(iu_file)
PortOpen=false
return PortOpen
end if
//初始化DCB
if (Not BuildCommDcbA ( ls_commset, lst_dcb )) then//波特率、奇偶校验、数据位、停止位
messagebox("错误","无法创建DCB" + " #" + string(getlasterror ( )),StopSign!)
if PortOpen then closehandle(iu_file)
PortOpen=false
return PortOpen
end if
//设置串口
if (Not setcommstate ( iu_file, lst_dcb )) then
//messagebox("",string(iu_file))
messagebox("错误","无法设置串口"+ ls_com + " #" + string(getlasterror ( )),StopSign!)
messagebox("",string(iu_file))
if PortOpen then closehandle(iu_file)
PortOpen=false
return PortOpen
end if
//设置超时
commtimeouts lst_to
lst_to.readintervaltimeout = 4294967295 //MAXDWORD
//lst_to.readtotaltimeoutconstant = 60000
//lst_to.readtotaltimeoutmultiplier = 10
SetCommTimeouts(iu_file, lst_to)
CommError=0
return PortOpen
如果ls_com是COM15,setcommstate 这个函数就返回false,getlasterror 返回的是6,我发现COM3和COM5的iu_file值是860而COM15是4294967295
请问有人能知道怎么解决么?