Visual Fox Pro: Collecting Data using WinWedge

WinWedge DDE Server Settings

Remember to set WinWedge up in DDE Server Mode! Click here.

DDE Application Name: MyServer
DDE Topic: MyTopic
DDE Command: [GRABDATA]

FoxPro Instructions

FoxPro does not have a “GrabData” command so we must create one. The FoxPro code example on the following page does exactly that. Create a new program module in the CODE section of FoxPro and enter the code on the following page. After you are done entering the code save your work and run the program.

What this example does is to set up WinWedge to issue a DDE command [GRABDATA] to your FoxPro application after each data record is received from your serial device. This causes the procedure DoCommand to run which then performs a DDERequest back to the Wedge asking for the data in Field(1) in the Wedge Window. This data is then returned to FoxPro in the variable: MyData. Once the data from the Wedge is in a variable, you can do whatever you like with it by including additional code of your own design.

 *** Set this application up as a DDE server. The following code must be run at the start***
*** of your application to make it able to respond to DDE commands.***
*** Set the DDE application name to: "MyServer" and Enable DDE command execution***
= DDESetService('MyServer', 'DEFINE')
= DDESetService('MyServer', 'EXECUTE', .T.)
*** Set the DDE topic to "MyTopic" ***
*** Set up procedure "DoCommand" to run on all DDEExecutes to topic "MyTopic"***
= DDESetTopic('MyServer', 'MyTopic', 'DoCommand')
*** The following procedure will run whenever another application***
*** issues a DDE command to application name 'MyServer' and topic 'MyTopic'***
*** The DDE command is passed in the variable "gData"***
PROCEDURE DoCommand

PARAMETERS gnChannel, gcAction, gcItem, gData, gcFormat, gnAdvise
glResult = .F.
*** It's necessary to return .T. from an INITIATE action or no connection is made ***
IF gcAction = 'INITIATE'
glResult = .T.
ENDIF
IF gcAction = 'EXECUTE'
*** support a GRABDATA command - performs a DDERequest to WinWedge***
*** on COM2, requests data from FIELD(1) and stores it in a variable: "MyData"***
IF gData="[GRABDATA]"
gnChanNum = DDEInitiate('WinWedge', 'COM2')
IF gnChanNum != -1
MyData=DDERequest(gnChanNum,'Field(1)')
= DDETerminate(gnChanNum) && Close the channel
*** The variable 'MyData' now contains the data from Field(1) in WinWedge***
*** Your code goes here to do something with it ***
WAIT WINDOW MyData NOWAIT && For Example - Display the data
ENDIF
ENDIF
ENDIF
IF gcAction = 'TERMINATE'
glResult = .T.
ENDIF
RETURN glResult

 

Contact Us