>I have a barcode scanner with a built in decoder, plugged into Com1.
>
>I'm trying to read the barcode that was swiped, and enter the contents into a textbox on a form. I can not get the OnComm event to fire.
>
I assume that you're using the MSCOMM32 control; in order to access the OnComm event, you'll need to use the VFPCOM automation object (download from msdn.microsoft.com/vfoxpro/downloads) to make the event visible to VFP. The basic process involved would be:
Create a class with a method OnComm in it, which provides the VFP wrapper code to associate with the OnCOmm event. You must do this in advance.
In your application, do the following:
Create an instance of your class containing the OnComm wrapper
Create an instance of MSCOMMLib.MSComm
Create an instance of VFPCOM.ComUtil
Bind the custom class to the MSCOMM control instance using the VFPCOM.ComUtil's BindEvents() method:
oMSCOMM = CREATEOBJ('MSCOMMLib.MSComm') && MSCOMM control
oEvent = CREATEOBJ('MyEventHandler') && your custom class
oVFPCOM = CREATEOBJ('VFPCOM.ComUtil') && VFPCOM
oVFPCOM.BindEvents(oMSCOMM, oEvent) && Bind MSCOMM and Event handler
At this point, an OnComm event in oMSCOMM will trigger the code in the OnComm method of oEvent. In order to make sure that this continues to work, make certain that all three objects remain alive and kicking throughout the application's lifespan; IOW, it only works if the VFPCOM object and oEvent are active and visible as long as oMSComm exists, and this is one of the few times where I use PUBLICs, to ensure that all three objects are in scope at the same time.
You still set up the operating mode of the MSCOMM control through the oMSCOMM object; oEvent only receives control when the OnCOmm event occurs, and will need to be able to get an object reference to the oMSCOMM object to have it read from the Comm port.
The docs for VFPCOM are included in the self-extracting executable; the VFPCOM utility must be installed and registered on all systems using the control, jsut like any other ActiveX component. VFPCOM works with both VFP5 and VFP6, and is freely redistributable.
>Any help would be much appreciated.
>
>Thanks.
>
>Jamie
>
jamie@s-d-x.com