Tuesday, January 24, 2023

Remote Procedure Calls (RPC)

Remote Procedure Calls (RPC)

Remote Procedure Calls (RPC) is a protocol that allows a computer program to make a request to a remote server and receive a response, similar to a local function call.

Here are a few examples of how to implement RPC in C++:

  1. gRPC: gRPC is a high-performance, open-source framework for building remote procedure call (RPC) APIs. It is based on the Protocol Buffers data serialization format and supports both C++ and C# languages.

  2. Apache Thrift: Apache Thrift is a software framework for developing RPC services. It is written in C++ and supports multiple languages including C++, C#, Java, Python, and more.

  3. Ice: Ice is a middleware for building distributed systems. It is written in C++ and supports multiple languages including C++, C#, Java, Python, and more.

  4. Boost.ASIO: Boost.ASIO is a C++ library for network and low-level I/O programming that can be used to implement RPC. It is part of the Boost C++ Libraries and provides a platform-independent interface for asynchronous I/O.

  5. XML-RPC: XML-RPC is a lightweight protocol for making remote procedure calls over HTTP. It is an older protocol and uses XML as the message format. It can be implemented in C++ using a library such as Xmlrpc-c

Monday, January 23, 2023

Open-source software options available for creating a factory monitoring / IOT dashboard

Open-source software options are available for creating a factory monitoring dashboard.

  1. Grafana: Grafana is a popular open-source platform for creating monitoring and analytics dashboards. It supports data from various sources, including time-series databases, and allows you to create custom visualizations and alerts

  2. InfluxDB: InfluxDB is an open-source time-series database that is often used in conjunction with Grafana for creating monitoring dashboards. It can be used to store and query large amounts of time-series data, such as sensor data from a factory.

  3. Node-RED: Node-RED is an open-source platform for creating IoT applications. It allows you to create custom workflows by connecting various nodes, such as sensors and data storage, and can be used to create a factory monitoring dashboard.

  4. Freeboard: Freeboard is an open-source dashboard platform that allows you to create custom dashboards with real-time data from various sources, such as sensors. It is easy to use and can be used to create a factory monitoring dashboard.

  5. Kibana: Kibana is an open-source data visualization and exploration platform that is part of the Elastic Stack. It allows you to create interactive dashboards and visualizations with data from various sources, including log data and metrics.

Open Source Hardware Communication C++ APIs for Windows Applications



The following APIs are useful in developing Windows applications factory monitoring systems, SCADA, or any industrial automation monitoring and control applications 

WIFI

  1. Win32 API: The Win32 API is the native Windows API for C++ and provides a set of functions for interacting with the operating system. It includes a set of functions for working with WiFi networks, including functions for scanning for available networks, connecting to networks, and managing network profiles.

  2. Native Wifi API: This is a set of functions for interacting with WiFi networks on Windows, it is built on top of the Win32 API and provides a higher-level, more convenient API for working with WiFi networks.

  3. WinRT API: The WinRT API is the modern Windows API for C++ and it provides a set of functions for interacting with the operating system. It includes a set of functions for working with WiFi networks, including functions for scanning for available networks, connecting to networks, and managing network profiles.

  4. Wireless Toolkit (WiFiAPI.dll): This is a C++ library for working with WiFi networks on Windows. It provides a set of functions for scanning for available networks, connecting to networks, and managing network profiles.

  5. C++ Wi-Fi Manager: This is a C++ library for working with WiFi networks on Windows. It provides a simple and easy-to-use API for interacting with WiFi networks and includes functions for scanning for available networks, connecting to networks, and managing network profiles.

BLUETOOTH

  1. Windows Bluetooth API (WinRT API): The Windows Bluetooth API is a modern Windows API for C++ that provides a set of functions for interacting with Bluetooth devices. It includes functions for scanning for available devices, connecting to devices, and sending and receiving data.

  2. Bluetooth Low Energy (BLE) API: This is a C++ API for working with Bluetooth Low Energy (BLE) devices on Windows. It provides a simple and easy-to-use API for interacting with BLE devices and includes functions for scanning for available devices, connecting to devices, and sending and receiving data.

  3. Windows Bluetooth Classic API (Win32 API): The Windows Bluetooth Classic API is the native Windows API for C++ that provides a set of functions for interacting with Bluetooth devices. It includes functions for scanning for available devices, connecting to devices, and sending and receiving data.

  4. Windows Universal Bluetooth API: This is a C++ API for working with Bluetooth devices on Windows. It provides a simple and easy-to-use API for interacting with Bluetooth devices and includes functions for scanning for available devices, connecting to devices, and sending and receiving data.

  5. C++ Bluetooth Library: This is a C++ library for working with Bluetooth devices on Windows. It provides a set


USB

open-source USB C++ APIs available for use in Windows. Here are a few examples:

  1. Windows USB API (WinRT API): The Windows USB API is a modern Windows API for C++ that provides a set of functions for interacting with USB devices. It includes functions for enumerating and accessing USB devices, sending and receiving data, and controlling device configuration.

  2. LibUsb: This is a cross-platform library that provides a C API for interacting with USB devices. It can be used in Windows by using a C++ wrapper library such as libusbpp or libusbwin.

  3. libusbK: This is an open-source library that provides a C API for interacting with USB devices on Windows. It includes functions for enumerating and accessing USB devices, sending and receiving data, and controlling device configuration.

  4. Windows Driver Frameworks (WDF): This is a set of libraries and tools for creating USB device drivers for Windows. It provides a C++ API for working with USB devices and can be used to create both user-mode and kernel-mode drivers.

  5. libusb: This is an open-source library that provides a C API for interacting with USB devices. It can be used in Windows by using a C++ wrapper library such as libusbpp or libusbwin.

ETHERNET

open-source Ethernet C++ APIs are available for use in Windows. Here are a few examples:

  1. Windows Sockets (WinSock): This is the native Windows API for network programming and it provides a C API for working with Ethernet and other network protocols. It includes functions for creating sockets, connecting to remote hosts, and sending and receiving data.

  2. Boost.Asio: Boost. Asio is a C++ library for network programming, it provides an abstraction of the operating system's I/O services and supports Ethernet communication. It is a cross-platform library, which supports Windows, macOS, and Linux.

  3. PcapPlusPlus: This is an open-source, cross-platform C++ library for capturing, parsing, and crafting network packets. It supports both Windows and Linux and it can be used for Ethernet packets.

  4. libtins: This is a C++ network packet crafting and sniffing library. It provides a simple and easy-to-use API for working with Ethernet packets and supports Windows, Linux, and MacOS.

  5. WinPcap: This is a powerful, open-source library for capturing and transmitting Ethernet packets on Windows. It provides a C API for working with Ethernet packets and includes functions for capturing, filtering, and sending packets.

Modbus

open-source Modbus C++ APIs available for use in Windows. Here are a few examples:

  1. libmodbus: This is a C library for Modbus communication, it can be used on Windows by using a C++ wrapper library such as libmodbuspp.

  2. FreeModbus: This is an open-source, cross-platform Modbus library that provides a C API for working with Modbus communication. It supports Windows and Linux.

  3. ModbusMaster: This is a C++ library for Modbus communication that provides a simple and easy-to-use API for working with Modbus devices. It supports Windows, Linux, and MacOS.

  4. C++ Modbus Library: This is a C++ library for Modbus communication that provides a simple and easy-to-use API for working with Modbus devices. It supports Windows and Linux.

  5. QModBus: This is a C++ library for Modbus communication that is part of the Qt framework. It provides a high-level, cross-platform API for interacting with Modbus devices and is supported on Windows, MacOS, and Linux.

USART

USRT (USB Serial Real-Time Transfer) is a protocol that allows the real-time transfer of data over USB. It is commonly used in industrial automation and control systems. Here are a few open-source USRT USB C++ APIs available for use in Windows:

  1. libserial: This is a cross-platform C++ library for working with serial ports, including USB-to-serial devices. It provides a simple and easy-to-use API for working with USRT devices on Windows.

  2. Boost.Asio: Boost. Asio is a C++ library for network programming, it provides an abstraction of the operating system's I/O services and supports USB serial communication. It is a cross-platform library, which supports Windows, MacOS, and Linux.

  3. CSerial: This is a C++ class library for working with serial ports, including USB-to-serial devices. It provides a simple and easy-to-use API for working with USRT devices on Windows.

  4. SerialPort: This is a C++ library for working with serial ports, including USB-to-serial devices. It provides a simple and easy-to-use API for working with USRT devices on Windows.

  5. QSerialPort: This is a C++ library for working with serial ports, including USB-to-serial devices. It is part of the Qt framework and provides a high-level, cross-platform API for interacting with USRT devices and is supported on Windows, MacOS, and Linux.


Arduino vs STM32

Arduino vs STM32



Arduino and STM32 are both popular microcontroller platforms, but they have some key differences.

Arduino is an open-source electronics platform based on simple microcontroller boards. It is designed for hobbyists and beginners, it is easy to use, and has a large community of users and developers. Arduino boards have a wide range of compatible shields, which are add-on boards that can be used to add functionality to the microcontroller. The Arduino boards are usually based on AVR or SAM microcontrollers, and they have a simple and easy-to-use IDE (Integrated Development Environment) and a large library of pre-written code.

STM32 is a family of 32-bit microcontroller integrated circuits by STMicroelectronics. It is designed for professional use in a wide range of applications, including industrial, medical, and automotive. STM32 boards are based on ARM Cortex-M microcontrollers, which are more powerful and complex than the microcontrollers used in Arduino boards. The STM32 boards have a more advanced development environment and toolchain, which is geared toward professional use. They also have a large number of peripherals and interfaces that are not available on Arduino boards, such as USB, Ethernet, and CAN bus.

In summary, Arduino is more suited for hobbyists and beginners while STM32 is more geared towards professionals and advanced users that require more powerful and complex solutions.

High speed PCB trace routing best practices

 High speed PCB trace routing best practices

High-speed PCB trace routing is an important aspect of designing and building electronic devices that operate at high speeds. Proper routing can help to reduce electromagnetic interference (EMI) and improve signal integrity. Here are a few best practices for high-speed PCB trace routing:

  1. Use controlled impedance: Controlled impedance is the characteristic impedance of a trace, which should match with the transmission line to prevent signal reflections and improve signal integrity.

  2. Minimize the trace length: Minimizing the trace length will help to reduce the parasitic capacitance and inductance, which can cause signal integrity issues.

  3. Minimize the via count and use via stitching: Vias can introduce unwanted inductance and capacitance to the signal path, minimizing the number of vias, and using the via stitching technique can help to mitigate this issue.

  4. Use differential signaling: Differential signaling can help to reduce the susceptibility to noise and improve signal integrity.

  5. Use a ground plane: A continuous, unbroken ground plane provides a low-impedance return path for high-frequency signals, reducing EMI and improving signal integrity.

  6. Use shielding: Shielding can help to reduce EMI by providing a low-impedance path for electromagnetic interference.

  7. Use ferrite beads: Ferrite beads can be used to suppress high-frequency noise on the power and signal lines.

  8. Avoid sharp corners: Sharp corners can cause signal reflections and increase the loop area, increasing the susceptibility to noise.

 

High-speed PCB (printed circuit board) grounding best practices

Best practices for high-speed PCB grounding

High-speed PCB (printed circuit board) grounding is an important aspect of designing and building electronic devices that operate at high speeds. Proper grounding can help to reduce electromagnetic interference (EMI) and improve signal integrity. Here are a few best practices for high-speed PCB grounding:

  1. Use a solid ground plane: A continuous, unbroken ground plane provides a low-impedance return path for high-frequency signals, reducing EMI and improving signal integrity.

  2. Minimize ground loops: Ground loops can cause EMI and signal integrity issues, so it's important to minimize the number of connections between different ground planes.

  3. Use wide and short traces: Wide and short traces reduce the inductance and resistance of the grounding paths, which can help to improve signal integrity and reduce EMI.

  4. Place decoupling capacitors close to the power pins: Decoupling capacitors can help to reduce power supply noise and improve signal integrity. They should be placed as close as possible to the power pins to minimize the inductance and resistance of the grounding paths.

  5. Use a star grounding configuration: A star grounding configuration, which connects all of the ground points to a single central point, can help to reduce EMI and improve signal integrity.

  6. Use shielded cables: Shielded cables can help to reduce EMI by providing a low-impedance path for electromagnetic interference.

  7. Use ferrite beads: Ferrite beads can be used to suppress high-frequency noise on the power and signal lines.

Analog signals


High-speed analog signal traces require special consideration when it comes to grounding in order to minimize noise and ensure signal integrity. Here are a few best practices for grounding high-speed analog signal traces:

  1. Use a separate ground plane: It is recommended to use a separate ground plane for high-speed analog signal traces, this will help to isolate the analog signals from digital noise and improve signal integrity.

  2. Keep the ground plane as close as possible to the signal trace: The ground plane should be placed as close as possible to the signal trace, this will help to reduce the loop area and minimize the coupling between the signal trace and the surrounding noise.

  3. Use a guard trace: A guard trace is a trace that surrounds the signal trace and it is connected to the ground plane. This helps to reduce the coupling between the signal trace and the surrounding noise.

  4. Minimize the trace length: Minimizing the trace length will help to reduce the parasitic capacitance and inductance, which can cause signal integrity issues.

  5. Use a balanced transmission line: A balanced transmission line such as differential pair or a coaxial cable can help to reduce the susceptibility to noise and improve the signal integrity.

  6. Control the impedance: The impedance of the signal trace should match the characteristic impedance of the transmission line to prevent signal reflections.

  7. Minimize the via count and use via stitching: Vias can introduce unwanted inductance and capacitance to the signal path, minimizing the number of vias, and using the via stitching technique can help to mitigate this issue.

Digital Signals


High-speed digital signal traces require special consideration when it comes to grounding in order to minimize noise and ensure signal integrity. Here are a few best practices for grounding high-speed digital signal traces:

  1. Use a separate ground plane: It is recommended to use a separate ground plane for high-speed digital signal traces, this will help to isolate the digital signals from analog noise and improve signal integrity.

  2. Keep the ground plane as close as possible to the signal trace: The ground plane should be placed as close as possible to the signal trace, this will help to reduce the loop area and minimize the coupling between the signal trace and the surrounding noise.

  3. Use a guard trace: A guard trace is a trace that surrounds the signal trace and it is connected to the ground plane. This helps to reduce the coupling between the signal trace and the surrounding noise.

  4. Minimize the trace length: Minimizing the trace length will help to reduce the parasitic capacitance and inductance, which can cause signal integrity issues.

  5. Control the impedance: The impedance of the signal trace should match the characteristic impedance of the transmission line to prevent signal reflections.

  6. Minimize the via count and use via stitching: Vias can introduce unwanted inductance and capacitance to the signal path, minimizing the number of vias, and using the via stitching technique can help to mitigate this issue.

  7. Use termination techniques: High-speed digital signals can reflect back and forth on the trace, causing signal integrity issues. Using termination techniques such as series termination or parallel termination can help to reduce reflections.

  8. Use of ground and power planes with low resistance and inductance: This will help to minimize the noise and keep the signal integrity.

Communication


High-speed communication signal traces require special consideration when it comes to grounding in order to minimize noise and ensure signal integrity. Here are a few best practices for grounding high-speed communication signal traces for some popular communication protocols:

  1. I2C:
  • Keep the clock and data lines as close as possible to their corresponding ground lines to minimize the loop area and reduce coupling.
  • Use a pull-up resistor on the clock and data lines to keep the lines at a known state when no communication is taking place.
  1. CAN bus:
  • Use a twisted pair for the CAN_H and CAN_L lines to reduce electromagnetic interference and improve signal integrity.
  • Keep the CAN_H and CAN_L lines as close as possible to their corresponding ground lines to minimize the loop area and reduce coupling.
  1. UART:
  • Use a separate ground plane for the UART signals to isolate them from other noise sources.
  • Minimize the trace length to reduce parasitic capacitance and inductance.
  1. RS485:
  • Use a twisted pair for the signal and ground lines to reduce electromagnetic interference and improve signal integrity.
  • Use a termination resistor at the end of the RS485 bus to reduce reflections.
  1. USB Type B and USB Type C:
  • Use a separate ground plane for the USB signals to isolate them from other noise sources.
  • Minimize the trace length to reduce parasitic capacitance and inductance.
  • Use differential signaling for USB Type C to improve signal integrity.
  1. SPI:
  • Keep the clock, data, and slave select lines as close as possible to their corresponding ground lines to minimize the loop area and reduce coupling.
  • Use a pull-up resistor on the slave select line to keep the line at a known state when no communication is taking place.
  1. Ethernet:
  • Use twisted pairs for the signal and ground lines to reduce electromagnetic interference and improve signal integrity.
  • Use a separate ground plane for the Ethernet signals to isolate them from other noise sources.
  • Use termination resistors at both ends of the Ethernet bus to reduce reflections.

It is important to note that the best practices for high-speed communication signal trace grounding may vary depending on the specific application and the requirements of the device. It's important to consult industry standards and guidelines and to test the design thoroughly before finalizing the PCB.

Mixed signals


High-speed PCBs with mixed signal traces (analog and digital) require special consideration when it comes to grounding in order to minimize noise and ensure signal integrity. Here are a few best practices for grounding high-speed mixed signal traces:

  1. Use separate ground planes: It is recommended to use a separate ground plane for the analog and digital signals. This will help to isolate analog signals from digital noise and improve signal integrity.

  2. Keep the ground planes as close as possible to the signal traces: The ground planes should be placed as close as possible to the signal traces, this will help to reduce the loop area and minimize the coupling between the signal traces and the surrounding noise.

  3. Use a guard trace: A guard trace is a trace that surrounds the signal trace and it is connected to the ground plane. This helps to reduce the coupling between the signal trace and the surrounding noise.

  4. Minimize the trace length: Minimizing the trace length will help to reduce the parasitic capacitance and inductance, which can cause signal integrity issues.

  5. Control the impedance: The impedance of the signal trace should match the characteristic impedance of the transmission line to prevent signal reflections.

  6. Minimize the via count and use via stitching: Vias can introduce unwanted inductance and capacitance to the signal path, minimizing the number of vias, and using the via stitching technique can help to mitigate this issue.

  7. Use isolation techniques: Techniques such as optoisolator or transformer isolation can be used to isolate analog and digital signals, reducing noise and improving signal integrity.

  8. Use power and ground planes with low resistance and inductance: This will help to minimize the noise and keep the signal integrity.

LeetCode C++ Cheat Sheet June

🎯 Core Patterns & Representative Questions 1. Arrays & Hashing Two Sum – hash map → O(n) Contains Duplicate , Product of A...