Modbus Source Code Libraries

Modbus is an application layer messaging protocol, positioned at level 7 of the OSI model that provides client/server communication between devices connected on different types of buses or networks. Modbus is a request/reply protocol and offers services specified by function codes. Modbus function codes are elements of Modbus request/reply PDUs.

Triangle MicroWorks’ Software Libraries provide a cost-effective means of supporting industry-standard protocols in your device. Incorporating our  Software Libraries in your products will shorten development time, freeing internal resources to work on company proprietary aspects of your products.

Triangle MicroWorks Software Libraries are available in two formats: .NET Protocol Components for incorporation in Windows .NET-based products, and ANSI-Standard C Source Code Libraries for all other platforms.

For almost 30 years, Triangle has provided the diagnostic tools and protocol expertise to  our customers to support all their conformance  & certification needs. We will work with you to ensure that your implementation of our source code libraries will pass all industry related certification and conformance testing.

Related Products

What's New

Current Release: v3.32
Release Date:  March 2024 

Newest Features in this Release

  • Added TCP channel callback functions to retrieve IP addresses when the server is connected or disconnected.

  • Channels are no longer closed automatically when the last session on the channel is closed.

  • Store the last exception Function Code so the user can find out what the Function Code is not accepted by the server device when needed.

  • In WinIoTarg, added a channel diagnostic mask bit to control whether diagnostics messages are generated.

  • In LinIoTarg improvements to use linked list instead of array for keep channels listening on a particular port. That improvement will allow unlimited channels be configured to one specific TCP port.
  • In WinIoTarg, if the TCP listening thread is not started due to the port being occupied, the channel is now closed more quickly (previously could take up to 5 seconds).

Key Additions to Recent Releases


  • “Slave” has been replaced by “Outstation”, “Controlled Station”, or “Server” depending on protocol in documentation, filenames, variable names, and function names. An effort has been made to maintain interface backward compatibility where possible.
  • Minor changes to allow SCL to build with VS2019 and VS2022 without modification related to std::string and .NET Framework version.
  • Added support for OpenSSL Version 3.x.x. OpenSSL Version 1.1.1 is still supported, however according to the End Of Life date for the 1.1.1 series is September 11 2023. Support for Version 1.0.2 has been removed.
  • In WinIoTarg and LinIoTarg add clientSourceIpPort to allow TCP Client Channels to specify the IP Port to use for originating TCP Connections.
  • Add support for TMWDIAG_ID_OCTETS bit to determine whether the actual Hex Octets from a transmitted or received message are formatted and/or displayed in a diagnostic message.
  • Allow Modbus TCP to be configured to use UDP Only instead of a TCP connection.


  • In LinIoTarg speed up processing during TCP Channel closing.
  • In LinIoTarg function call to deprecated pthread_mutexattr_setkind_np() has been replaced with a call to pthread_mutexattr_settype().
  • Add support for multiple Polled Timers and disabling the Windows Target Layer multiple timers to allow application to run SCL in the context of its own threads.


  • In WinIoTarg added define to allow channel thread code to be compiled out.
  • Improved TLS example code and include sample TLS Certificates for ANSI C and
    .NET SCLs.


  • In WinIoTarg potentially speed up waiting for a channel thread to exit when a channel with olledMode=false is closed.
  • In LinIoTarg replaced deprecated stime() with clock_settime().
  • In LinIoTarg speed up new connection indication to protocol library when running
    with polledMode=true.
  • Support .NET txPhysCallbackEvent, rxPhysCallbackEvent, txApplCallbackEvent,
    and rxLinkCallbackEvent callback events in TMWChannel class for all protocols.
    Move .NET rxLinkHdrCallbackEvent and rxTransportCallbackEvent callback events
    out of TMWChannel class to DNPChannel since those two events only apply to
    DNP channels and were misleading.


  • In LinIoTarg use localIpAddress when a TCP Client binds to the connect socket.


  • General bug fixes and code optimization.


  • Created an implementation guide for SCLs. 
  • The SCL now supports a common serial configuration structure. 
  • Added event driver support to Windows serial channel. 
  • WinIoTarg now uses the Channel thread to check for received data eliminating the need for a separate CheckForInput thread/class. 
  • Update Linux target layer to use consistent logging technique. 
  • LinIoTarg now creates a thread per channel (when not configured to run in polled mode). Once the channel has been opened, this thread will establish/listen for the channel connection and wait on the data socket for incoming data. This eliminates the latency when polling for received data. Also, locking has been reduced by eliminating the linked list of TCP Channels which required locking each time the list was accessed. 
  • The Linux target layer has been updated to provide a basis for porting a target layer to another OS: 
  • • The dependency on threads has been removed.
    • The Linux target layer will conditionally support poll and select. The Linux target layer will default to use epoll/poll which is more efficient than select and correctly handles file descriptors greater than 1024. However, select will continue to be supported by using a conditional such that it can be tested with Linux and provide a port example for OS's that only support select.
    • A tmwtargcnfg.h file has been added to both the Linux and Windows target layer. This configuration file defines which features a given target layer supports. This will allow customers porting the Linux target layer to other OS's to easily identify code that may be unnecessary for their application and remove it instead of wasting time porting it. Target layer features currently defined in this file are:
    1. RS232
    2. TCP
    3. UDP (Only required for DNP)
    4. TLS
    5. EPOLL
  • In addition, SampleIoTarg has been created. This Sample target layer is a target layer example that can be compiled and linked with the wintoolkit C example programs that has no OS dependencies. It can be used as a baseline target layer to port the library to another OS or RTOS.  It can be built by specifying 
    build=sample from the Linux command line. 


  • Made improvements to target layer timer examples.
  • Implemented event driven receive data in winiotarg so channels don’t have to be polled. This is also available in liniotarg.
  • Updated the Linux target layer, replaced LINIOCNFG_EVENT_DRIVEN conditional
    with polledMode configuration.
  • Support for epoll has been added to the Linux target layer. This support is
    controlled by the preprocessor conditional LINIOTARG_SUPPORT_EPOLL. If this is not defined, select is used. The select option has been left in place so we continue to have an example that can be ported to OS’s that do not support epoll.
  • Include files to allow SCL customers to generate Windows project files for different
    versions of Visual Studio.
  • Support for 64-bit versions of the .NET Protocol Components has been added.
  • Added configuration for the generation of diagnostic messages per sector, session,
    and channel to allow maximum flexibility. Maximum performance can be achieved
    by configuring each mask to zero so no diagnostic messages are generated, thus
    no messages would be forwarded to the .NET code. This also would allow a user
    to enable diagnostic messages on a single sector, session, etc. in a large
    configuration on a problem connection and avoid having to filter out diagnostic
    messages from all other connections.
  • Updated database wrapper header files and removed the /clr flag from the
    modbusManaged and utilsManaged projects.


  • Added support for TLS v1.2 in target layer
  • Included support for 64 bit builds in the example project and solution files provided for Visual Studio
  • Improved management of Transaction IDs by Master when responses are severely delayed
  • Improved performance of database interface and other library functions
  • Restructured directories and sample code for Windows® and Linux® target layer libraries
  • Added support for IPv6 in Linux target layer (Modbus TCP)
  • Expanded Windows target layer support for resolving IP address from destination host name
  • Updated Linux sample makefiles to generate debug information by default
  • Allow compile time choice of using either standard or Microsoft “safe” string functions that include the length of the buffer to be written to (ie strcpy or strcpy_s)
  • Added more checking to discard improperly formatted messages
  • Improved Linux makefiles and Windows® solution and project files
  • Allow compile time choice of using either standard or Microsoft “safe” string functions that include the length of the buffer to be written to (ie strcpy or strcpy_s)
  • Added more checking to discard improperly formatted messages
v3.19 - allow use of either UNICODE or MBCS character set
v3.18 - Support for C99 standard types for 16 bit and 32 bit types
v3.16 - Corrected GNU-Wall compiler warnings
v3.09 - Modifications to conform to new Modbus certification tests.
v3.07 - Added sample Linux and Windows target implementation.
v3.01.01 - Added ability to keep time on a per-session basis.
v3.00.35 - Added memory alignment support.
v3.00.32 - Added support for multiple threads.
v3.00.25 - Added ability for Master to queue commands.



Quick Links  Contact Us:
About Us

Triangle MicroWorks, Inc.
Sales: +1 919.870.5101
Support: +1 919.781.1931
Fax: +1 919.870.6692

Follow us on YouTube Follow us on Facebook Visit us on LinkedIn Follow us on Twitter

Copyright © 2013-2024 Triangle MicroWorks, Inc. All Rights Reserved