0% found this document useful (0 votes)
1K views

Read Serial Port in Abap

This document provides instructions to download and install the MSCOMM32.OCX component and register it to enable serial port communication functionality in SAP. It includes downloading the file, creating a registry entry and batch file to copy and register the component, and implementing it in a function module to read and write to the serial port.

Uploaded by

nstomar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Read Serial Port in Abap

This document provides instructions to download and install the MSCOMM32.OCX component and register it to enable serial port communication functionality in SAP. It includes downloading the file, creating a registry entry and batch file to copy and register the component, and implementing it in a function module to read and write to the serial port.

Uploaded by

nstomar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1 - Download MSCOMM32.

OCX ( for instance, you can download it from here : Link)


http://www.tweakbit.com/land/fix-my-pc/support?content=ocx&privacyshield=2&build
=1a2dn&instructions=1&kw=ocx&utm_source=ocxdump.com&utm_medium=ocx&utm_campaign=
OCXDump
2 - Create a text file named comm.reg with the following content:
Windows Registry Editor version 5.00
[HKEY_CLASSES_ROOT\Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905]
"VALUE"="REG_SZ=kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun"

3 - Create a batch file comm.bat with the following content:


copy MSCOMM32.ocx %SYSTEMROOT%\SysWOW64\
if not exist %SYSTEMROOT%\SysWOW64\mscomm32.ocx (copy MSCOMM32.ocx %SYSTEMROOT%\
system32\)
if exist %SYSTEMROOT%\SysWOW64\mscomm32.ocx (regsvr32 /s MSCOMM32.OCX)
if exist %SYSTEMROOT%\SysWOW64\mscomm32.ocx (regedit /s comm.reg)
if exist %SYSTEMROOT%\system32\mscomm32.ocx (regsvr32 /s MSCOMM32.OCX)
if exist %SYSTEMROOT%\system32\mscomm32.ocx (regedit /s comm.reg)

4 - Place all three files in the same location and run, with administrator privi
leges, the comm.bat file).
You may find additional help from the following links:
http://forums.sdn.sap.com/thread.jspa?threadID=1766170
http://www.sapfans.com/forums/viewtopic.php?f=13&t=145782&start=0&st=0&sk=t&sd=a
Step 1: Create a Function Module (code given below)
Step 2: Register the Windows activeX control MSCOM32.OCX on the client PC where
the Weighbridge's serial port is connected.
Step 3: Implement this control in Transaction SOLE in SAP (Create an entry MSCOM
MLIB.MSCOMM.1 and enter the CLSID. {648A5600-2C6E-101B-82B6-000000000014}
Step 4: Active this MSCOMM32.OCX with Licence Key on the client PC where the Wei
ghbridge's serial port is connected.
Open RUN execute : regedit
Go to u201CHKEY_CLASSES_ROOT\Licenses\u201D
Create new key (Folder) name with '4250E830-6AC2-11cf-8ADB-00AA00C00905'
Give the default VALUE: kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun
Restart the system and run the FM. if the data is coming on the serial port then
you will get the result.
FM Code:
FUNCTION z_serial_comport.

"------------------------------------------------------------------------------"
""""Local Interface:
"" IMPORTING
""
REFERENCE(MODE) TYPE I DEFAULT 0
""
REFERENCE(COMMPORT) TYPE I DEFAULT 1
""
REFERENCE(SETTINGS) TYPE C DEFAULT '2400,N,8,1'
""
REFERENCE(OUTPUT) TYPE C OPTIONAL
"" EXPORTING
""
REFERENCE(INPUT) TYPE C
"" EXCEPTIONS
""
NO_CREATE_OBJECT
"------------------------------------------------------------------------------"
TYPE-POOLS: sabc.
INCLUDE ole2incl.
PERFORM init.
PERFORM open_port USING commport settings.
IF mode = 0.
PERFORM read_port
CHANGING input.
ENDIF.
IF mode = 1.
PERFORM write_port
USING output
CHANGING input.
ENDIF.
PERFORM final.
ENDFUNCTION.
DATA: o_obj TYPE ole2_object.
"------------------------------------------------------------------------------"
FORM init.
DATA:
wa_repid LIKE sy-repid.
wa_repid = sy-repid.
CALL FUNCTION 'AUTHORITY_CHECK_OLE'
EXPORTING
program
= wa_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 o_obj 'MSCOMMLib.MSComm.1'.
IF sy-subrc <> 0.
RAISE no_create_object.
ENDIF.
ENDFORM.
" Init
"------------------------------------------------------------------------------"

FORM open_port USING commport settings.


SET PROPERTY OF o_obj 'CommPort' = commport.
SET PROPERTY OF o_obj 'Settings' = settings.
SET PROPERTY OF o_obj 'InputLen' = 0.
SET PROPERTY OF o_obj 'PortOpen' = 1.
ENDFORM.
"open_port
"------------------------------------------------------------------------------"
FORM read_port
CHANGING input.
DATA:
wa_buffer TYPE i.
DO 10 TIMES.
GET PROPERTY OF o_obj 'InBufferCount' = wa_buffer.
IF wa_buffer > 0.
GET PROPERTY OF o_obj 'Input' = input.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
" read_port
"------------------------------------------------------------------------------"
FORM write_port
USING output
CHANGING input.
DATA:
wa_buffer TYPE i.
SET PROPERTY OF o_obj 'Output' = output.
DO 10 TIMES.
GET PROPERTY OF o_obj 'InBufferCount' = wa_buffer.
IF wa_buffer > 0.
GET PROPERTY OF o_obj 'Input' = input.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
"write_port
"------------------------------------------------------------------------------"
FORM final.
SET PROPERTY OF o_obj 'PortOpen' = 0.
FREE OBJECT o_obj.
ENDFORM.
" final

You might also like