Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Firoz_Ashraf
Contributor
34,422
Case: Weighbridge scale sends the weight data to COMM Port.

Earlier we had to write a .NET program using SAP.NET Connector (Using VB.NET) and then from SAP side we had to create RFC so that the COMM port data gets utilized in SAP.

Now there is no need to use the third party software (VB.NET, C# etc) Using the following steps we can directly fetch the weight data at the COMM Port to SAP:

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. Please click here to get detailed steps on how to register/activate this control.

Step 3: Implement this control in Transaction SOLE in SAP (Create an entry MSCOMMLIB.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 Weighbridge's serial port is connected.

Open RUN execute : regedit

Go to u201CHKEY_CLASSES_ROOT\Licenses\u201D
the correct path is: HKEY_CLASSES_ROOT\Licenses\

not u201CHKEY_CLASSES_ROOT\Licenses\u201D

don't confuse with strings u201C and u201D because are ascii characters for double quotes (").

You can also use the path HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Licenses\ as stated in this link.  

https://github.com/davidanger/MSCOMM32
(Courtesy noelbaez)


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 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

Regards,

Firoz.
16 Comments
Labels in this area