Documentation
¶
Overview ¶
Package sim provides a synthetic driver.Driver that generates values from simple time-based waveforms, so silk HMIs can run, be demoed and be tested without any real PLC or field device attached (the "仿真" / simulation mode familiar from FameView and other SCADA tools).
A point's Address encodes the waveform and its parameters as "<wave>:<params>":
sine:min=0,max=100,period=10s smooth 0.5+0.5*sin, one full cycle per period ramp:min=0,max=100,period=5s linear sawtooth min->max, repeating each period toggle:period=2s bool, flips every period const:42 a fixed number random:min=0,max=100 a value in [min,max], deterministic per instant
Params are comma-separated key=value pairs; min and max default to 0 and 100, period defaults to 1s when omitted. const takes a single bare number instead of key=value pairs. period is any Go duration (time.ParseDuration).
Waveform values track elapsed = Now()-start, where start is captured in NewSim and Now is an injectable clock (time.Now in production, a pinned function in tests). WritePoint records an override keyed by Address; a subsequent ReadPoint of that Address returns the written value instead of the waveform, so a read-write point behaves like a holding register once set.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sim ¶
type Sim struct {
// Now is the clock used for elapsed time. Defaults to time.Now in NewSim;
// tests replace it with a pinned function to control the waveform phase.
Now func() time.Time
// contains filtered or unexported fields
}
Sim is a hardware-free driver.Driver. Connect/Close are no-ops. ReadPoint derives a value from the point's Address waveform (or a prior WritePoint override); WritePoint stores an override under the Address.
func NewSim ¶
func NewSim() *Sim
NewSim builds a simulator with the real clock and the current time as its waveform origin.