This is the description of the Modbus protocol for the RED Brick. General information and technical specifications for the RED Brick are summarized in its hardware description.
A general description of the Modbus protocol structure can be found here.
The RED Brick API is meant to be used by the Brick Viewer to implement the offered functionality (getting status information, managing programs etc.). Normal users will not need to use this API, it may only be interesting for power users.
FIXME: explain sessions
The RED Brick API operates on reference counted objects (strings, lists, files, directories, processes and programs) that are identified by their 16bit object ID. Functions that allocate or return an object ID (e.g. allocate_string and get_next_directory_entry) increase the reference count of the returned object. If the object is no longer needed then release_object has to be called to decrease the reference count of the object again. In contrast to allocation and getter functions, the reference count for an object returned by a callback is not increased and release_object must not be called for such an object in response to a callback.
There are functions (e.g. get_file_info) that only return valid objects under certain conditions. This conditions are documented for the specific functions. For invalid objects release_object must not be called.
There are also function (e.g. set_program_stdio_redirection) that have conditionally unused object parameters. Under which conditions an object parameter is unused is documented for the specific functions. For unused object parameters 0 has to be passed as object ID.
The RED Brick API is more complex then the typical Brick API and requires more elaborate error reporting than the TCP/IP protocol can provide with its 2bit error code. Therefore, almost all functions of the RED Brick API return an 8bit error code. Possible error codes are:
If a function returns an error code other than Success then its other return values (if any) are invalid and must not be used.
The error code InvalidOperation is returned if the requested operation cannot be performed because the current state of the object does not allow it. For example, trying to append an item to a full list object or trying to undefine an already undefined program.
The error code NotSupported is returned if the requested operation can never be performed. For example, trying to append a list object to itself, trying to get the name of a file object with type Pipe or trying to create a directory non-recursively with more than the last part of the directory name referring to non-existing directories.
String objects store UTF-8 encoded data.
Function ID: | 1 |
---|---|
Request: |
|
Response: |
|
Function ID: | 2 |
---|---|
Request: |
|
Response: |
|
Function ID: | 3 |
---|---|
Request: |
|
Response: | no response |
Function ID: | 4 |
---|---|
Request: |
|
Response: |
|
Function ID: | 5 |
---|---|
Request: |
|
Response: |
|
Decreases the reference count of an object by one and returns the resulting error code. If the reference count reaches zero the object gets destroyed.
Function ID: | 6 |
---|---|
Request: |
|
Response: | no response |
Function ID: | 7 |
---|---|
Request: |
|
Response: |
|
Allocates a new string object, reserves length_to_reserve bytes memory for it and sets up to the first 60 bytes. Set length_to_reserve to the length of the string that should be stored in the string object.
Returns the object ID of the new string object and the resulting error code.
Function ID: | 8 |
---|---|
Request: |
|
Response: |
|
Truncates a string object to length bytes and returns the resulting error code.
Function ID: | 9 |
---|---|
Request: |
|
Response: |
|
Returns the length of a string object in bytes and the resulting error code.
Function ID: | 10 |
---|---|
Request: |
|
Response: |
|
Sets a chunk of up to 58 bytes in a string object beginning at offset.
Returns the resulting error code.
Function ID: | 11 |
---|---|
Request: |
|
Response: |
|
Returns a chunk up to 63 bytes from a string object beginning at offset and returns the resulting error code.
Function ID: | 12 |
---|---|
Request: |
|
Response: |
|
Allocates a new list object and reserves memory for length_to_reserve items. Set length_to_reserve to the number of items that should be stored in the list object.
Returns the object ID of the new list object and the resulting error code.
When a list object gets destroyed then the reference count of each object in the list object is decreased by one.
Function ID: | 13 |
---|---|
Request: |
|
Response: |
|
Returns the length of a list object in items and the resulting error code.
Function ID: | 14 |
---|---|
Request: |
|
Response: |
|
Returns the object ID and type of the object stored at index in a list object and returns the resulting error code.
Possible object types are:
Function ID: | 15 |
---|---|
Request: |
|
Response: |
|
Appends an object to a list object and increases the reference count of the appended object by one.
Returns the resulting error code.
Function ID: | 16 |
---|---|
Request: |
|
Response: |
|
Removes the object stored at index from a list object and decreases the reference count of the removed object by one.
Returns the resulting error code.
Function ID: | 17 |
---|---|
Request: |
|
Response: |
|
Opens an existing file or creates a new file and allocates a new file object for it.
FIXME: name has to be absolute
The reference count of the name string object is increased by one. When the file object gets destroyed then the reference count of the name string object is decreased by one. Also the name string object is locked and cannot be modified while the file object holds a reference to it.
The flags parameter takes a ORed combination of the following possible file flags (in hexadecimal notation):
FIXME: explain Temporary and Replace flag
The permissions parameter takes a ORed combination of the following possible file permissions (in octal notation) that match the common UNIX permission bits:
Returns the object ID of the new file object and the resulting error code.
Function ID: | 18 |
---|---|
Request: |
|
Response: |
|
Creates a new pipe and allocates a new file object for it.
The flags parameter takes a ORed combination of the following possible pipe flags (in hexadecimal notation):
The length of the pipe buffer can be specified with the length parameter in bytes. If length is set to zero, then the default pipe buffer length is used.
Returns the object ID of the new file object and the resulting error code.
Function ID: | 19 |
---|---|
Request: |
|
Response: |
|
Returns various information about a file and the resulting error code.
Possible file types are:
If the file type is Pipe then the returned name string object is invalid, because a pipe has no name. Otherwise the returned name string object was used to open or create the file object, as passed to open_file.
The returned flags were used to open or create the file object, as passed to open_file or create_pipe. See the respective function for a list of possible file and pipe flags.
FIXME: everything except flags and length is invalid if file type is Pipe
Function ID: | 20 |
---|---|
Request: |
|
Response: |
|
Reads up to 62 bytes from a file object.
Returns the bytes read, the actual number of bytes read and the resulting error code.
If there is not data to be read, either because the file position reached end-of-file or because there is not data in the pipe, then zero bytes are returned.
If the file object was created by open_file without the NonBlocking flag or by create_pipe without the NonBlockingRead flag then the error code NotSupported is returned.
Function ID: | 21 |
---|---|
Request: |
|
Response: | no response |
Reads up to 263 - 1 bytes from a file object asynchronously.
Reports the bytes read (in 60 byte chunks), the actual number of bytes read and the resulting error code via the CALLBACK_ASYNC_FILE_READ callback.
If there is not data to be read, either because the file position reached end-of-file or because there is not data in the pipe, then zero bytes are reported.
If the file object was created by open_file without the NonBlocking flag or by create_pipe without the NonBlockingRead flag then the error code NotSupported is reported via the CALLBACK_ASYNC_FILE_READ callback.
Function ID: | 22 |
---|---|
Request: |
|
Response: |
|
Aborts a read_file_async operation in progress.
Returns the resulting error code.
On success the CALLBACK_ASYNC_FILE_READ callback will report OperationAborted.
Function ID: | 23 |
---|---|
Request: |
|
Response: |
|
Writes up to 61 bytes to a file object.
Returns the actual number of bytes written and the resulting error code.
If the file object was created by open_file without the NonBlocking flag or by create_pipe without the NonBlockingWrite flag then the error code NotSupported is returned.
Function ID: | 24 |
---|---|
Request: |
|
Response: | no response |
Writes up to 61 bytes to a file object.
Does neither report the actual number of bytes written nor the resulting error code.
If the file object was created by open_file without the NonBlocking flag or by create_pipe without the NonBlockingWrite flag then the write operation will fail silently.
Function ID: | 25 |
---|---|
Request: |
|
Response: | no response |
Writes up to 61 bytes to a file object.
Reports the actual number of bytes written and the resulting error code via the CALLBACK_ASYNC_FILE_WRITE callback.
If the file object was created by open_file without the NonBlocking flag or by create_pipe without the NonBlockingWrite flag then the error code NotSupported is reported via the CALLBACK_ASYNC_FILE_WRITE callback.
Function ID: | 26 |
---|---|
Request: |
|
Response: |
|
Set the current seek position of a file object in bytes relative to origin.
Possible file origins are:
Returns the resulting absolute seek position and error code.
If the file object was created by create_pipe then it has no seek position and the error code InvalidSeek is returned.
Function ID: | 27 |
---|---|
Request: |
|
Response: |
|
Returns the current seek position of a file object in bytes and returns the resulting error code.
If the file object was created by create_pipe then it has no seek position and the error code InvalidSeek is returned.
Function ID: | 28 |
---|---|
Request: |
|
Response: |
|
Function ID: | 29 |
---|---|
Request: |
|
Response: |
|
Function ID: | 33 |
---|---|
Request: |
|
Response: |
|
Opens an existing directory and allocates a new directory object for it.
FIXME: name has to be absolute
The reference count of the name string object is increased by one. When the directory object is destroyed then the reference count of the name string object is decreased by one. Also the name string object is locked and cannot be modified while the directory object holds a reference to it.
Returns the object ID of the new directory object and the resulting error code.
Function ID: | 34 |
---|---|
Request: |
|
Response: |
|
Returns the name of a directory object, as passed to open_directory, and the resulting error code.
Function ID: | 35 |
---|---|
Request: |
|
Response: |
|
Returns the next entry in a directory object and the resulting error code.
If there is not next entry then error code NoMoreData is returned. To rewind a directory object call rewind_directory.
Possible directory entry types are:
Function ID: | 36 |
---|---|
Request: |
|
Response: |
|
Rewinds a directory object and returns the resulting error code.
Function ID: | 37 |
---|---|
Request: |
|
Response: |
|
FIXME: name has to be absolute
Function ID: | 38 |
---|---|
Request: |
|
Response: |
|
Function ID: | 39 |
---|---|
Request: |
|
Response: |
|
Function ID: | 40 |
---|---|
Request: |
|
Response: |
|
Sends a UNIX signal to a process object and returns the resulting error code.
Possible UNIX signals are:
Function ID: | 41 |
---|---|
Request: |
|
Response: |
|
Returns the executable, arguments, environment and working directory used to spawn a process object, as passed to spawn_process, and the resulting error code.
Function ID: | 42 |
---|---|
Request: |
|
Response: |
|
Returns the process ID and the user and group ID used to spawn a process object, as passed to spawn_process, and the resulting error code.
The process ID is only valid if the state is Running or Stopped, see get_process_state.
Function ID: | 43 |
---|---|
Request: |
|
Response: |
|
Returns the stdin, stdout and stderr files used to spawn a process object, as passed to spawn_process, and the resulting error code.
Function ID: | 44 |
---|---|
Request: |
|
Response: |
|
Returns the current state, timestamp and exit code of a process object, and the resulting error code.
Possible process states are:
The timestamp represents the UNIX time since when the process is in its current state.
The exit code is only valid if the state is Error, Exited, Killed or Stopped and has different meanings depending on the state:
Possible exit/error codes in Error state are:
The CannotExecute error can be caused by the executable being opened for writing.
Function ID: | 46 |
---|---|
Request: |
|
Response: |
|
Function ID: | 47 |
---|---|
Request: |
|
Response: |
|
Function ID: | 48 |
---|---|
Request: |
|
Response: |
|
Function ID: | 49 |
---|---|
Request: |
|
Response: |
|
Function ID: | 50 |
---|---|
Request: |
|
Response: |
|
FIXME: root directory is absolute: <home>/programs/<identifier>
Function ID: | 51 |
---|---|
Request: |
|
Response: |
|
FIXME: working directory is relative to <home>/programs/<identifier>/bin
Function ID: | 52 |
---|---|
Request: |
|
Response: |
|
FIXME: working directory is relative to <home>/programs/<identifier>/bin
Function ID: | 53 |
---|---|
Request: |
|
Response: |
|
FIXME: stdio file names are relative to <home>/programs/<identifier>/bin
Function ID: | 54 |
---|---|
Request: |
|
Response: |
|
FIXME: stdio file names are relative to <home>/programs/<identifier>/bin
Function ID: | 55 |
---|---|
Request: |
|
Response: |
|
Function ID: | 56 |
---|---|
Request: |
|
Response: |
|
Function ID: | 57 |
---|---|
Request: |
|
Response: |
|
FIXME: message is currently valid in error-occurred state only
Function ID: | 58 |
---|---|
Request: |
|
Response: |
|
Function ID: | 59 |
---|---|
Request: |
|
Response: |
|
Function ID: | 60 |
---|---|
Request: |
|
Response: |
|
Function ID: | 61 |
---|---|
Request: |
|
Response: |
|
Function ID: | 62 |
---|---|
Request: |
|
Response: |
|
Function ID: | 63 |
---|---|
Request: |
|
Response: |
|
Function ID: | 64 |
---|---|
Request: |
|
Response: |
|
Function ID: | 255 |
---|---|
Request: | empty payload |
Response: |
|
Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.
The position can be '0'-'8' (stack position).
The device identifier numbers can be found here.
Function ID: | 30 |
---|---|
Response: |
|
This callback reports the result of a call to the read_file_async function.
Function ID: | 31 |
---|---|
Response: |
|
This callback reports the result of a call to the write_file_async function.
Function ID: | 32 |
---|---|
Response: |
|
Function ID: | 45 |
---|---|
Response: |
|
Function ID: | 65 |
---|---|
Response: |
|
Function ID: | 66 |
---|---|
Response: |
|