2 Replies Latest reply: Aug 28, 2013 7:28 AM by Stratos RSS

    Reading data from Comm Port - Scanner


      Hi everyone! I need your help.

      I am using Oracle Forms 6i and i want to use an rs-232 Handheld Scanner, which i have already connected on the COM3 port of the pc. I want to use this type of scanner because i want to prevent user from typing a barcode in text item. The only input method must be the SCANNER.

      I have made a lot of search for the implementation (most topics refer to weight scale) but the problem is how to finally get the input from the scanner when a barcode is scanned . How i catch the event that something scanned ?

      I have done the following:


      1. Create an OLE container ('block3.ole_control4') and connect it with file mscomm32.ocx deom system32 (Right click on the item and selecting Miscrosoft Communication Control does nothing; doesn't show any icon on the item)

      2. Import OLE library MSCOMMLib_IMSComm

      3. Create a text item <<data2>> on a block to show the scanned barcode and  a button with the following code in the 'WHEN-BUTTON-PRESSED'



      CommHandle ole2.obj_type; -- to hold the interface pointer

      hold number;

      NUM1 number;

      string1 Varchar2(2000);

      string2 OleVar;

      errCode         pls_integer;

      errSrc          varchar2(200);

      errDescription  varchar2(2000);

      errHelpfile     varchar2(200);

      errHelpContext  pls_integer;


        CommHandle := forms_ole.get_interface_pointer('block3.ole_control4');


        OLE2.SET_PROPERTY(CommHandle, 'CommPort', 3);


        /* try to close COM2, in case it was open for some reason.

        0 = FALSE, -1 = TRUE



        OLE2.SET_PROPERTY(CommHandle, 'PortOpen', 0);--port open


        when others then

        Message('Port is open');Message(' ');



        -- Set device to 9600 baud, no parity, 8 data, and 1 stop bit.

        OLE2.SET_PROPERTY(CommHandle, 'Settings', '9600,N,8,1');


        -- Open the port. 0 = FALSE, -1 = TRUE

        OLE2.SET_PROPERTY(CommHandle, 'PortOpen', -1);



           --***************here is the problem******************

           :data2 := OLE2.GET_CHAR_PROPERTY(CommHandle, 'Input');


           --Get_Ole_Var(CommHandle, 26); --this code raises error

           --string1:=var_to_Char(string2); --this code raises error


               when form_ole_failure then

             errCode := last_ole_exception( errSrc,




             message('ERR:'||errSrc||': '||errDescription);pause;

           When Others Then

           message('Error In Reading');pause;






      OLE2.SET_PROPERTY(CommHandle, 'InBufferCount', '0');






      When Others Then





      The main problem is how i finally get the INPUT.

      Is the 'WHEN-BUTTON-PRESSED' is the correct trigger to put the code << OLE2.GET_CHAR_PROPERTY(CommHandle, 'Input');  >>  ?

      In here it causes  error 305500-non Oracle Exception.


      Please i look forward for your help.

        • 1. Re: Reading data from Comm Port - Scanner

          Hi Stratos,

             i think in declaration part you increase the varchar2 size  to varchar2(65534) and then try it...

          errSrc          varchar2(65534);

          errDescription  varchar2(65534);

          errHelpfile     varchar2(65534);



          or otherwise


          write it as sepertate program units and call that procedure in button.....


          hope this will help.

          • 2. Re: Reading data from Comm Port - Scanner

            Su.gi thank you for your reply. Unfortunately the maximum available size of varchar2 is 32767. I set it to the maximum.
            Although i don't thing that this is the problem cause the code raises error 305500-non Oracle Exception at OLE2.GET_CHAR_PROPERTY(CommHandle, 'Input');

            and goes to when others exception . I 'm still wondering how i can read the scanned value.


            Any other think of correction ??