|
| 1 | +--- |
| 2 | +title: "Developing Workstation-Enabled Applications" |
| 3 | +url: /mendix-workstation/build-app/ |
| 4 | +description: "Describes the key concepts and best practices to consider when building an app to work with Mendix Workstation." |
| 5 | +weight: 25 |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +To start using Mendix Workstation, implement your own custom logic for interacting with devices. The following nanoflows and actions serve as the core building blocks for integrating devices into your Mendix applications and tailoring the functionality to your specific requirements. |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +To help you develop your application, familiarize yourself with the [Mendix Studio Pro Guide](/refguide/), especially the following topics: |
| 15 | + |
| 16 | +* [Studio Pro Overview](/refguide/studio-pro-overview/) |
| 17 | +* [Data in the Domain Model](/refguide/domain-model/) |
| 18 | +* [Pages](/refguide/pages/) |
| 19 | +* [Microflows and Nanoflows](/refguide/microflows-and-nanoflows/) |
| 20 | +* [Development Best Practices](/refguide/dev-best-practices/) |
| 21 | + |
| 22 | +## Understanding the Domain Model |
| 23 | + |
| 24 | +The Workstation domain model contains the following entities: |
| 25 | + |
| 26 | +* **Station** - A non-persistent entity representing the Workstation Client configuration. |
| 27 | +* **Device** - A non-persistent entity representing a connectable peripheral device. Includes the name, class and state (Available, Connected, or Error). Specialize this to maintain your device specific state. |
| 28 | +* **AppKeyPair** - A persistent entity to store the app's key pair. The public key needs to be entered in the corresponding app in the Workstation Management. |
| 29 | + |
| 30 | +## Using the Nanoflows and Actions {#javascript-actions} |
| 31 | + |
| 32 | +The following section provides more information about using the Workstation nanoflows and Java actions in your Mendix application. |
| 33 | + |
| 34 | +#### SendDeviceRequest |
| 35 | + |
| 36 | +Call `SendDeviceRequest` to send a message to a device and return the response or error. Requires Workstation Client 4.0 or later, and a device that supports requests. For more information about the supported message syntax, see [Configuring Devices](/mendix-workstation/management-devices/). This action has the following parameters: |
| 37 | + |
| 38 | +* `device` |
| 39 | +* `message` |
| 40 | + |
| 41 | +### SendDeviceMessage |
| 42 | + |
| 43 | +Call `SendDeviceMessage` to send a message to a device. For more information about the supported message syntax, see [Configuring Devices](/mendix-workstation/management-devices/). This action has the following parameters: |
| 44 | + |
| 45 | +* `device` |
| 46 | +* `message` |
| 47 | + |
| 48 | +Responses are passed through message callbacks. For more information, see `GetCreateDevice` (`onMessage`), `WaitForDeviceMessage`, and `SubscribeToDeviceMessages`. |
| 49 | + |
| 50 | +### WaitForDeviceMessage |
| 51 | + |
| 52 | +Call `WaitForDeviceMessage` to wait for a message from the connected device for the duration of the specified timeout period. This action has the following parameters: |
| 53 | + |
| 54 | +* `device` |
| 55 | +* `timeout` |
| 56 | + |
| 57 | +### WaitForObjectChange |
| 58 | + |
| 59 | +Call `WaitForObjectChange` to wait for changes in the attributes of the specified object for the duration of the specified timeout period. This action has the following parameters: |
| 60 | + |
| 61 | +* `objectToObserve` |
| 62 | +* `attributes` |
| 63 | +* `timeout` |
| 64 | + |
| 65 | +### GetCreateDevice |
| 66 | + |
| 67 | +Call this nanoflow to create and configure a device, and define the actions that should happen on connection, disconnection, or messages from the device. This action has the following parameters: |
| 68 | + |
| 69 | +* `name` |
| 70 | +* `class` |
| 71 | +* `initialize` |
| 72 | +* `createDevice` |
| 73 | +* `entity` |
| 74 | +* `onConnect` |
| 75 | +* `onMessage` |
| 76 | +* `onDisconnect` |
| 77 | + |
| 78 | +### ConnectDevice |
| 79 | + |
| 80 | +Call this action to connect to a specific device. |
| 81 | + |
| 82 | +### DisconnectDevice |
| 83 | + |
| 84 | +Call this action to disconnect from a specific device. |
| 85 | + |
| 86 | +### Initialize |
| 87 | + |
| 88 | +This action sets up communication with the Workstation Client. It should be automatically called through the `initialize` parameter of `GetStation` or `GetCreateDevice`. |
| 89 | + |
| 90 | +### GetStation |
| 91 | + |
| 92 | +Call `GetStation` to retrieve the current Workstation Client configuration and devices. This action creates and returns a station object with a linked device object per peripheral. |
| 93 | + |
| 94 | +To interact with a specific device, it is better to use `GetCreateDevice` instead. `GetCreateDevice` has a more convenient API, allows specialization, and does not create station and device objects which may not be needed. |
| 95 | + |
| 96 | +### SubscribeToObjectChanges |
| 97 | + |
| 98 | +Call `SubscribeToObjectChanges` to trigger a nanoflow when the specified object changes. This action has the following parameters: |
| 99 | + |
| 100 | +* `objectToObserve` |
| 101 | +* `attributes` |
| 102 | +* `callback` |
| 103 | +* `applicationContext` |
| 104 | + |
| 105 | +### SubscribeToDeviceMessages |
| 106 | + |
| 107 | +Call `SubscribeToDeviceMessages` to trigger a nanoflow when a message is received from a device. This action has the following parameters: |
| 108 | + |
| 109 | +* `device` |
| 110 | +* `callback` |
| 111 | +* `applicationContext` |
| 112 | + |
| 113 | +### SubscribeToDeviceErrors |
| 114 | + |
| 115 | +Call `SubscribeToDeviceErrors` to trigger a nanoflow on device connection error. This action has the following parameters: |
| 116 | + |
| 117 | +* `device` |
| 118 | +* `callback` |
| 119 | +* `applicationContext` |
| 120 | + |
| 121 | +### Unsubscribe |
| 122 | + |
| 123 | +Call `Unsubscribe` to end a subscription. |
| 124 | + |
| 125 | +### Private Nanoflows |
| 126 | + |
| 127 | +`CreateStation`, `CommitStation`, `CreateDevice`, and `CommitDevice` are private nanoflows, required be compatible with [strict mode](/refguide/strict-mode/). |
| 128 | + |
| 129 | +## Widgets {#widgets} |
| 130 | + |
| 131 | +The following widgets allow you to specify when to execute an action: |
| 132 | + |
| 133 | +* **On Load/Unload** - Execute the action when the widget is first rendered, or when it is removed (unloaded). |
| 134 | +* **On Change** - Execute the action when the specified attribute changes. |
| 135 | +* **On Equal** - Execute the action when an attribute is equal to the specified expression. |
| 136 | +* **On True** - Execute the action when the specified expression is true. |
| 137 | + |
| 138 | +## Error Logs |
| 139 | + |
| 140 | +Logs for the Workstation Management, Client, and Connector are available in case of issues. For more information about accessing the logs, see [Troubleshooting Mendix Workstation](/mendix-workstation/troubleshooting/). |
| 141 | + |
| 142 | +## Deploying Your Application |
| 143 | + |
| 144 | +There are multiple ways to deploy a Mendix application. You can deploy to your local machine for development and testing. You can deploy to Mendix Cloud, which is the default location for both free and licensed apps. You can also deploy to SAP Business Technology (SAP BTP) Platform, Kubernetes and Cloud Foundry-based platforms, Docker containers, Azure, or to a server you configured yourself. For more information, see [Deploying Apps](/deployment/). |
0 commit comments