Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using MSCOMM with USB to serial device
Message
From
29/05/2008 10:51:54
 
 
To
29/05/2008 08:11:58
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01320080
Message ID:
01320245
Views:
22
This message has been marked as a message which has helped to the initial question of the thread.
>Thanks for your response.
>
>What I am doing is similar to what you suggest except I do not need to poll the port since I only want data sent from the device in response to commands I send to it.
>
>I can type the following in the command window and get the correct data back from the device.
>
>ot = CREATEOBJECT('mscommlib.mscomm')
>ot.CommPort = 4
>ot.Settings='115200,n,8,1'
>ot.PortOpen = .T.
>lqout = 0hA0A20001B700B7B0B3
>ot.Output = lqout
>lqin = ot.Input
>ot.PortOpen = .F.
>CREATE CURSOR test (testrec Q(100))
>INSERT INTO test VALUES(lqin)
>
>
>But when I run the same code in a PRG, the contents of the input buffer are cleared before being assigned to the local varuable.
>
>Thanks in advance for any insight.

As they already told you, you have to wait for the response from your device, that means you have to get the data in the OnComm event.

Your code works in the Command Window because by the time you type "lqin = ot.Input" the device has already sent the response data, but in a prg the line "lqin = ot.Input" executes BEFORE the device has sent the data.

In the OnComm event:
#Define comEvReceive	2	&& Receive event.

*!* Return if we don't have a data event.
If This.oSerial.Object.CommEvent # comEvReceive
	Return
Endif

*!* Get your data here
Carlos Alloatti
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform