Subsystem
Construction of SubSystems
A SubSystem consists of connected components. Thus, to construct a SubSystem, we first construct components, connect them and specify the input and output of SubSystem.
Basic Operation of SubSystems
The operation of a SubSystem is very similar to that of a StaticSystem. The only difference is that when a SubSystem is triggered through its trigger pin, it distributes the trigger to the trigger pins of its components. Then, each of the components of the SubSystem takes steps individually.
Let us construct a subsystem consisting of a generator and an adder.
julia> using Jusdl # hide
julia> gen = ConstantGenerator()
ConstantGenerator(amp:1.0)
julia> adder = Adder((+,+))
ERROR: MethodError: no method matching Adder(::Tuple{typeof(+),typeof(+)})
Closest candidates are:
Adder(::S, !Matched::IP, !Matched::OP, !Matched::RO, !Matched::TR, !Matched::HS, !Matched::CB, !Matched::Symbol, !Matched::ID) where {S, IP, OP, RO, TR, HS, CB, ID} at /home/sari/.julia/dev/Jusdl/src/components/systems/staticsystems/staticsystems.jl:104
Adder(; signs, input, output, readout, trigger, handshake, callbacks, name, id) at /home/sari/.julia/dev/Jusdl/src/components/componentsbase/macros.jl:55Connect the generator and adder.
julia> connect!(gen.output, adder.input[1])
ERROR: UndefVarError: adder not definedWe are ready to construct a SubSystem.
julia> sub = SubSystem([gen, adder], [adder.input[2]], adder.output)
ERROR: UndefVarError: adder not definedTo trigger the sub, we need to launch it. For that purpose, we construct ports and pins for input-output and signaling.
julia> oport, iport, trg, hnd = Outport(length(sub.input)), Inport(length(sub.output)), Outpin(), Inpin{Bool}()
ERROR: UndefVarError: sub not defined
julia> connect!(oport, sub.input)
ERROR: UndefVarError: sub not defined
julia> connect!(sub.output, iport)
ERROR: UndefVarError: sub not defined
julia> connect!(trg, sub.trigger)
ERROR: UndefVarError: sub not defined
julia> connect!(sub.handshake, hnd)
ERROR: UndefVarError: sub not defined
julia> t = launch(sub)
ERROR: UndefVarError: sub not defined
julia> t2 = @async while true
all(take!(iport) .=== NaN) && break
end
Task (failed) @0x00007fe233185fc0
UndefVarError: iport not defined
macro expansion at ./none:2 [inlined]
(::Main.ex-subsystem_ex.var"#1#2")() at ./task.jl:358sub is ready to be triggered,
julia> put!(trg, 1.)
ERROR: UndefVarError: trg not definedPut some data to the input of sub via oport (since oport is connected to sub.input)
julia> put!(oport, [1.])
ERROR: UndefVarError: oport not definedThe step needs to be approved.
julia> take!(hnd)
ERROR: UndefVarError: hnd not definedNow print the data written to the outputs of the components of sub.
julia> sub.components[1].output[1].links[1].buffer[1]
ERROR: UndefVarError: sub not defined
julia> sub.components[2].output[1].links[1].buffer[1]
ERROR: UndefVarError: sub not definedNote that when sub is triggered, sub transfer the trigger to all its internal components.