Table of Contents

Events & the SBIO Format String

An event's format string is the contract between Storyboard and your application. This page explains its grammar, how it maps to generated properties, and the two rules that will otherwise cost you an afternoon.

Table of Contents

Anatomy of an Event

The Format String

Type Codes

Arrays

Strings

How Field Names Become Property Names

Worked Example

Rules and Gotchas

Anatomy of an Event

Events are declared in the Storyboard project's events/custom.evt:

<event format="2u1 value 1u1 increase" name="change_brightness" type="0x20">
  <field name="increase">
    <attr f="i" k="sb.max_value">1</attr>
  </field>
  <field name="value"/>
</event>
Attribute Meaning
name Event name. Becomes the generated class name and the Name constant.
type Direction: 0x20 inbound (UI to application), 0x40 outbound (application to UI)
format Field layout — the subject of this page

You normally author these in Designer rather than by hand, but reading the raw file is the quickest way to check what your code will be generated against.

Note

Events whose names begin with gre. are Storyboard's own system events (animation completion and similar). They appear in custom.evt but carry no custom fields.

The Format String

The format is a flat, space-separated sequence of pairs: a type specifier followed by a field name.

2u1 value 1u1 increase
└┬┘ └─┬─┘ └┬┘ └──┬───┘
 │    │    │     └─ field name
 │    │    └─────── type specifier
 │    └──────────── field name
 └───────────────── type specifier

Each type specifier is three or more characters:

2u1
││└─ element count
│└── signedness: u unsigned, s signed, f float
└─── element size in bytes

Fields are packed with no padding, in declaration order. A field's offset is the sum of size × count for every field before it.

Type Codes

Specifier SBFieldType .NET type Bytes
4f1 Float_4f float 4
8u1 Int64_8u ulong 8
4u1 Int32_4u uint 4
2u1 Int16_2u ushort 2
1u1 Int8_1u byte 1
8s1 SignedInt64_8s long 8
4s1 SignedInt32_4s int 4
2s1 SignedInt16_2s short 2
1s1 SignedInt8_1s sbyte 1
1s0 String_1s string variable

Values are written in the host's native byte order. Both sides run on the same device, so this is not a concern in practice.

Arrays

A count greater than one declares an array. The generated property is an array of the element type, and the field occupies size × count bytes.

2u8 cylinder_temps

generates:

public UInt16[] CylinderTemps
{
    get { return OnGetValue<UInt16[]>(); }
    set { OnSetValue(value); }
}

The array is fixed length. Assigning an array of a different length writes only as many elements as the declared count.

Strings

A count of zero declares a string, whatever the size and signedness characters say. 1s0 is the conventional spelling.

Strings are UTF-8 and null-terminated, and they are variable length — which drives both rules below.

Important

A string must be the last field in its event. A string field advances the packing offset by size × 0, which is zero, so every field declared after it shares the string's offset and is unreachable. Reading a string takes every byte from its start offset to the end of the buffer.

Warning

Writing a string of the same length may not reach the display. Setting a property only commits when the value differs, and a string write is committed by replacing the buffer. Swapping "IDLE" for "STOP" — same length — can appear to do nothing. Make status labels differ in length, or pad them to distinct lengths. The MultiScreen demo's mode labels (IDLE / RUN / SERVICE) are deliberately different lengths for this reason.

How Field Names Become Property Names

Field names are snake_case in Storyboard and PascalCase in generated code. The conversion drops each underscore and capitalises the following letter, then capitalises the first letter:

Field name Generated property
percentage Percentage
signal_level SignalLevel
target_temperature TargetTemperature
cylinder_temps CylinderTemps

The same conversion is applied to event names to produce class names, so change_brightness becomes ChangeBrightness.

Worked Example

<event format="4u1 signal_level 1s0 ssid" name="connection_status" type="0x40"/>

Layout:

Field Specifier Offset Length
signal_level 4u1 0 4 bytes
ssid 1s0 4 to end of buffer

Generated:

public partial class ConnectionStatus : DemoViewModelBase
{
    public const string Name = "connection_status";
    public const string Format = "4u1 signal_level 1s0 ssid";
    public const StoryboardMessageDirection Direction = StoryboardMessageDirection.Out;

    public UInt32 SignalLevel { get => OnGetValue<UInt32>(); set => OnSetValue(value); }
    public String Ssid { get => OnGetValue<String>(); set => OnSetValue(value); }
}

Used:

var status = new ConnectionStatus();
status.SignalLevel = 72;
status.Ssid = "ShopFloor-2G";
client.SendEvent(status.Message);

Rules and Gotchas

Rule Why
A string must be the last field Zero-length packing makes later fields unreachable
Only one string per event Same reason — the first one consumes the rest of the buffer
Event names must be unique across every project in launchConfigurations All event files merge into one generated namespace
The format must match on both sides Nothing validates it; mismatched sizes silently produce wrong values
Changing a field's type changes the generated property's type Intentional — callers fail to compile rather than misbehave
Equal-length string writes may not commit See the warning above

Next: Generated Model Objects.