<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abdullah KARATEKIN on Medium]]></title>
        <description><![CDATA[Stories by Abdullah KARATEKIN on Medium]]></description>
        <link>https://medium.com/@abdullahkaratekin?source=rss-5bfad1d28ed0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*B-y326zI4kvEpBtwmfqhAg.jpeg</url>
            <title>Stories by Abdullah KARATEKIN on Medium</title>
            <link>https://medium.com/@abdullahkaratekin?source=rss-5bfad1d28ed0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:12:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdullahkaratekin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[OPC-UA Sampling, PLC Scan Cycles, and the Math in Between]]></title>
            <link>https://abdullahkaratekin.medium.com/opc-ua-sampling-plc-scan-cycles-and-the-math-in-between-befd2fe8318b?source=rss-5bfad1d28ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/befd2fe8318b</guid>
            <category><![CDATA[plc]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Abdullah KARATEKIN]]></dc:creator>
            <pubDate>Sat, 06 Jun 2026 22:47:29 GMT</pubDate>
            <atom:updated>2026-06-06T23:13:21.403Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been working with OPC-UA and industrial IoT systems for a while. At some point I wanted to sit down and properly connect the dots between the physical signal, the PLC internals, and the subscription configuration not because any of it was unfamiliar, but because I had never written it all down in one place as a coherent chain. I started taking notes.</p><p>Then my son was born in April, and free time became a negotiable concept. Most of this got written in fragments between feeds, during naps, at 2am when he had opinions about sleeping and I had a laptop nearby. Anyway, here it is.</p><h3><strong>Where the Data Comes From</strong></h3><p>It is easy to think of OPC-UA as just a protocol. Connect, subscribe, receive values. But there is a physical chain behind every tag you subscribe to, and each step in that chain has its own constraints:</p><pre>Physical signal     (motor vibrating at N Hz)<br>      ↓<br>ADC + PLC scan      (converts analog to digital at scan rate)<br>      ↓<br>OPC-UA node         (value updated each scan cycle)<br>      ↓<br>SamplingInterval    (how often you read that node)<br>      ↓<br>C# handler          (what you do with the data)<br></pre><p>As a software developer, you control the bottom two layers. The rest is already decided by physics, by the machine, by whoever configured the PLC.</p><h3>The Physical Signal</h3><p>A motor vibration sensor is not generating abstract floats. It is measuring a mechanical phenomenon that has real frequency content. Different conditions and fault types show up at different frequencies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFld8n3fC75627eqx1mtbQ.png" /></figure><p>Knowing which of these you care about is the first question, not what value to put in SamplingInterval. Everything else follows from this.</p><h3>The PLC Scan Cycle and Nyquist</h3><p>The PLC is the OPC-UA server. There is no separate middleware. The firmware exposes its internal memory directly over OPC-UA, and that memory updates on every scan cycle.</p><p>Inside the PLC, an ADC (Analog-to-Digital Converter) reads the physical sensor voltage and converts it to a number. It does this once per scan cycle. This is where the first hard mathematical constraint appears.</p><h4>The Nyquist-Shannon Sampling Theorem</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/104/1*21YASCe8zgVSEXgBm6a_Tg.png" /></figure><p>To correctly reconstruct a signal, the sampling frequency must be <strong>at least twice</strong> the highest frequency of interest.</p><p>This is not a guideline. It is a theorem with a proof. Below this threshold, high-frequency components do not just degrade they fold back into your data as false lower-frequency signals. This phenomenon is called <strong>aliasing</strong>, and it is silent. No errors, no warnings. Just measurements that look plausible and are wrong.</p><p>The scan cycle determines the sampling frequency:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/84/1*E2cF3wx5b1YUZGE9XEtPeA.png" /></figure><p>And from Nyquist, the maximum frequency you can correctly capture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*kGECGfldhTVPxkkOeXPwPg.png" /></figure><p>For a PLC with a 10ms scan cycle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*n142vNO3fUL-4ZogE0jXlA.png" /></figure><p>Everything above 50Hz is invisible. Not noisy invisible. The ADC never sampled it.</p><h4>What Aliasing Actually Looks Like</h4><p>This is where it gets interesting. When a signal exceeds the Nyquist limit, it does not disappear it folds back and masquerades as a lower frequency. Consider a 80Hz bearing fault signal being sampled at 100Hz (10ms scan cycle):</p><pre><br>True signal: 80Hz<br>fs:          100Hz<br>Alias frequency = fs - f_true = 100 - 80 = 20Hz</pre><p>So your monitoring system does not show nothing. It shows a 20Hz signal which looks like normal operating vibration. The bearing is failing and the data says everything is fine.</p><p>Visually, this is what happens at the sample points:</p><pre>True signal (80Hz):<br>  |    .   .        .   .        .   .<br>  |  .       .    .       .    .       .<br>  |.           ..           ..           ..<br>  +--+--+--+--+--+--+--+--+--+--+--+--+--&gt;<br>  0  1  2  3  4  5  6  7  8  9  10  (ms)<br>  ^     ^     ^     ^     ^     ^<br>  |     |     |     |     |     |<br>  samples at 100Hz (every 10ms)<br><br>What those samples reconstruct:<br>  |         .               .<br>  |      .     .         .     .<br>  |   .           .   .           .<br>  +--+--+--+--+--+--+--+--+--+--+--+--&gt;<br><br>  Looks like 20Hz. Normal vibration range. No alarm triggered.</pre><p>The alias frequency formula in general:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*NRCB9bwp2-eWcudfH6vTVA.png" /></figure><p>where n is chosen to bring the result into the range [0, fs/2]. For our case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*5KYYLLf-gv0GO1xDNnaCcA.png" /></figure><p>This is why aliasing is dangerous in industrial monitoring specifically. It does not produce garbage data. It produces plausible data that maps to a different physical condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dp0ocLXVuT-ffTGkWTqObA.png" /></figure><p>Working backwards from a target frequency is where this becomes useful. If you need to detect bearing faults at 150Hz, the required scan cycle is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*ukAD3dcYcAgEh-IGIgGzXw.png" /></figure><p>If the PLC runs at 10ms, bearing fault detection at 150Hz is not a software problem. The data was never captured. That conversation belongs with the automation team, not in your SamplingInterval configuration.</p><p>Siemens S7–1500 defaults to around 10ms. Configurable, but rarely changed in practice.</p><h3>SamplingInterval</h3><p>With that context, SamplingInterval becomes more concrete. It tells the OPC-UA server how often to check a node&#39;s value and queue changes for delivery. It does not affect the PLC scan rate. It only determines how often you observe the values the PLC has already written.</p><p>Two ways this goes wrong:</p><h4>Too slow — missed updates</h4><pre>PLC scan cycle: 10ms<br>SamplingInterval: 100ms<br><br>  0ms   node = 1.23<br> 10ms   node = 1.31  (not observed)<br> 20ms   node = 1.28  (not observed)<br> 30ms   node = 1.35  (not observed)<br>...<br>100ms   you read: 1.19</pre><p>Nine out of ten updates are discarded before you ever see them. No error is raised.</p><h4>Too fast — redundant reads</h4><pre>PLC scan cycle: 10ms<br>SamplingInterval: 3ms<br><br>  0ms   read: 1.23<br>  3ms   read: 1.23  (PLC has not updated yet)<br>  6ms   read: 1.23<br>  9ms   read: 1.23<br> 10ms   PLC updates: 1.31<br> 12ms   read: 1.31</pre><p>Additional load with no additional information.</p><p>The right value is simply:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*m6fteTXYKYMuYU8_38kCwQ.png" /></figure><p>You can query the server’s minimum supported interval directly rather than guessing:</p><pre>var attributes = session.Read(new ReadValueIdCollection {<br>    new ReadValueId {<br>        NodeId      = monitoredItemNodeId,<br>        AttributeId = Attributes.MinimumSamplingInterval<br>    }<br>});<br><br>var minimumInterval = (double)attributes[0].Value;</pre><h4>The C# Handler and Little’s Law</h4><p>Once SamplingInterval is set correctly, the message rate may be higher than expected. 200 tags at a 10ms scan cycle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*su70HwU1OmLsU-5O8nvNwQ.png" /></figure><p>Processing each one synchronously in the notification handler is a common pattern:</p><pre>private void MonitoredItem_Notification(MonitoredItem item,<br>                                         MonitoredItemNotificationEventArgs e)<br>{<br>    var value = (e.NotificationValue as MonitoredItemNotification)?.Value;<br>    _repository.Save(item.DisplayName, value.Value, value.SourceTimestamp);<br>}</pre><p>This works fine at low rates. At 20,000 messages per second it quietly falls apart.</p><h4>Little’s Law</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/86/1*Oyxma6T9Ax-1yyzBTzl6AQ.png" /></figure><ul><li><strong>L</strong> — average number of items queued in the system</li><li><strong>λ</strong> — arrival rate (messages per second)</li><li><strong>W</strong> — average processing time per item (seconds)</li></ul><p>With a 5ms synchronous DB write:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*bQk6u-WNS174kvUNPpYG1w.png" /></figure><p>That number looks manageable. The problem is that it assumes you can actually sustain 20,000 writes per second. Your real throughput with a 5ms write is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*hrTNPYq5M4iCt3TeVrs7qA.png" /></figure><p>You are receiving 20,000 and processing 200. Little’s Law only holds for <strong>stable</strong> systems. This one is not stable the queue grows without bound. Thread pool backs up. Eventually the OPC-UA client begins dropping notifications silently to keep up.</p><p>The fix is to stop treating the notification handler as a processing unit. It should only receive:</p><pre>private readonly Channel&lt;DataPoint&gt; _channel =<br>    Channel.CreateBounded&lt;DataPoint&gt;(capacity: 100_000);<br><br>private void MonitoredItem_Notification(MonitoredItem item,<br>                                         MonitoredItemNotificationEventArgs e)<br>{<br>    var value = (e.NotificationValue as MonitoredItemNotification)?.Value;<br><br>    _channel.Writer.TryWrite(new DataPoint(<br>        Tag:       item.DisplayName,<br>        Value:     Convert.ToDouble(value.Value),<br>        Timestamp: value.SourceTimestamp<br>    ));<br>}<br><br>private async Task ConsumeAsync(CancellationToken ct)<br>{<br>    await foreach (var point in _channel.Reader.ReadAllAsync(ct))<br>        await _repository.SaveAsync(point);<br>}</pre><p>The handler returns immediately. The consumer runs at whatever pace the downstream system can sustain. With a bounded channel you can reason about queue depth and backpressure using Little’s Law explicitly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*Yj1tHTSfm8TPL97e0gmGHA.png" /></figure><p>If that exceeds your channel capacity, you have a sizing problem you can measure and address rather than a silent failure you discover in production.</p><h3>That&#39;s It</h3><p>The numbers you type into an OPC-UA subscription reflect assumptions about the physical process being monitored. Two formulas Nyquist and Little’s Law turn those assumptions into something you can verify before the code ships.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=befd2fe8318b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reading PLC Data Over OPC-UA: Why Your Bytes Are Lying to You]]></title>
            <link>https://abdullahkaratekin.medium.com/reading-plc-data-over-opc-ua-why-your-bytes-are-lying-to-you-5c108f97506c?source=rss-5bfad1d28ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c108f97506c</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[opc-ua]]></category>
            <category><![CDATA[industrial-iot]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Abdullah KARATEKIN]]></dc:creator>
            <pubDate>Fri, 17 Apr 2026 13:28:59 GMT</pubDate>
            <atom:updated>2026-04-17T13:28:59.874Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This past weekend, I ran into this problem again while working on a side project connecting to a Siemens S7 PLC over OPC-UA. Wrong values, no exceptions, no bad status codes just silent garbage. I recognized it immediately. I’d seen the same thing before, in different systems, different contexts. It’s one of those bugs that looks different every time but always comes from the same place. That’s why I decided to write it down properly, once and for all.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xunx3mrSfR8fyP7f" /><figcaption>Photo by <a href="https://unsplash.com/@simonkadula?utm_source=medium&amp;utm_medium=referral">Simon Kadula</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The Symptom</h3><p>You’re reading a pressure value from a Siemens S7 PLC over OPC-UA. The physical sensor reads 325.5 bar. Your C# client receives 1208025088. No exception. No Bad StatusCode. Just a completely wrong number delivered with full confidence.</p><p>This is not an OPC-UA bug. It is not a PLC bug. It is a bytes problem specifically, a problem of interpreting the same bytes in the wrong order, with the wrong type assumption.</p><h3>The Foundation: How Numbers Live in Memory</h3><p>Before touching OPC-UA, we need to understand how a PLC stores numbers because OPC-UA is often just a transparent window into that raw memory.</p><p>A 16-bit integer 0x1234 (decimal: 4660) occupies 2 bytes. But which byte comes first in memory?</p><pre>Big-Endian (Motorola, most PLCs):<br>Address:  0x00  0x01<br>Value:    0x12  0x34<br>          ↑ MSB first<br><br>Little-Endian (Intel, x86, .NET):<br>Address:  0x00  0x01<br>Value:    0x34  0x12<br>          ↑ LSB first</pre><p><strong>MSB</strong> = Most Significant Byte. <strong>LSB</strong> = Least Significant Byte.</p><p>Siemens S7 PLCs use <strong>big-endian</strong> byte order the most significant byte comes first. Your .NET runtime on x86/x64 is <strong>little-endian</strong> the least significant byte comes first.</p><p>When you read raw bytes from an S7 PLC over OPC-UA and hand them to BitConverter without swapping, you are reading the bytes backwards.</p><pre>byte[] plcBytes = { 0x12, 0x34 }; // PLC sent this (big-endian)<br><br>// WRONG — BitConverter assumes little-endian on x86<br>short wrong = BitConverter.ToInt16(plcBytes, 0);<br>// Result: 0x3412 = 13330 ← not what the PLC meant<br><br>// CORRECT — reverse before converting<br>Array.Reverse(plcBytes);<br>short correct = BitConverter.ToInt16(plcBytes, 0);<br>// Result: 0x1234 = 4660 ✓</pre><p>This is the root of most “my OPC-UA values are garbage” complaints.</p><h3>Word, DWord, Real: PLC Type Vocabulary</h3><p>PLCs don’t speak Int32 or Float. They speak their own type vocabulary and when OPC-UA exposes these values, you need to know the mapping:</p><pre>PLC Type   Size      Meaning           .NET Equivalent<br>--------   -------   ---------------   ---------------<br>BOOL       1 bit     Single bit flag   bool<br>BYTE       8 bits    Unsigned byte     byte<br>WORD       16 bits   Unsigned 16-bit   ushort<br>DWORD      32 bits   Unsigned 32-bit   uint<br>INT        16 bits   Signed 16-bit     short<br>DINT       32 bits   Signed 32-bit     int<br>REAL       32 bits   IEEE 754 float    float<br>LREAL      64 bits   IEEE 754 double   double</pre><p>The critical insight: a DWORD and a REAL are both 32 bits. The bytes are identical in memory. The only difference is <em>how you interpret them</em>.</p><pre>PLC Memory (4 bytes): 0x43A31800<br><br>As DWORD (uint):   1,135,009,792<br>As REAL (float):   326.1875</pre><p>Same bytes. Completely different numbers. If OPC-UA exposes this node as UInt32 but the PLC engineer intended it as REAL, your pipeline stores 1,135,009,792 instead of 326.1875and both are valid numbers, so nothing complains.</p><h3>Where OPC-UA Hides This Complexity</h3><p>A well-configured OPC-UA server (like Siemens’ own S7 OPC-UA interface) maps PLC types to OPC-UA types automatically. A REAL becomes a Float node. A DINT becomes an Int32 node. In this ideal world, you read the node and get the correct typed value.</p><p>But the real world is messier. You will encounter:</p><p><strong>Scenario 1: Node exposed as </strong><strong>ByteString</strong></p><p>Some OPC-UA servers (especially third-party gateways bridging legacy PLCs) expose raw memory regions as ByteString nodes. You get a byte[] and you&#39;re on your own:</p><pre>var dataValue = await session.ReadValueAsync(nodeId);<br>byte[] raw = (byte[])dataValue.Value;<br><br>// You must know the PLC type from documentation<br>// Assume it&#39;s a REAL (float), big-endian from S7<br>float value = ReadBigEndianFloat(raw, offset: 0);</pre><p><strong>Scenario 2: Node type mismatch</strong></p><p>The OPC-UA server maps a REAL as UInt32 due to misconfiguration. You read 1,135,009,792 when you should read 326.1875. No error. Just a wrong number.</p><p><strong>Scenario 3: </strong><strong>Variant with ambiguous type</strong></p><p>The node is exposed as Variant. At runtime, the actual type depends on server configuration. Your client code must handle both cases defensively.</p><h3>Correct Byte Manipulation in C#</h3><p>Modern C# gives you several tools. Here is when to use each:</p><blockquote>BitConverter — Simple but dangerous on its own</blockquote><pre>byte[] bytes = { 0x43, 0xA3, 0x18, 0x00 }; // big-endian from PLC<br><br>// BitConverter assumes host endianness (little-endian on x86)<br>// Must check and reverse if needed<br>if (!BitConverter.IsLittleEndian)<br>{<br>    // We&#39;re on a big-endian host — no swap needed<br>    float value = BitConverter.ToSingle(bytes, 0);<br>}<br>else<br>{<br>    // Little-endian host — must reverse for big-endian PLC data<br>    byte[] reversed = new byte[4];<br>    bytes.CopyTo(reversed, 0);<br>    Array.Reverse(reversed);<br>    float value = BitConverter.ToSingle(reversed, 0);<br>}</pre><p>The problem: Array.Reverse allocates. In a high-frequency IoT pipeline reading thousands of values per second, this matters.</p><blockquote>BinaryPrimitives — The modern, allocation-free approach</blockquote><pre>using System.Buffers.Binary;<br><br>ReadOnlySpan&lt;byte&gt; span = stackalloc byte[] { 0x43, 0xA3, 0x18, 0x00 };<br><br>// Explicit endianness — no ambiguity<br>uint rawBits = BinaryPrimitives.ReadUInt32BigEndian(span);<br><br>// Reinterpret bits as float (IEEE 754)<br>float value = BitConverter.Int32BitsToSingle((int)rawBits);<br>// Result: 326.1875 ✓</pre><p>BinaryPrimitives is the right tool for production IoT code. It is:</p><ul><li>Explicit about endianness no host endianness surprises</li><li>Allocation-free works with Span&lt;byte&gt; and ReadOnlySpan&lt;byte&gt;</li><li>Available from .NET Standard 2.1 / .NET Core 2.1</li></ul><blockquote>MemoryMarshal — Zero-copy reinterpretation</blockquote><p>When you need to reinterpret a block of bytes as a struct without copying:</p><pre>using System.Runtime.InteropServices;<br><br>[StructLayout(LayoutKind.Sequential, Pack = 1)]<br>struct PlcDataBlock<br>{<br>    public short Temperature;  // INT — 2 bytes<br>    public short Pressure;     // INT — 2 bytes<br>    public float FlowRate;     // REAL — 4 bytes<br>}<br><br>byte[] raw = GetRawBytesFromOpcUa(); // 8 bytes from PLC DB<br><br>// Zero-copy cast — no allocation<br>ref PlcDataBlock db = ref MemoryMarshal.AsRef&lt;PlcDataBlock&gt;(raw);<br><br>// Still need to handle endianness for each field<br>short temp = BinaryPrimitives.ReverseEndianness(db.Temperature);</pre><p>MemoryMarshal is powerful but dangerous it bypasses the type system. Use it only when you have a well-defined, stable PLC data block structure and you need maximum performance.</p><h3>Floating Point Special Case: IEEE 754 in 4 Bytes</h3><p>The REAL type in PLCs is IEEE 754 single-precision float the same as C#&#39;s float. But the bit layout is worth understanding, because it explains why a misinterpreted REAL produces such wildly wrong integers.</p><p>A 32-bit IEEE 754 float breaks down as:</p><pre>Bit 31   Bits 30-23    Bits 22-0<br>  │          │              │<br>Sign     Exponent (8)   Mantissa (23)<br><br>Example: 326.1875<br><br>Binary: 0 10000111 01000110001100000000000<br>        │ └───────┘ └─────────────────────┘<br>        │    135        mantissa bits<br>        │<br>        └─ positive<br><br>Value = (-1)^0 × 2^(135-127) × 1.01000110001100000000000<br>      = 1 × 2^8 × 1.26640625<br>      = 256 × 1.26640625<br>      = 326.1875 ✓<br><br>Raw hex: 0x43A31800<br>As uint: 1,135,009,792</pre><p>When you read 1,135,009,792 from a REAL node mistyped as UInt32, that&#39;s not random garbage it&#39;s the IEEE 754 bit pattern of 326.1875 interpreted as an unsigned integer. Understanding this helps you diagnose type mismatches: if you see suspiciously large integers from a sensor that should report small physical values, suspect a REALas integer mismatch.</p><p>The correct decode in C#:</p><pre>uint rawBits = BinaryPrimitives.ReadUInt32BigEndian(span);<br>float value = BitConverter.Int32BitsToSingle((int)rawBits);</pre><p>BitConverter.Int32BitsToSingle does a bitwise reinterpret it does not convert the integer value 1,135,009,792 to a float. It reinterprets the same 32 bits as a float. This is the correct operation.</p><h3>A Practical Checklist</h3><p>Before writing a single line of OPC-UA client code against a new PLC data source, answer these five questions:</p><p><strong>1. What is the PLC manufacturer and model?</strong> Siemens S7 → big-endian. Allen-Bradley ControlLogix → little-endian. Mitsubishi MELSEC → big-endian. Endianness is hardware-specific, not OPC-UA-specific.</p><p><strong>2. What is the native PLC type for each node?</strong> Get the PLC engineer’s data block documentation. Do not trust the OPC-UA type alone verify it matches the PLC side type declaration.</p><p><strong>3. Is the OPC-UA server doing type mapping, or exposing raw memory?</strong> A well-configured server maps REAL → Float. A raw gateway might expose ByteString. Know which you&#39;re dealing with before writing decode logic.</p><p><strong>4. Are there multi-register values?</strong> Some PLCs split a 32-bit value across two 16-bit registers. The OPC-UA server might expose them as two separate UInt16 nodes. You must combine them with correct byte order to get the actual value.</p><p><strong>5. What is the StatusCode strategy?</strong> A Good StatusCode on a byte-level misinterpretation means nothing. Data quality validation must happen at the semantic level does this value fall within physically plausible bounds for this sensor?</p><p>When I ran into this again last weekend, I knew I had to write it down. Not because it’s a new problem it isn’t. But because it’s the kind of thing that costs hours the first time you see it, and five seconds the second time. If this saves someone that first painful encounter, it was worth writing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c108f97506c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Abstract Syntax Tree (AST)]]></title>
            <link>https://abdullahkaratekin.medium.com/abstract-syntax-tree-ast-d38508684e38?source=rss-5bfad1d28ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d38508684e38</guid>
            <dc:creator><![CDATA[Abdullah KARATEKIN]]></dc:creator>
            <pubDate>Mon, 22 Nov 2021 21:10:03 GMT</pubDate>
            <atom:updated>2021-11-22T21:10:03.275Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most important steps when designing a compiler is generating abstract syntax code. The AST is tree-like representation. It is one of the most important steps of a compiler and each branch of this tree contains information about the program, we can say the data structure in which these tokens are placed after parsing and symbolizing lines of code.</p><p>The code must pass the Lexer Analysis and Syntax Analysis steps.</p><p><strong>Lexer Analysis</strong><br>The process of converting a character string to a token string is called. <br>What we call a token is a string of characters consisting of and carrying one or more characters. <br>The codes that perform this analysis are called lexers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*MMrZBqk3HSaa4SL7nTEV_g.png" /><figcaption>Example of lexers code.</figcaption></figure><p><strong>Syntax Analysis<br></strong>The process of controlling the output of lexical analysis according to the rules of the language, determining the priority of the parentheses, detecting and parsing the errors that may occur on the code is called syntax analysis.</p><p><strong>AST Generate</strong></p><p>If it passes both phases and after its accuracy is confirmed, the AST will have done its job, sometimes AST can be used to create an intermediate language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KOUC1XOk_Rcw5Q2liTTyw.png" /><figcaption><a href="https://astexplorer.net/">AST Explorer</a></figcaption></figure><p>The ast is using for application analysis or application transformation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d38508684e38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is The Consistency Hashing?]]></title>
            <link>https://abdullahkaratekin.medium.com/what-is-the-consistency-hashing-dc4a3d576cc1?source=rss-5bfad1d28ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc4a3d576cc1</guid>
            <dc:creator><![CDATA[Abdullah KARATEKIN]]></dc:creator>
            <pubDate>Thu, 26 Aug 2021 11:00:57 GMT</pubDate>
            <atom:updated>2021-08-26T11:00:57.579Z</atom:updated>
            <content:encoded><![CDATA[<p>While talking to my teammates, the topic suddenly came to hashing and distributed systems, talking about my experience in distributed systems, I said why am I not writing about this topic and start to work. I will talk about hashing a bit rather than going directly to the subject.</p><h4><strong>Hash</strong></h4><p>When we started to write code, we often say to each other, please hashing important fields, but then I realized that most of the time we miss the math behind it, yes we do, but we don’t know exactly how?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*SLnweHAl9MvLbHuC" /><figcaption>Not Hash-Tag</figcaption></figure><blockquote>A hash function takes an input as a key, which is associated with a datum or record and used to identify it to the data storage and retrieval application. The keys may be fixed length, like an integer, or variable length, like a name. In some cases, the key is the datum itself. The output is a hash code used to index a hash table holding the data or records, or pointers to them. (<a href="https://en.wikipedia.org/wiki/Hash_function">https://en.wikipedia.org/wiki/Hash_function</a>)</blockquote><p>If I wanted to explain it with a book sentence, I would look at the Wikipedia above. But I will explain with details and example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7o-kS_rqJQqtPOok.png" /></figure><p>Let’s consider the MD5 algorithm: This algorithm working one-way which mean you cannot reverse. Algorithm reduces the original data to 128 bits, no matter how long. We calling “summary” from this algorithm output generating a 32 char via hexadecimal number system.</p><p>The data is divided into blocks of 512 bits and the same operation is applied to each block. A 1 is added to the end of the binary value of the data, with 64 less than the nearest multiple of 512 bits, and a 0 is added to the remainder. This 64-bit difference is used to specify the length of the data. The length of the original message is written in mod 2⁶⁴ to the remaining 64 bits.</p><p>It works on 128-bit chunks separated by 4 32-bit words called A, B, C, and D, initialized with certain constant values, and then the algorithm uses each 512-bit message block to change its state. The processing of a message block consists of four similar stages, called rounds; Each round consists of a nonlinear function, modular addition, and bitwise left shift. There are 16 rounds in total.</p><p>I think enough for hashing don’t want bother you we can continue main topic.</p><h4><strong>Consistency Hashing</strong></h4><p>It’s purpose helping for load balancing and scaling on distributed systems. It is a method that tries to reduce the effect of newly added or removed nodes on the system by feeding the hash function according to the range of value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*fA8njCbrMq2cT5TGXtzTJg.png" /></figure><p>Let’s say we have city list, we want keep on our 3 cache server then create a model like above figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*yCG8k6dcB0DnUK_HKSTDaw.png" /></figure><h4>“hash(k)mod(n)”</h4><p>Using this formula, we will find which server will hold which data. I assume we already hashing field of keys for our example.</p><p>Everything good to here. Let’s assume one of servers is down and that server number 2. We still using “hash(k) mod (n)” formula. That will occurrence a problem when it give number 2 because of no server number 2. So solve that problem we will using range key approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*fgJp3TKQZ2z_VzQABxcDOA.png" /><figcaption>Assume limit 3000</figcaption></figure><p>All keys are assigned to the next server in a clockwise order, potentially doubling that server’s load. This is definitely undesirable from a performance standpoint, each server can be hashed to multiple locations on the unit flat to ensure a more even redistribution of keys in case of server failure or scaling. When a server fails, the keys assigned to each of its replicas in the unit ring are reassigned clockwise to a different server, so the keys are redistributed more evenly. When a single key is used frequently in different situations and needs to be hosted on multiple servers, the object can be assigned to multiple servers by moving the keys clockwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*RFQZdNU1qy-PbdPT.jpg" /><figcaption>Source: <a href="https://en.wikipedia.org/wiki/Consistent_hashing">https://en.wikipedia.org/wiki/Consistent_hashing</a></figcaption></figure><p>This approach remapping instead of whole server reload data it will save us and it will better performance.</p><h3>References</h3><p><a href="https://www.acodersjourney.com/system-design-interview-consistent-hashing/">https://www.acodersjourney.com/system-design-interview-consistent-hashing/</a></p><p><a href="https://en.wikipedia.org/wiki/Consistent_hashing">https://en.wikipedia.org/wiki/Consistent_hashing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc4a3d576cc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind of Garbage Collection — Mark and Sweep Algorithm]]></title>
            <link>https://abdullahkaratekin.medium.com/behind-of-garbage-collection-mark-and-sweep-algorithm-35b2c2259308?source=rss-5bfad1d28ed0------2</link>
            <guid isPermaLink="false">https://medium.com/p/35b2c2259308</guid>
            <dc:creator><![CDATA[Abdullah KARATEKIN]]></dc:creator>
            <pubDate>Mon, 17 May 2021 11:45:51 GMT</pubDate>
            <atom:updated>2021-05-17T11:45:51.327Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Behind of Garbage Collection — Mark and Sweep Algorithm</strong></h3><p>First of all, we should remember what we were doing before GC especially who wrote C and C++ languages.</p><p>When we created any object we were supposed to destructure for memory management so this situation was causing repeat code and time for developers therefore GC was invented by John McCarthy in 1959 (see wikipedia). GC is an automatic memory management it’s based on deallocating and returning to memory for unused objects but that’s not all.</p><p>Today many programming language such as Java, C#, GO, Python, PHP has a garbage collection whatever after all this brief we can proceed to algorithms.</p><ul><li><strong>Reference Counting</strong></li><li><strong>Mark and Sweep</strong></li><li><strong>Mark and Sweep Compact</strong></li><li><strong>Mark Copy</strong></li></ul><p>Mark and Sweep algorithm is generally the most used algorithm for GC. That is the reason I will only tell about “Mark and Sweep” in this article. Mark and Sweep algorithms consist of two processes “Mark” and “Sweep”. As you can understand, the name of the algorithm comes from these two processes.</p><p>However I should mention the “stop-the-world” mechanism before the processes. Stop the world mechanism is when GC is fired it pauses the program for a while. The reason for this is to make sure GC runs properly otherwise it will be difficult to distinguish whether objects have been moved or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/0*9G_WiLCh6ypMxGDj" /><figcaption>Green nodes is reachable, white nodes not unreachable</figcaption></figure><h3><strong>Mark</strong></h3><p>This is based on marking reachable or unreachable objects on memory, reachable objects are marked as true.</p><pre>function Mark(root){<br>    if root.marked == false {<br>        root.marked = true;<br>        foreach (var reference in root) {<br>            Mark(reference)<br>        }<br>    }<br>}<br>//example code</pre><h3><strong>Sweep</strong></h3><p>This is based on removing unreachable objects, which means those objects marked as false.</p><pre>function Sweep() {<br>    foreach (reference in heap){<br>        if reference.marked = true {<br>            reference.marked = false;<br>        } else {<br>            Remove(reference);<br>        }<br>    }<br>}<br>//example code</pre><p>After all these examples we need discussion about Mark and Sweep algorithm advantages and disadvantages. Advantages it does not loop endlessly and also releases all unused memory but as for the disadvantages stops the running program when GC runs and causes many free spaces on memory.</p><p><strong>References:</strong></p><ul><li><a href="https://docs.microsoft.com/en-us/archive/blogs/abhinaba/back-to-basics-mark-and-sweep-garbage-collection">Back To Basics: Mark and Sweep Garbage Collection</a></li><li><a href="https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)">Garbage collection (computer science) - Wikipedia</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35b2c2259308" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>