开发工具:
文件大小: 37kb
下载次数: 0
上传时间: 2016-12-07
详细说明: The modbus protocol comes in two flavors: RTU and ASCII. RTU is a binary implementation and is often most desirable. As such, this discussion will pertain solely to the RTU standard. public bool SendFc3(byte address, ushort start, ushort registers, ref shor t[] values) { //Ensure port is open: if (sp.IsOpen) { //Clear in/out buffers: sp.DiscardOutBuffer(); sp.DiscardInBuffer(); //Function 3 request is always 8 bytes: byte[] message = new byte[8]; //Function 3 response buffer: byte[] response = new byte[5 + 2 * registers]; //Build outgoing modbus message: BuildMessage(address, (byte)3, start, registers, ref message); //Send modbus message to Serial Port: try { sp.Write(message, 0, message.Length); GetResponse(ref response); } catch (Exception err) { modbusStatus = "Error in read event: " + err.Message; return false; } //Evaluate message: if (CheckResponse(response)) { //Return requested register values: for (int i = 0; i < (response.Length - 5) / 2; i++) { values[i] = response[2 * i + 3]; values[i] <<= 8; values[i] += response[2 * i + 4]; } modbusStatus = "Read successful"; return true; } else { modbusStatus = "CRC error"; return false; } } else { modbusStatus = "Serial port not open"; return false; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.