Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Barcode scanning
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00256911
Message ID:
00257005
Views:
27
>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
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform