Home » Developer & Programmer » Forms » Application Crashes Using MSCOMM Control
Application Crashes Using MSCOMM Control [message #47929] Sat, 02 October 2004 08:22 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 #428950 is a reply to message #47929] Sat, 31 October 2009 01:47 Go to previous messageGo to next message
spcsunil
Messages: 1
Registered: October 2009
Location: Pune
Junior Member

hi all

when i used the ablove code in my form i got this error

frm-40922 An Ole error occured: 0x80004002

on Set_Ole(interface, 4, CommPort, VT_I2);

statement

and on my_new_value := Get_Ole_Num(interface, 20);


FUNCTION PortOpen(interface OleObj) RETURN NUMBER IS
my_new_value NUMBER;
BEGIN
my_new_value := Get_Ole_Num(interface, 20);
return my_new_value;
End;
  • Attachment: comport.fmb
    (Size: 504.00KB, Downloaded 291 times)
Re: Application Crashes Using MSCOMM Control [message #431536 is a reply to message #428950] Tue, 17 November 2009 23:56 Go to previous message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
The post you are referring to was posted in 2004.

Which version of Forms are YOU using?

Search this forum for 'MSCOMM' and see the problems that others are having at the moment.

Did you use the 'message;pause;' pair method to prove which statement is failing?

David
Previous Topic: Is it possible to install Oracle Developer Suite 10g on Windows 64 bits
Next Topic: what's datatype against this vb.net collection type
Goto Forum:
  


Current Time: Fri Dec 09 02:07:49 CST 2016

Total time taken to generate the page: 0.14617 seconds