Steps For Setting Up WinWedge:
1. Select "DDE Server" from WinWedge
MODE menu. When the dialog box appears asking for a DDE Command Destination Application,
enter: MyServer as the Application Name and enter MyTopic as the DDE topic.
2. Select "Input Data Record Structure" from the
DEFINE menu and define the structure of the input records to WinWedge. When you get to the
final Window entitled "Input Record Definition Editor", enter the string: [GRABDATA]
as the "Field Postamble DDE Command" after the last data field that you have
defined. This is a DDE command that will be sent to your FoxPro application after each
data record is received by the Wedge.
3. Set up the rest of WinWedge parameters and
activate it.
Steps For Setting Up FoxPro:
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
|