废话很少说,直接上。java
鉴于abap调研的dll文件须要在wins注册,本身尝试过delphi和C#感受不是很好,最后毅然选择了VB来写函数
由于须要用到MScomm控件,因此对于将要写的dll须要带form的,貌似这样才能将控件加到dll中来。工具
步骤:测试
1,新建dll程序,添加一个窗体spa
2,在from_load中初始化com口参数code
1
2
3
4
5
6
7
8
|
With
MSComm1
.CommPort = 1
'设置Com1为通讯端口
.Settings =
"1200,n,7,1"
'设置通讯端口参数 9600赫兹、偶校验、7个数据位、1个中止位.(这里须要进一步说明的是:.Setting=”BBBB,P,D,S”。
.InBufferSize = 16
'设置缓冲区接收数据为40字
.InputLen = 1
'设置Input一次从接收缓冲读取字节数为1
.RThreshold = 1
'设置接收一个字节就产生OnComm事件
.PortOpen =
True
End
With
|
3,写对应的端口数据接受(由于以前用端口测试工具测试过传出的数据流,因此下面代码只是针对特定数据流的截取)orm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
On
Error
Resume
Next
If
MSComm1.CommEvent = comEvReceive
Then
If
MSComm1.InBufferCount > 0
Then
Rx_buff = MSComm1.Input
If
Rx_buff =
"N"
Then
start =
"S"
Constop =
False
For
i = 0
To
UBound(Rx_buff)
If
start =
"S"
Then
send = send & Rx_buff
If
Len(send) > 17
Then
Text1.Text =
CDbl
(Mid(send, 8, 10))
start =
"E"
MSComm1.PortOpen =
False
End
If
End
If
Next
i
End
If
End
If
|
4,在dll的class1中写函数啦blog
1
2
3
4
5
6
7
8
9
|
Public
Function
show()
Form1.str =
"s"
Form1.Caption =
"链接状态"
Form1.show vbModal
End
Function
Public
Function
sget()
As
String
sget = Form1.str & Form1.send
End
Function
|
先调出窗口,再获取端口值事件
由于能力有限,在测试的时候没法将窗口隐藏而不影响到form_load的执行,因此,才有这个必须出现的窗口ci
好了,至此,一个带from的调用Mscomm控件的dll文件就写好了,
5,将dll文件保存到system32/syswow64下
运行cmd注册dll文件
6,abap调用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
REPORT ZLYTEST_DLLTEST001.
include ole2incl.
data win32 type ole2_object.
DATA SUM TYPE I.
data label type string.
create object win32
'lytest10.class1'
.
*create object win32
'TESTDLL'
.
call METHOD of win32
'show'
.
call method of win32
'sget'
= label.
*
0
Successful processing of the method meth.
*
1
Communication Error to SAP GUI.
*
2
Error when calling method meth.
*
3
Error when setting a property.
*
4
Error when reading a property.
*
write label.
|
至此,就将数据带回abap来了,而后怎么操做这个数,就看需求啦