資源簡介
Modbus Rtu c# 相關代碼(CRC生成,數據發送,數據接收與驗證)
代碼片段和文件信息
using?System;
using?System.Collections;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.IO.Ports;
using?System.Text;
using?System.Threading;
using?Bandweaver.Bus.Data;
namespace?Bandweaver.applet.HaiNanDataAgent
{
????///?
????///?版權(C)?2008-2018上海波匯通信科技有限公司
????///?文件名稱:ModbusHelper.cs
????///?編寫人員:許盼盼
????///?編寫日期:2012/10/8?16:17:02
????///?功能描述:完成對Modbus操作幫助類
????///?更改歷史:
????///? ?
????public?class?ModbusController
????{
????????#region?事件
????????///?
????????///?接收數據
????????///?
????????public?event?RecivedDataEventHandler?RecivedDataEvent?=?null;
????????///?
????????///?接收到消息
????????///?
????????public?event?RecivedMessageEventHandler?RecivedMessageEvent?=?null;
????????///?
????????///?COMM口狀態改變事件
????????///?
????????public?event?ComPortStatusChangedEventHandler?ComPortStatusChangedEvent?=?null;
????????#endregion
????????#region?屬性
????????///?
????????///?狀態
????????///?
????????public?AppStatus?Status?=?AppStatus.停止;
????????///?
????????///?COM操作對象
????????///?
????????private?SerialPort?sp?=?new?SerialPort();
????????///?
????????///?鎖
????????///?
????????private?static?object?o?=?new?object();
????????///?
????????///?CRC驗證表
????????///?
????????public?byte[]?crc_table?=?new?byte[512];
????????///?
????????///?數據集合
????????///?
????????private?Dictionary?DicData?=?null;
????????///?
????????///?從機地址
????????///?
????????private?byte?SlaveID?=?0;
????????///?
????????///?數據發送對象配置信息
????????///?
????????private?ArrayList?DataList?=?null;
????????///?
????????///?COM口配置信息
????????///?
????????private?ComSetting?Setting?=?null;
????????#endregion
????????#region?構造函數
????????///?
????????///?構造函數
????????///? ?
????????public?ModbusController(RecivedConfigurationTable?configuration)
????????{
????????????#region?初始化CRC
????????????crc_table[0]?=?0x0;
????????????crc_table[1]?=?0xC1;
????????????crc_table[2]?=?0x81;
????????????crc_table[3]?=?0x40;
????????????crc_table[4]?=?0x1;
????????????crc_table[5]?=?0xC0;
????????????crc_table[6]?=?0x80;
????????????crc_table[7]?=?0x41;
????????????crc_table[8]?=?0x1;
????????????crc_table[9]?=?0xC0;
????????????crc_table[10]?=?0x80;
????????????crc_table[11]?=?0x41;
????????????crc_table[12]?=?0x0;
????????????crc_table[13]?=?0xC1;
????????????crc_table[14]?=?0x81;
????????????crc_table[15]?=?0x40;
????????????crc_table[16]?=?0x1;
????????????crc_table[17]?=?0xC0;
????????????crc_table[18]?=?0x80;
????????????crc_table[19]?=?0x41;
????????????crc_table[20]?=?0x0;
????????????crc_table[21]?=?0xC1;
????????????crc_table[22]?=?0x81;
????????????crc_table[23]?=?0x40;
????????????crc_table[24]?=?0x0;
???????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????98304??2003-12-30?19:43??Modbus?Poll?v3.60\Keygen.exe
-----------?---------??----------?-----??----
????????????????98304????????????????????1
- 上一篇:企業信息文檔管理系統
- 下一篇:C#操作INI配置文件
評論
共有 條評論