这是我的代码:
use Win32::API;Win32::API::More->import("kernel32","int GetCurrentProcessID()");Win32::API::More->import("UHFReader288.dll","OpenComPort","IPPI","I","_cdecl");sub OpenReader { my $comport = 1; my $comAddr = " " x 255; my $baud = "5"; my $handle = -1; my $result = OpenComPort($comport,$comAddr,$baud,$handle); return $result;}
以下是该函数的原型:
int OpenComPort(int port,BYTE* ComAdr,BYTE baud,int* FrmHandle);
该功能的文档由下图提供(对不起):
有人可以告诉我我做错了什么吗?当我调用该函数时,Perl解释器崩溃了!!
我在Win10上运行草莓Perl 5.24
解决方法use strict;use warnings qw( all );use feature qw( state );use Win32::API qw( );use constant { COM1 => 1,COM2 => 2,COM3 => 3,COM4 => 4,COM5 => 5,COM6 => 6,COM7 => 7,COM8 => 8,COM9 => 9,# etc COM_ADR_broADCAST => 0xFF,BAUD_9600 => 0,BAUD_19200 => 1,BAUD_38400 => 2,BAUD_57600 => 5,BAUD_115200 => 6,};sub OpenComPort { my ($port,$ComAdr_ref,$FrmHandle_ref) = @_; state $OpenComPort = Win32::API::More->new('UHFReader288.dll','OpenComPort','iPCP','i','_cdecl') or dIE($^E); my $ComAdr_buf = pack('C',$$ComAdr_ref); my $FrmHandle_buf = pack('i',-1); my $rv = $OpenComPort->Call($port,$ComAdr_buf,chr($baud),$FrmHandle_buf); $$ComAdr_ref = unpack('C',$ComAdr_buf); $$FrmHandle_ref = unpack('i',$FrmHandle_buf); return $rv;}{ my $ComAdr = COM_ADR_broADCAST; my $FrmHandle; OpenComPort(COM1,$ComAdr,BAUD_57600,$FrmHandle) or dIE("Error"); ...}
未经测试.
总结以上是内存溢出为你收集整理的perl – 使用Win32 :: API调用OpenComPort全部内容,希望文章能够帮你解决perl – 使用Win32 :: API调用OpenComPort所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)