Git Product home page Git Product logo

pmodbus's Introduction

PModbus

对NModbus4的封装。简单配置后即可进行多线程下的数据读写

Features

  1. 读写数据方便
  2. 连接状态通知
  3. 可以分组修改读取数据列表
  4. 断开自动年重连
  5. 可以设置延迟读取数据轮次
PModbusClient client;
private void ButtonStart_Click(object sender, EventArgs e)
{ 
    if (client == null)
     {
         //添加RS232通信
         var cc = new PModbusConnection(new SerialPortDevice()
         {
             ComPort = "COM1",
             BandRate = 115200,
             Timeout = 1000,
         });                               
         //添加需要读取的数据
     	cc.AddToRead(new PModbusReadItem(0, 100, PModbusType.Input) { GroupID = 1, Enabled = false });
        cc.AddToRead(new PModbusReadItem(0, 100, PModbusType.Hold));

         //添加数据存储类,并实例化PModbusClient
         client = new PModbusClient(cc, new PModbusStore(ref AppData.IDatas, ref AppData.ODatas));
         //注册状态改变的通知事件
         client.Notify += Clienter_Notify;
         //设置数据读写的间隔
         client.Interval=10;
         //启动任务
         client.Start();
		
         Debug.WriteLine(client.Connection.ToString());
     }
}
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {//程序关闭时,停止任务并释放资源
     if (client != null)
     	client.Stop();
 }
//指定的位置写入数据
client.Write(0,new ushort[] { 1});

pmodbus's People

Contributors

hearhank avatar

Watchers

James Cloos avatar  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.