另一个串口dll的调用演示
By
admin
at 2020-06-13 • 0人收藏 • 1646人看过
aardio已经有了sio串口库了, 功能更强大.
下面这个dll是网上别人分享的, 贵在简单, 只有四个函数, 不用设置很多东西
网址: https://www.cnblogs.com/wenziqi/archive/2010/08/07/1794606.html
测了下, 这个dll不支持$符号内嵌到exe (注意sio库里的pcomm.dll是可以的).
注意:
这个dll , 虽然提供了H头文件, 但是里面有些常量并未提供出来, 所以下面函数里面的某些常量参数都是猜的, 比如init函数里的parity校验常量和stopbit停止位常量, 测试发现当stopbit设置为1(猜测1位停止位)是错误的, 初始化会失败, 但是设置为0,2,3...却能返回true
另外,此dll里没有对读取超时的设置,
综上, 有空还是弄个硬件测试下.
import win.ui; /*DSG{{*/ mainForm = win.form(text="aardio工程3";right=298;bottom=186) mainForm.add( button={cls="button";text="open";left=19;top=54;right=131;bottom=83;z=1}; button2={cls="button";text="close";left=170;top=54;right=282;bottom=83;z=2}; button3={cls="button";text="send";left=19;top=100;right=131;bottom=129;z=3}; button4={cls="button";text="rec";left=170;top=100;right=282;bottom=129;z=4} ) /*}}*/ import console console.open() var dll = raw.loadDll("\res\SmartMComDll.dll","domdll","cdecl"); var init = dll.api("Init","bool(INT portnr,INT baud,INT parity,INT databits,INT stopbits)" ); var close = dll.api("Close","bool()" ); var send = dll.api("Send","INT(string pSendBytes,INT unSendLength)" ); var recv = dll.api("Recv","INT(string& pRecvBytes,INT unRecvLength)" ); mainForm.button.oncommand = function(id,event){ var ret = init(1,9600,0,8,0); console.log(ret) } mainForm.button2.oncommand = function(id,event){ var ret = close(); console.log(ret) } mainForm.button3.oncommand = function(id,event){ var str = string.unhex("44 55 66"," "); var ret = send(str,3); console.log(ret) } mainForm.button4.oncommand = function(id,event){ var ret,buff = recv(raw.buffer(10),10); console.log(ret,string.hex(string.left(buff,ret)," ")) } mainForm.show(); return win.loopMessage();
登录后方可回帖