Device Message Syntax
Introduction
When a Mendix application exchanges data with a device through the Workstation Connector, it sends and receives plain string messages. Every device type defines its own syntax for these messages, so your nanoflow logic must build and parse messages according to the device type it talks to.
This document describes the message and response syntax for every device type. Send messages with SendDeviceMessage or SendDeviceRequest, and read them with the onMessage callback of GetCreateDevice, WaitForDeviceMessage, or SubscribeToDeviceMessages. For more information, see Develop an App with the Workstation Connector.
To configure a device in a station, see Configuring Devices.
Card Readers
This device type requires the following message and response:
Message
Send an instruction in hexadecimal as a string, for example, FFCA000000 to read the smart card ID. The messages exchanged with the card reader are APDU messages. For more information, refer to the documentation of the APDU command for your smart card reader.
Response
0#- Card connected1#- Card disconnected2# Response- Response from device as raw hexadecimal3# Error- Error message from device
Bluetooth
This device type requires the following message and response:
Message
0#ServiceUUID#CharacteristicUUID- Subscribe to characteristicCharacteristicUUIDfrom serviceServiceUUID.1#ServiceUUID#CharacteristicUUID- Unsubscribe from characteristicCharacteristicUUIDfrom serviceServiceUUID.2#ServiceUUID#CharacteristicUUID- Read characteristicCharacteristicUUIDfrom serviceServiceUUID.3#ServiceUUID#CharacteristicUUID- Write to characteristicCharacteristicUUIDfrom serviceServiceUUID.
Response
CharacteristicUUID#Response
Example
The sample subscribe command 0#0000180f-0000-1000-8000-00805f9b34fb#00002a19-0000-1000-8000-00805f9b34fb contains the following elements:
0(command prefix) - Tells the Workstation Client to subscribe to a characteristic.- Separator
0000180f-0000-1000-8000-00805f9b34fb(ServiceUUID) - The standard Bluetooth SIG UUID for the Battery service.- Separator
00002a19-0000-1000-8000-00805f9b34fb(CharacteristicUUID) - The standard Bluetooth SIG UUID for the Battery Level characteristic.
Once subscribed, every notification from the device arrives as a response in the form 00002a19-0000-1000-8000-00805f9b34fb#Response, where Response is the raw value reported by the characteristic.
Instead of building these messages by hand, you can call the BLE_Subscribe, BLE_Unsubscribe, BLE_Read, and BLE_Write nanoflows from Workstation Commons, which take ServiceUUID and CharacteristicUUID as plain parameters.
Keyboard Wedge
Keyboard wedge devices are input-only, so Mendix applications do not send messages to them. When the Workstation Client recognizes a complete message, it forwards the payload to the Workstation Connector with the prefix and suffix removed.
Printer
This device type requires the following message and response:
Message
P#PrintJobDocName#Format#DataPayloadInBase64- Submit a print job.S- Get printer status and queued jobs.C#JobId- Cancel print job.
Response
P#DocName#JobId- Print job accepted by OS print interface.S#State#StateReason1,...#NumJobs#JobId1:JobName1:JobState1,...- Printer state and job list summary.E#ErrorMessage- Error.
Example
The sample print command P#TESTHELLO#RAW#aGVsbG8= contains the following elements:
P(command prefix) - Tells the Workstation Client that the incoming instruction is a Print command.- Separator
TESTHELLOFILE(file name) - Name assigned to the print job. The client uses this to create the temporary file (for example,TESTHELLOFILE.prn) before sending it to the printer spooler.- Separator
RAW(format type) - Tells the Workstation Client that the following data is a Raw Printer Command (such as ZPL for Zebra printers, EPL, or PCL) rather than a standard document like a PDF or a Word file. Printing in RAW bypasses the standard printer drivers' formatting. It sends the exact code the printer needs to generate labels, barcodes, or specific layouts.aGVsbG8=(payload) - A data string encoded to Base64. Base64 decoded, it translates to the texthello. If you are testing this and the printer is not reacting, verify that the string you are encoding in Base64 matches the specific language your printer speaks. For example, a Zebra printer cannot process a plain texthellounless it is wrapped in ZPL commands like^XA^FO50,50^A0N,50,50^FDhello^FS^XZ.
File Device
Before sending messages to the file device, review the following points:
- Path handling - You can provide the paths either as absolute paths (for example,
/var/log/app.logorC:\Data\report.txt), or as relative paths. Relative paths are always interpreted relative to the allowed folder configured in Workstation Management. - Delimiter - The
#character is used as a delimiter within messages. Paths and data may not contain the#character. - Case sensitivity - File and directory paths may be case-sensitive depending on the underlying operating system. For example, Linux paths are typically case-sensitive, while Windows paths are not.
Message
0#Path- Initiate watching for changes in the specifiedPath. IfPathis a directory, the device will watch for changes within that directory (creation, deletion, renaming, or modification of files/subdirectories). IfPathis a file, the device will watch for changes to that specific file (modification, deletion, or renaming).1#Path- Stop watching for changes in the specifiedPath.2#File path- Read the content of the file at the specifiedFile Path.3#File path#Data#flag- WriteDatato the file at the specifiedFile Path. Theflagcan bewfor overwrite,afor append; if left blank, the value defaults tow.
Response
R#Path- File or directory at the specifiedPathwas renamed, created, or deleted.C#Path- File or directory at the specifiedPathwas changed. This is triggered both when a file is modified and when the contents of a directory change.D#Data-Datafrom file read.E#Error-Errormessage from operating system.S#{0,1,2,3}#directory- The command{0,1,2,3}ondirectorywas successful.
Example
The sample write command 3#test.txt#Hello from Mendix#a contains the following elements:
3(command prefix) - Tells the Workstation Client that the incoming instruction is a write command.- Separator
test.txt(file path) - The file to write to, relative to the allowed folder configured for this device, for exampleC:\MyTestFolder\test.txt.- Separator
Hello from Mendix(data) - The text written to the file.- Separator
a(flag) - Appends the data to the end of the file instead of overwriting its contents.
The device answers with S#3#C:\MyTestFolder\test.txt, confirming that the write command completed successfully on that path.