专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > PB

求在PowerBuilder中调用Pcomm串行通讯组件的例子解决方案

发布时间:2011-06-29 20:30:46 文章来源:www.iduyao.cn 采编人员:星星草
求在PowerBuilder中调用Pcomm串行通讯组件的例子
想在pb9下调用Pcomm串行通讯组件实现通讯,在Moxa的官网上下载了PComm Lite 2000,Version1.4,但是HELP里没有pb调用的例子。哪位大虾用过,望不吝赐教。e_mail:csupk@163.com

------解决方案--------------------
不是有帮助么?这个有个不好的是不能主动接受消息 只能读写
------解决方案--------------------
PB65下从串口通信获取程控交换机计费数据的API调用


首先定义外部函数:
Function Boolean CloseHandle(ulong hObject ) Library "kernel32.dll"
FUNCTION boolean ReadFile(ulong fhand,
& ref string lpbuffer,
& ulong numbyte,
& ref ulong bytesread,
& ulong lpover) LIBRARY "kernel32.dll"
FUNCTION ulong CreateFileA(ref string fname,
& ulong f_access,
& ulong f_share,
& ulong f_sec,
& ulong f_create,
& ulong f_flag,
& ulong f_attrib) LIBRARY "kernel32.dll"
Function Boolean WriteFile(uLong handle,
& ref string lpbuffer,
& ulong numbytes,
& ref ulong bytesread,
& ulong lpOverLaped) Library "Kernel32.dll"
Function Boolean GetCommProperties(ulong hFile,
& ref COMMPROP lpCommProp ) Library "Kernel32.dll"
Function Boolean BuildCommDCBA(ref string lpDef,
& ref DCB lpDCB ) Library "Kernel32.dll"
Function Boolean SetCommState(ulong hCommDev,
& ref DCB lpdcb ) Library "Kernel32.dll"
Function Boolean GetCommState(ulong hCommDev,
& ref DCB lpdcb ) Library "Kernel32.dll"
Function ulong GetLastError() Library "Kernel32.dll"
Function Boolean SetCommTimeouts(ulong hCommDev,
& ref COMMTIMEOUTS lpctmo ) Library "Kernel32.dll"
Function Boolean PurgeComm(ulong hCommDev,
& ulong fdwAction ) Library "Kernel32.dll"
实例变量定义:
ulong iu_file
string is_buffer//数据缓冲
string is_valid_num = "123" //有效数据
第二是初始设置
string ls_com,ls_commset
dcb lst_dcb
ls_com = "COM1" //

ib_reading = true //打开串口
iu_file = CreateFileA(ls_com,3221225472,0,0,3,128,0)
if (iu_file < 0) then
messagebox("错误","无法打开" + ls_com + " #" + string(getlasterror ( )),StopSign!)
end if //初始化DCB
ls_commset = "4800,N,8,1"
if (Not BuildCommDcbA ( ls_commset, lst_dcb )) then
messagebox("错误","无法创建DCB" + " #" + string(getlasterror ( )),StopSign!)
end if
//设置串口
if (Not setcommstate ( iu_file, lst_dcb )) then
messagebox("错误","无法设置串口"+ ls_com + " #" + string(getlasterror ( )),StopSign!)

end if
//设置超时
commtimeouts lst_to lst_to.readintervaltimeout = 4294967295 //MAXDWORD //
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: