Accessing the Data Store

Purpose

To demonstrate how to use Python to obtain data store keys and their corresponding values via gRPC. The data store can be used to communicate with running EcScripts. For example, an external appliation can set or get values for object locations in the data store, while an EcScript creates a path toward the object based on the location in the Data Store. Access to the Data Store is safed, controlled by the RCF Data Access Layer.

Download & Setup:

  1. Project Requirements:

    Project Prerequisites

  2. Download this XML file and place it in ~/projects/myProject/rcf/:

    deviceDataStore.xml

  3. Make a backup copy of ~/projects/myProject/rcf/system_controller.xml.

  4. Edit the system_controller.xml file. Find the tag <dataStoreElements> tag. Paste the following code below the tag.

    <!-- data elements for the EcScript application -->
    <xi:include href="deviceDataStore.xml" parse="xml"/>
  5. Project Startup:

    Project Startup

  6. Download this zip file, which contains the example code:

    pyDataStoreExample.zip

  7. Open a terminal window:

    Unzip into a new folder. we suggest: projects/examples/pyDataStoreExample

  8. Build the gRPC bindings using the actin proto files:

    $ python compile_protos_datastore.py

    This will create an actin folder with these contents in ~/projects/examples/pyDataStoreExample :

    actin/rpc/api/common/common_types_pb2.py
    actin/rpc/api/data_store/data_store_types_pb2.py
    actin/rpc/api/data_store/data_store_service_pb2.py
    actin/rpc/api/data_store/data_store_service_pb2_grpc.py

Run the python gRPC Example:

Open a new terminal window, then run the data store client:

$ python ds_client.py

You should see output similar to the following:

----------------
Data Store Paths Matching '.*' Pattern (count=N):
  - /
  - /app
  ...
----------------
Data Store Elements At '/app' Path (count=5):
  - [String] DEVICE_LABEL
  - [Boolean] DEVICE_IS_READY
  - [Int16] DEVICE_REGISTERS
  - [Float64] DEVICE_OFFSET
----------------
Writing 'GRIP_D1' to element '[String] DEVICE_LABEL@@/app'...
Read 'GRIP_D1' from element '[String] DEVICE_LABEL@@/app'.
Writing 'GRIP_D2' to element '[String] DEVICE_LABEL@@/app'...
Read 'GRIP_D2' from element '[String] DEVICE_LABEL@@/app'.
----------------
Writing 'False' to element '[Boolean] DEVICE_IS_READY@@/app'...
Read 'False' from element '[Boolean] DEVICE_IS_READY@@/app'.
Writing 'True' to element '[Boolean] DEVICE_IS_READY@@/app'...
Read 'True' from element '[Boolean] DEVICE_IS_READY@@/app'.
----------------
Writing '78' to element '[Int16] DEVICE_REGISTERS@@/app'...
Read '78' from element '[Int16] DEVICE_REGISTERS@@/app'.
Writing '163' to element '[Int16] DEVICE_REGISTERS@@/app'...
Read '163' from element '[Int16] DEVICE_REGISTERS@@/app'.
----------------
Writing '127.38' to element '[Float64] DEVICE_OFFSET@@/app'...
Read '127.38' from element '[Float64] DEVICE_OFFSET@@/app'.
Writing '245.9687' to element '[Float64] DEVICE_OFFSET@@/app'...
Read '245.9687' from element '[Float64] DEVICE_OFFSET@@/app'.
----------------
Creating element '[Int64] NEW_NUMBER@@/app' with value '123'...
Writing '777' to element '[Int64] NEW_NUMBER@@/app'...
Read '777' from element '[Int64] NEW_NUMBER@@/app'.

Clean up

After testing the python application, clean up in this order:

  • Close the python app
  • Close ActinViz
  • Stop RCF (Ctrl-C)

Note: You can shutdown and restart the python app with RCF running. Just reconnect, load a script, and play.

Getting Help

If you are running into problems running this python example, please contact us at support@energid.com. We can help