<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">For this particular effort, I am using Beckhoff’s TwinCAT 3 framework for PC-based industrial control.  In addition to the normal industrial programming standards, they provide a C/C++ implementation that provides *<b>hard</b>* real-time
 capability through a modified subset of the standard libraries implemented in the kernel mode of the underlying (Windows 10 in this case) OS.  Within this environment I am constrained by the APIs offered to communicate with the outside world / programs in
 user mode.  I have to use proprietary libraries to get socket functionality etc. and thus I can not use the erl_interface without modification (and the port driver and NIF approaches are not applicable in this scenario).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have been learning about Erlang and am very intrigued by the language.  I would like to try out some ideas implemented in Erlang but some of the code will have hard real-time constraints as well as other industrial communication protocol
 requirements.  Thus, I will have to split the code across the BEAM and the TwinCAT3 environments.  Since I am at the beginning, I have the luxury of defining the architecture/interfaces and I thought passing Erlang (binary) terms between the two environments
 would be a nice approach to allow somewhat native communication between hard real-time C/C++ processes while also avoiding writing an arbitrary serialized protocol from scratch….   Perhaps I am being naïve.  Also, after digging some more, I have discovered
 that a lot of the functions in ei/erl_interface that I was excited about have been deprecated in OTP 22 and are scheduled for (have been already?) removal.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks for your help and patience,<o:p></o:p></p>
<p class="MsoNormal">Brett<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> Albin Stigö <albin.stigo@gmail.com> <br>
<b>Sent:</b> Sunday, September 20, 2020 10:58 AM<br>
<b>To:</b> Brett Hemes <brhemes@mmm.com><br>
<b>Cc:</b> Max Lapshin <max.lapshin@gmail.com>; Erlang Questions <erlang-questions@erlang.org><br>
<b>Subject:</b> [EXTERNAL] Re: Re: Using (stripped down ei.h) with generic TCP instead of ports<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Which kernel are you using?<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">--Albin<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Sat, Sep 19, 2020, 21:29 Brett Hemes <<a href="mailto:brhemes@mmm.com">brhemes@mmm.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Could you perhaps elaborate on your reply a bit?  The RT development environment (running in kernel mode) offers only a memory mapped interface besides the aforementioned UDP/TCP
 option for communication between the RT modules and user mode applications.  I believe “exposing the interface” would require me to both make an interface from scratch and then wrap it as a port driver or NIF to get it into the BEAM.  Aside from some arbitrary
 handshaking interface via registers I could imagine passing strings via fixed length character buffers but I will still need some form of encoding/decoding… which is how I ended up looking at the ei library.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Also, most of what I have read regarding Erlang seems to favor ports over drivers and NIFs as they better align with the Erlang philosophy but I am too new to all this to really
 know when each is preferred.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thanks much,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Brett<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b>From:</b> Albin Stigö <<a href="mailto:albin.stigo@gmail.com" target="_blank">albin.stigo@gmail.com</a>>
<br>
<b>Sent:</b> Thursday, September 17, 2020 9:32 AM<br>
<b>To:</b> Max Lapshin <<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>><br>
<b>Cc:</b> Brett Hemes <<a href="mailto:brhemes@mmm.com" target="_blank">brhemes@mmm.com</a>>; Erlang Questions <<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>><br>
<b>Subject:</b> [EXTERNAL] Re: Using (stripped down ei.h) with generic TCP instead of ports<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I would expose the kernel code through a char or block device driver. There are already many facilities in most kernels for effective communication with userpace. a<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">After all, that's the whole point of a kernel...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">--Albin<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">On Thu, Sep 17, 2020, 16:00 Max Lapshin <<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Your idea is ok.  Just strip everything you don't need from ei and it will work for you.<o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">As for me, I like enif api more, but Sverker has pointed that I'm misuing it inside drivers and it may break once =)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>