最近SAP系统需要与道闸设备集成,通过串口通讯模式控制道闸栏杆升降,在此将开发过程中的思路及问题点做个备注。
一.相关设备
道闸设备型号:富士智能FJC-D618
串口模块:康耐德 C2000-A1-PXD0020-BX1
转换器:DTECH DT-9020 RS-232<=>RS485
二.设备集成方式:调用系统组件MSComm32.OCX
64位文件路径:C:/Windows/SysWOW64/MSCOMM32.OCX
若找不到MSCOMM32.OCX组件,可以网上下载。
三.组件MSComm32.OCX 相关属性说明
路径:VB-串口通信详解
四.SAP与道闸设备集成操作步骤
1.控件注册
a.将MSComm32.OCX文件放置在 C:/Windows/SysWOW64 路径下(32位操作系统放在 C:/Windows/System32 )
b.控件注册:管理员权限运行CMD->Regsvr32 C:/Windows/SysWOW64/MSCOMM32.OCX
c.修改注册表(这一步感觉可有可无):
c1.运行CMD->Regedit
c2.在HKEY_CLASSES_ROOT/Licenses下新建项:4250E830-6AC2-11cf-8ADB-00AA00C00905 修改数值数据:kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun
d.重启电脑,控件启用
2.SAP系统应用程序维护
a.查找CLSID:运行CMD->Regedit,搜索“MSCOMMLib.MSComm.1”,获取CLSID:{648A5600-2C6E-101B-82B6-000000000014}
b.登录GUI,T-CODE:SOLE 修改-新条目
OLE 应用程序: MSCOMMLIB.MSCOMM.1
版本号:
CLSID: {648A5600-2C6E-101B-82B6-000000000014}
CLSID 库类型:
OLE 对象名:
类型信息代码:
包含程序:
语言:
检查权限:
文本:
3.SAP直接调用MSCOMM32.OCX控件(16进制多条记录无法发送下位机)
*&---------------------------------------------------------------------* *& Report ZRICO_MSCOMM *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zrico_mscomm. data: lv_cur type string, lv_rst type string, lv_buffer type i. data: lo_dz type ole2_object. selection-screen begin of block block1 with frame title text-001. parameters: p_port type char30 default '1', p_sett type char30 default '9600,n,8,1', p_inpt type char30 default '0', p_open type char30 default '1', p_intxt type string default '01 01 00 64 00 01 BC 15', p_ottxt type string. selection-screen end of block block1. start-of-selection. call function 'AUTHORITY_CHECK_OLE' exporting program = sy-repid activity = sabc_act_call application = 'MSCOMMLIB.MSCOMM.1' exceptions no_authority = 1 activity_unknown = 2 others = 3. if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. "创建对象 create object lo_dz 'MSCOMMLib.MSComm.1'. if sy-subrc <> 0. raise no_create_object. endif. "初始参数 set property of lo_dz 'CommPort' = p_port. set property of lo_dz 'Settings' = p_sett. set property of lo_dz 'InputMode' = 1. set property of lo_dz 'InputLen' = p_inpt. set property of lo_dz 'InBufferSize' = 1024. set property of lo_dz 'OutBufferSize' = 512. "打开串口 set property of lo_dz 'PortOpen' = p_open. "发送数据-多条记录-16进制 "此处不知如何处理:需将16进制转换为字符数组Byte[]方式发送至下位机 "若将16进制转换为10进制内表传值则直接Dump,若直接传输16进制字符串则无返回值 set property of lo_dz 'Output' = p_intxt. "接收数据 do 40 times. get property of lo_dz 'InBufferCount' = lv_buffer. if lv_buffer > 0. get property of lo_dz 'Input' = lv_rst. exit. endif. enddo. "关闭串口 set property of lo_dz 'PortOpen' = 0. "释放 free object lo_dz.
3.1因发送16进制数据为多条记录,控件MSCOMM发送数据类型为Byte[],ABAP无法将16进制数转换为字节数组,若转换为内表传输则直接Dump,最终无解。
3.2ABAP无法一次发送多条记录至下位机,则改用其他方式处理(详见4):
a.用VB创建DLL文件,引用MSCOMM32.OCX控件并创建多个类方法。
b.系统注册DLL文件
c.SAP调用DLL文件,并访问自定义方法类
4.解决16进制多条记录发送问题
4.1用VB创建DLL文件,封装MSCOMM32.OCX控件相关属性及自定义方法
4.2SAP调用自定义类文件 MSCommPrj.DLL
a.注册文件MSCommPrj.DLL
运行CMD->regsvr32 文件路径
b.ABAP调用类文件 :16进制多条记录用”&”符号拼接为字符串
*&---------------------------------------------------------------------* *& Report ZRICO_MSCOMMPRJ *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zrico_mscommprj. data: gv_rst type string. data: go_mscomm type ole2_object. selection-screen begin of block block1 with frame title text-001. parameters: p_port type char10 default '1', p_sett type char30 default '9600,n,8,1', p_mode type char10 default '0', p_time type char10 default '100', p_data type char200 default '01 01 00 64 00 01 BC 15 & 01 0F 00 64 00 01 01 FF 1F 1F & 01 01 00 64 00 01 BC 15 & 01 0F 00 64 00 01 01 00 5F 5F'. selection-screen end of block block1. start-of-selection. call function 'AUTHORITY_CHECK_OLE' exporting program = sy-repid activity = sabc_act_call application = 'MSCommPrj.msCommCls' exceptions no_authority = 1 activity_unknown = 2 others = 3. if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. "创建对象 create object go_mscomm 'MSCommPrj.msCommCls'. if sy-subrc <> 0. raise no_create_object. endif. "初始化参数 call method of go_mscomm 'frm_initial_parameters' = gv_rst exporting #1 = p_port #2 = p_sett #2 = p_mode . write:/10 gv_rst. "打开串口 call method of go_mscomm 'frm_open_serialport' = gv_rst. write:/10 gv_rst. "发送数据 call method of go_mscomm 'frm_send_data' = gv_rst exporting #1 = p_mode #2 = p_time #2 = p_data . write:/10 gv_rst. "接收数据 call method of go_mscomm 'frm_receive_data' = gv_rst exporting #1 = p_mode. write:/10 gv_rst. "关闭串口 call method of go_mscomm 'frm_close_serialport' = gv_rst. write:/10 gv_rst. free object go_mscomm.
5.SAP测试DLL
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/17978.html