Home » Developer & Programmer » Reports & Discoverer » Application Crashes Using MSCOMM Control
Application Crashes Using MSCOMM Control [message #90024] Sat, 02 October 2004 08:25 Go to next message
fanni
Messages: 96
Registered: March 2004
Member
AOA

You had given me clue to read the data from ComPort using MSCOMM control in Oracle FORMS 6.
I have got success in reading the data from COM Port. Now i am facing a very severe problem. I have made a procedure that
that is being called by timer and reads the data from the COM port.
Now it happens so that sometimes My Forms Application crashes out. I have tried a lot to find the reason but still unable to resolve the reason.

i get this sort of data that i filter it and get my required data from it

   5285  kg US,NT,0,   5680  kgUS,NT,0,   5815  kgUS,NT,0,   5860  kgUS,NT,0,   5905  kgUS,NT,0,   5935  kgUS,NT,0,   5950  kgUS,NT,0,   5955  kg

   4995  kgST,NT,0,   4990  kgST,NT,0,   4990  kgST,NT,0,   4985  kgST,NT,0,   4985  kgUS,NT,0,   4995  kgUS,NT,0,   5005  kgUS,NT,0,   4990  kg

   5770  kgUS,NT,0,   5775  kgUS,NT,0,   5775  kgUS,NT,0,   5775  kgUS,NT,0,   5780  kgUS,NT,0,   5790  kgUS,NT,0,   5795  kgUS,NT,0,   5800  kg

   6685  kgUS,NT,0,   6655  kgUS,NT,0,   6630  kgUS,NT,0,   6605  kgUS,NT,0,   6580  kgUS,NT,0,   6555  kgUS,NT,0,   6535  kgUS,NT,0,   6510  kg

this is my code
---------------------------------------------------------------------------------------

--**********************************************************
--Purpose
--This piece of Code reads data from com port 1 and
--put the data in the given field. This task is being
--accomplished by using Microsoft Activ-X Control 
--MSCOMM32.OCX as called as 'Communication Control'
--**********************************************************

FUNCTION ScaleWeight RETURN CHAR IS
 receive   OLEVAR;
 Wreceive   VARCHAR2(400);
 v_buffer varchar2(10240);
 Attempts Number:= 0; --counts the number of attempts to read the data from port
 v_FirstPoint number;  --used for taking the index of first symbol of 'kg'
 v_SecondPoint number; --used for taking the index of second symbol of 'kg'
 v_BufferLength number; --stores the data stream get from com port
 v_DataStream varchar2(32767); -- gets the data from com port and stores in v_BufferLength
 a number:=1;
-- Attempts NUMBER:=0;

 
BEGIN   
 --changing the cusor style
 --set_application_property(cursor_style,'BUSY');
 --assigning the comport to active x control
 MSCOMMLib_IMSComm.CommPort(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,1);
 --check to see whether it is already open or closed
 if (MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE) = -1) then --open
  null;
 else
  --setting the mode for communication
  MSCOMMLib_IMSComm.Settings(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,'9600,n,8,1');
  --opening the port
  MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,1); 
 end if; 
 ------------------------------------
 --This loop ensures that the data string
 --has at least two 'KG' symbols in
 --the data string retrieved
 --message(MSCOMMLib_IMSComm.DTREnable(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE));
 --message(MSCOMMLib_IMSComm.DTREnable(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE));
 LOOP
  exit when (v_SecondPoint <> 0) ;
  v_FirstPoint := 0;
  v_SecondPoint := 0;
 --MESSAGE('INSIDE FIRTST LOOP');
  v_buffer :='';
  -- v_SecondPoint will be 0 only if 'KG' is not found second time
  --this loop causes a delay
  --MyDelay(150000);

  v_BufferLength := 0;
    insert into weightscale
    values(:DATA2,1);
    forms_ddl('commit');
 v_DataStream :='';
  loop
   exit when (v_BufferLength > 150) or (Attempts > 20);
   LOOP
    EXIT WHEN A> 300000;
    A:=A+1;
   END LOOP; 

   --MESSAGE('INSIDE SECOND LOOP');
   -- exit when (v_BufferLength > 150 );
   --INPUT function receives the data string from com port to OLEVAR variable
   receive := MSCOMMLib_IMSComm.input(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE);
   v_DataStream:= var_to_char(receive);
   --v_DataStream:= '   5285  kg US,NT,0,   5680  kgUS,NT,0,   5815  kgUS,NT,0,   5860  kgUS,NT,0,   5905  kgUS,NT,0,   5935  kgUS,NT,0,   5950  kgUS,NT,0,   5955  kg';
   v_BufferLength := NVL(length(v_buffer||v_DataStream),0);
   v_buffer := v_buffer||v_DataStream;
   :data2 := v_buffer;
    forms_ddl('commit');
   Attempts := Attempts +1;

  end loop;
    insert into weightscale
    values(:DATA2,:attempt);
 
  -------------------------------------
  IF (Attempts < 20) THEN
   --MESSAGE('INSIDE THE SECOND IF');
     --filteration code 
     v_FirstPoint := nvl(instr(v_buffer,'kg',1),0);
     -- v_FirstPoint will be 0 only if 'kg' is not found in the data string
     if (v_FirstPoint <> 0) then
       v_SecondPoint := nvl(instr(v_buffer,'kg',v_FirstPoint+2),0);
       if (v_SecondPoint <> 0) then
         v_buffer := substr(v_buffer,v_SecondPoint - 7 ,5);
         --:DATA:= v_buffer;
         --to_number(substr(v_buffer,1,2)||substr(v_buffer,4,3));
       else
         --this 5portion executes only if data string contains one symbol of 'kg'
         --MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,0);     
         --MSCOMMLib_IMSComm.Settings(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,'9600,n,8,1');
         --MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,1); 
         null;
       end if;  
     else
         --this portion executes only if data string contains zero symbol of 'kg'     
         --MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,0);     
         --MSCOMMLib_IMSComm.Settings(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,'9600,n,8,1');
         --MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,1); 
         null;
        
     end if;  
 ELSE
   message('Scale is not ready');
   message('Scale is not ready');
   v_SecondPoint := 339;--IT WILL TERMINATE THE FIRST LOOP
END IF;         
 
   
 
 
 
 END LOOP;
 --closing the port
 MSCOMMLib_IMSComm.PortOpen(:ITEM('BLOCK2.MSCOMMCONTROL').INTERFACE,0); 
 --changing the cursor style back to default
 set_application_property(cursor_style,'DEFAULT');

 
  RETURN TO_NUMBER(v_buffer);
 
END;

-----------------------------------------------------------------------------------------------------------------------

I really need your guidance.

Regards
Farhan Ashraf
Re: Application Crashes Using MSCOMM Control [message #424281 is a reply to message #90024] Thu, 01 October 2009 04:33 Go to previous message
imme
Messages: 3
Registered: September 2009
Location: vietnam
Junior Member

Can you sent to me your form? Smile

dinhthienthanh@yahoo.com
---------------------------
Previous Topic: barcode
Next Topic: Problem when using MScomm32.ocx in form 6i
Goto Forum:
  


Current Time: Fri Apr 19 09:47:26 CDT 2024