TransportDelay

model TransportDelay "Transport delay with initial parameter"
    import D = Modelica.Electrical.Digital;
    import L = Modelica.Electrical.Digital.Interfaces.Logic;

    extends D.Interfaces.SISO(x(start = L.'U', fixed = true));

    parameter SI.Time delayTime(start = 0) "delay time";
    parameter D.Interfaces.Logic y0 = L.'U' "initial value of output";
    constant D.Interfaces.Logic LogicValues[:] = L.'U':L.'-';
protected
    D.Interfaces.Logic x_delayed;
    Real xr "Auxiliary variable of type Real to use in delay()";
equation
    y = if 0 < delayTime then if delayTime <= time then x_delayed else y0 else pre(x);
    x_delayed = LogicValues[integer(delay(xr, delayTime))];
    xr = Integer(pre(x));

    annotation (
        Documentation(
            info = "<html>\n<p>\nProvide the input as output exactly delayed by <em>Tdel</em>.\nIf time less than <em>Tdel</em> the initial value <em>initout</em> holds.\n</p>\n</html>",
            revisions = "<html>\n<dl>\n<dt><em>August 11, 2003</em></dt>\n<dd>by Christoph Clauss initially modelled.</dd>\n</dl>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {152, -160}, 
                        {-148, -100}},
                    lineColor = {0, 0, 255},
                    textString = "%name"), 
                Rectangle(
                    extent = {
                        {-50, 100}, 
                        {50, -100}},
                    lineThickness = 0.5,
                    fillColor = {213, 170, 255},
                    fillPattern = FillPattern.Solid), 
                Polygon(points = {
                    {-6, 60}, 
                    {-16, 40}, 
                    {4, 40}, 
                    {-6, 60}}), 
                Line(points = {
                    {0, 60}, 
                    {20, 60}}), 
                Line(points = {
                    {10, 60}, 
                    {10, 40}}), 
                Text(
                    extent = {
                        {-50, -40}, 
                        {50, -20}},
                    textString = "Transport"), 
                Text(
                    extent = {
                        {-50, -60}, 
                        {50, -40}},
                    textString = "Delay")}));
end TransportDelay;