Implementing a Simple ThingPoint Application

From RAD Studio
Jump to: navigation, search

Go Up to ThingPoint Overview


You can create a new ThingPoint application to listen for requests from the EMS Server, and respond with the needed data.

You need the following components in your ThingPoint application:

  • The TEMSProvider component is used to set up the connection with the EMS Server.
  • The TEMSEdgeService component is used to listen for requests from the EMS Server.

You need the following components in your EMS Client application:

  • The TEMSProvider component is used to set up the connection with the EMS Server.
  • The TBackendEndpoint component is used to access a particular resource from the ThingPoint.

The EMS Server should be set up and running for this sample.

Creating a ThingPoint Application

  1. Create a new Multi-Device Application.
    • For Delphi: Open File > New > Multi-Device Application - Delphi
    • For C++: Open File > New > Multi-Device Application - C++Builder
  2. In the Tool Palette, search for a TEMSProvider component and drop it on the form.
  3. In the Object Inspector, configure the EMS Server parameters according to the EMS server configuration:
    • URLHost: localhost
    • URLPort: 8080
    • URLProtocol: http
  4. Click the Test Connection button. If the connection is successfully set up, you will get a message with the current version of the EMS Server.
  5. In the Tool Palette, search for a TEMSEdgeService component and drop it on the form.
  6. In the Object Inspector, configure the following TEMSEdgeService parameters:
    • Provider: EMSProvider1
    • ModuleName: WinEdge1
  7. In the Object Inspector, configure the following TEMSEdgeService parameters to listen to EMS server requests:
    • ListenerProtocol: http
    • ListenerService.Host: localhost
    • ListenerService.Port: 8081
  8. Build and run your application. Click F9 or Run.
    Note: You can only run a ThingPoint on the 32-bit Windows, 64-bit Windows, and OS X target platforms.

Creating an EMS Client Application to Retrieve ThingPoint Data

  1. Create a new Multi-Device Application:
    • For Delphi: Open File > New > Multi-Device Application - Delphi
    • For C++: Open File > New > Multi-Device Application - C++Builder
  2. In the Tool Palette, search for a TEMSProvider component and drop it on the form.
  3. In the Object Inspector, configure the EMS server parameters according to the EMS server configuration:
    • URLHost: localhost
    • URLPort: 8080
    • URLProtocol: http
  4. Drop a TBackendEndpoint component on the form.
  5. In the Object Inspector, set the following parameters of the TBackendEndpoint to use the ThingPoint resource:
    • Provider. In the drop-down list, select the name of the TEMSProvider component (EMSProvider1).
    • Resource: edgemodules/WinEdge1/version
    • Resource suffix: Leave it blank for this tutorial.
    • Method: rmGET
    TBackendEndpointConfigurationThingPointVersion.png

Visually Binding the Response Data

  1. Open the LiveBindings Designer to visually bind the response data from the ThingPoint. Select View > LiveBindings Designer.
  2. In the LiveBindings Designer, right-click the Response.JSONText property of the TBackendEndpoint component and choose the Link to new control option to link the response to a new TMemo component.
    EMSClientDesignViewThingPoint.png
  3. Drop a new TButton component on your form.
  4. Create the OnClick event of the TButton component (double-click on it) and add the following code:
    • Delphi:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        BackendEndpoint1.Execute;
    end;
    
    • C++:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        BackendEndpoint1->Execute();
    }
    
  5. Build and run your application.
    EMSClientExecutionThingPoint.png

See Also