LogicToBoolean

block LogicToBoolean "Logic to Boolean converter"
    import L = Modelica.Electrical.Digital.Interfaces.Logic;

    Modelica.Electrical.Digital.Interfaces.DigitalInput x[n] annotation (Placement(transformation(extent = {
        {-60, -10}, 
        {-40, 10}})));
    Modelica.Blocks.Interfaces.BooleanOutput y[n] annotation (Placement(transformation(extent = {
        {40, -10}, 
        {60, 10}})));
    parameter Integer n(final min = 1, start = 2) "signal width";
equation
    for i in 1:n loop
        y[i] = x[i] == L.'1' or x[i] == L.'H';
    end for;

    annotation (
        Documentation(
            info = "<html>\n<p>\nConversion of a digital input into a Boolean output without any delay according to:\n</p>\n<pre>\n input                 output\n 'U'  (coded by 1)     false\n 'X'  (coded by 2)     false\n '0'  (coded by 3)     false\n '1'  (coded by 4)     true\n 'Z'  (coded by 5)     false\n 'W'  (coded by 6)     false\n 'L'  (coded by 7)     false\n 'H'  (coded by 8)     true\n '-'  (coded by 9)     false\n</pre>\n<p>\nIf the signal width is greater than 1 this conversion is done for each signal.\n</p>\n</html>",
            revisions = "<html>\n<ul>\n<li><em>September 15, 2004</em>\n       by Christoph Clauss colors changed<br>\n       </li>\n<li><em>November 4, 2003</em>\n       by Christoph Clauss<br>\n       initially modelled.</li>\n</ul>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Polygon(
                    points = {
                        {-40, 40}, 
                        {40, 40}, 
                        {-40, -40}, 
                        {-40, 40}},
                    lineColor = {127, 0, 127},
                    fillColor = {127, 0, 127},
                    fillPattern = FillPattern.Solid), 
                Text(
                    extent = {
                        {152, -100}, 
                        {-148, -40}},
                    lineColor = {0, 0, 255},
                    textString = "%name"), 
                Polygon(
                    points = {
                        {-40, -40}, 
                        {40, -40}, 
                        {40, 40}, 
                        {-40, -40}},
                    lineColor = {255, 0, 255},
                    fillColor = {255, 0, 255},
                    fillPattern = FillPattern.Solid), 
                Rectangle(
                    extent = {
                        {-40, 40}, 
                        {40, -40}},
                    lineThickness = 0.5)}));
end LogicToBoolean;