• abap调vb写的dll实现电子天平的读数(带控件版)


    废话不多说,直接上。

    鉴于abap调研的dll文件需要在wins注册,自己尝试过delphi和C#感觉不是很好,最后毅然选择了VB来写

    因为需要用到MScomm控件,所以对于将要写的dll需要带form的,貌似这样才能将控件加到dll中来。

    步骤:

    1,新建dll程序,添加一个窗体

    2,在from_load中初始化com口参数

    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,写对应的端口数据接受(因为之前用端口测试工具测试过传出的数据流,所以下面代码只是针对特定数据流的截取)

    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中写函数啦

    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的执行,所以,才有这个必须出现的窗口

    好了,至此,一个带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来了,然后怎么操作这个数,就看需求啦

  • 相关阅读:
    关于HTML(七)--------HTML废弃的标签
    关于HTML(六)--------canvas
    抓包神器之Charles,常用功能都在这里了(转自https://blog.csdn.net/mxw2552261/article/details/78645118)
    混合开发的坑(7) ---输入文本时,键盘遮挡
    关于HTML(五)---------meta标签
    关于HTML(四)---------使用data-的好处
    关于HTML(三)---------xhtml和html的区别
    关于HTML(二)---------浏览器的标准模式和怪异模式
    关于HTML(一)---------HTML5新特性2
    关于HTML(一)---------HTML5新特性1
  • 原文地址:https://www.cnblogs.com/sapSB/p/3660050.html
Copyright © 2020-2023  润新知