Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving data from MSComm32

Status
Not open for further replies.

mican

Programmer
Nov 6, 2003
19
PH
I was tought about using the onComm event of MSComm32 object. It didn't work...

here is my code at MSComm1.OnComm

If This.ComEvent = 2
Thisform.Text1.Value = This.Input
Endif

Anyone who has idea on how to recieve data from MSComm32? Thanks...
 
Some sample code for accessing serial data in VFP using MSCOMM32 can be found in the following:
- HOWTO: Receive from the Serial Port by Using MScomm32.ocx.
Also useful may be
- HOWTO: Send to the Serial Port by Using Mscomm32.ocx.
And of course,
- HOWTO: Transmit and Receive Binary Data using MSCOMM32.

If MSCOMM32 doesn't provide you with enough control, you'll need to find another 3rd party control to handle the serial communication. Remember that in the Windows environment, it controls the I/O ports - you can't do it directly - especially in WinNT, Win2000 and XP.

Rick
 

If This.ComEvent = 2
Thisform.Text1.Value = This.Input
Endif


That seems like it should work. Are you sure the OnComm event is firing? What version of VFP are you working with?

Andy

 
Hi Andy

You're right. The OnComm event is not firing. I am using VFP8.0
 
Mican,

Do you have the control initialized correctly? This code may give you some ideas:

WITH THISFORM
.oleCommControl.Enabled = .T.
.oleCommControl.InputMode = 1 && Binary
.oleCommControl.CommPort = 2
.oleCommControl.Settings = "9600,n,8,1"

** RThreshold - Fire OnComm if 1 char is in the buffer
.oleCommControl.RThreshold = 1
.oleCommControl.InBufferSize = 8192
.oleCommControl.PortOpen = .T.
ENDWITH

** Should be ready to go...

Andy
 
Be sure and issue the following statement somewhere in your form load event or startup code:
Application.AutoYield = .F.

And also, you may need to issue a DOEVENTS. Here is an example of an OnComm event I use. After the 'Output', it forces the app to wait for an 'Input':
Code:
THISFORM.mybuffer = ''
STORE 0 TO nKey
STORE 0 TO nCounter
DO WHILE .T. 
   nCounter = nCounter + 1
   DOEVENTS
   nKey = INKEY(.1, 'HM')
   IF nKey = 27 .OR. (eot $ THISFORM.mybuffer) ;
      .OR. nCounter > 100  &&... Escape pressed or timeout
      EXIT
   ENDIF

   IF THIS.CommEvent = 2
      THISFORM.mybuffer = ;
         THISFORM.mybuffer +  TRANSFORM(THIS.INPUT)
   ENDIF
ENDDO   

RETURN


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top