WinForms Adapter
The WinForms adapter marshals channel events and point changes to the UI thread and provides control binding helpers so each form does not need custom InvokeRequired code.
var attachment = this.AttachZeus(builder => builder.AddVirtualChannel("meter"));
var meter = attachment.Host.Channels.Get("meter");
meter.BindState(stateLabel);
meter.BindText(echoLabel);
meter.BindText(hexLabel, ChannelTextFormatter.Hex);
meter.BindEnabled(sendButton);
Assembly: Zeus.Presentation.WinForms with target framework net8.0-windows.
APIs
| API | Purpose |
|---|---|
Form.AttachZeus(...) | Starts on load and disposes on form close |
host.AttachManually() | Creates the attachment without binding a window; useful after login or for tray apps |
BindText | Writes received data to Control.Text |
BindState | Displays channel state |
BindEnabled | Sets Control.Enabled, defaulting to enabled only when Open |
AsBindingSource(control) | Exposes an INotifyPropertyChanged projection |
points.BindText("temperature", label) | Writes point value to a control |
points.BindSnapshot(...) | Pushes full point snapshots to the UI thread |
points.BindGauge(...) | Maps the current value onto a progress bar |
points.AsBindingSource("temperature", control) | Single-point INotifyPropertyChanged projection |
alarms.BindAlarms(...) | Pushes the active alarm list to the UI thread |
alarms.AsAlarmBindingSource(control) | Alarm-queue INotifyPropertyChanged projection |
points.BindEnabled("setpoint", button) | Enables a button from writable / error state |
points.BindAlarmBackColor / BindAlarmForeColor | Changes colors based on alarm/error state |
points.BindWriteBack | Binds a button click to Points.WriteAsync |
Destroyed controls or controls without handles ignore updates.
Point Binding
points.BindText("temperature", temperatureLabel, value => $"{value:0.0} C");
points.BindAlarmBackColor("temperature", temperatureLabel);
points.BindSnapshot("temperature", alarmLabel, snapshot =>
{
alarmLabel.Text = snapshot.AlarmState.ToString();
});
points.BindEnabled("setpoint", writeButton);
points.BindWriteBack(
"setpoint",
setpointTextBox,
writeButton,
text => double.Parse(text, CultureInfo.InvariantCulture),
ex => MessageBox.Show(this, ex.Message, "Write failed", MessageBoxButtons.OK, MessageBoxIcon.Warning));
If you already use WinForms data binding, bind the projection:
var source = points.AsBindingSource("temperature", this);
temperatureLabel.DataBindings.Add("Text", source, nameof(PointBindingSource.Text));
alarmLabel.DataBindings.Add("Text", source, nameof(PointBindingSource.AlarmState));
A few labels, alarm colors, and write-back buttons should stay on the per-point helpers above. For a DataGrid, overview, or dozens of points on one screen, use points.AsTableBindingSource(this): it only projects the core BatchChanged event into a bindable list, once per poll. Do not bind every point separately and then Clear/Add on Changed. Keep write-back text boxes on per-point bindings so a table refresh cannot overwrite an in-progress edit. The point-table events themselves are UI-agnostic; see Point Tables and Acquisition.
Trend charts and report histories should subscribe to points.Changed / points.BatchChanged and store their own samples. Zeus does not keep point-history buffers or chart adapters. Prefer BatchChanged for multi-point trends.
Common Issues
- Cross-thread exception: use this package's
BindText,BindState, or point-table binding extensions instead of updating controls insideDataReceived. - Serial port remains busy after closing: use
AttachZeusor dispose the host yourself. - Need to bind another property: use a specific helper when available, or map it yourself through
BindSnapshot.