Coder Social home page Coder Social logo

modbustcp-dotnet's Introduction

Introduction

Visual Studio modbusTCP class

This class implements a Modbus TCP master driver. The code is written in C# but the DLL can be used in any other language.

Picture

It supports the following function codes:

  • Read coils
  • Read discrete inputs
  • Write single coil
  • Write multiple coils
  • Read holding register
  • Read input register
  • Write single register
  • Write multiple registers

Background I will not explain how the Modbus protocol works in detail because there is plenty of information available online.

Modbus IDA home page

Modbus IDA PDF documentation

Using the code

All commands are sent in synchronous or asynchronous mode. If a value is accessed in synchronous mode, the program will stop and wait for the slave to respond. If the slave does not answer within a specified time, a timeout exception is called. The class uses multi-threading for both synchronous and asynchronous access. The class opens two communication channels for each slave. This is necessary because the synchronous thread has to wait for a command to finish. This would block the asynchronous connection. The class directory contains a help file (ModbusClassTCP\doc) with detailed information for every function.

A sample application is included in the package that shows the basic features. It uses asynchronous mode for all function calls. The sample has some additional code to make the result handling more comfortable.

Points of Interest

Remember that a lot of Modbus clients use a watchdog telegram to make sure the master is still active. If you don’t call this watchdog within a specified time, the slave will close the connection. This feature is used to avoid unused open ports when the connection is interrupted.

History

Next Version (04/03/2022)

  • Fixed: Typo in sample

Version 3.6 (26/03/2019)

  • Fixed: Handle null reference in receive function block when cable is disconnected

Version 3.5 (12/06/2018)

  • Fixed: Exception is not triggered when synchonous channel is disabled
  • Fixed: WriteSingleRegister now fires exception excIllegalDataVal if number of bytes is not 2

Version 3.4 (01/01/2015)

  • Added: Option to disable synchronous channel to limit number of connections to one
  • Added: Trigger exception if number of registers (250) or discrete values (2000) is exceeded

Version 3.3 (6/14/2013)

  • Fixed: ID high and low byte swapped
  • Added: Modbus parameter UNIT added to function calls

Version 3.2

First release Edit message

Write a small message here explaining this change. (Optional) © 2018 GitHub, Inc. Terms Privacy Security Status Help Contact GitHub API Training Shop Blog About Press h to open a hovercard with more details.

modbustcp-dotnet's People

Contributors

stephan1827 avatar fabrizioc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.