資源簡(jiǎn)介
找ModbusTCP好久,一點(diǎn)也不全,現(xiàn)傳一個(gè)client端包含報(bào)頭和協(xié)議部分,免費(fèi)隨便下。
代碼片段和文件信息
using?System;
using?System.Collections;
using?System.Text;
using?System.IO;
using?System.Net;
using?System.Net.Sockets;
using?System.Threading;
namespace?ModbusTCP
{
????///?
????///?Modbus?TCP?common?driver?class.?This?class?implements?a?modbus?TCP?master?driver.
????///?It?supports?the?following?commands:
????///?
????///?Read?coils
????///?Read?discrete?inputs
????///?Write?single?coil
????///?Write?multiple?cooils
????///?Read?holding?register
????///?Read?input?register
????///?Write?single?register
????///?Write?multiple?register
????///?
????///?All?commands?can?be?sent?in?synchronous?or?asynchronous?mode.?If?a?value?is?accessed
????///?in?synchronous?mode?the?program?will?stop?and?wait?for?slave?to?response.?If?the?
????///?slave?didn‘t?answer?within?a?specified?time?a?timeout?exception?is?called.
????///?The?class?uses?multi?threading?for?both?synchronous?and?asynchronous?access.?For
????///?the?communication?two?lines?are?created.?This?is?necessary?because?the?synchronous
????///?thread?has?to?wait?for?a?previous?command?to?finish.
????///?
????///?
????public?class?Master
????{
????????//?------------------------------------------------------------------------
????????//?Constants?for?access
????????private?const?byte?fctReadCoil?=?1;
????????private?const?byte?fctReadDiscreteInputs?=?2;
????????private?const?byte?fctReadHoldingRegister?=?3;
????????private?const?byte?fctReadInputRegister?=?4;
????????private?const?byte?fctWriteSingleCoil?=?5;
????????private?const?byte?fctWriteSingleRegister?=?6;
????????private?const?byte?fctWriteMultipleCoils?=?15;
????????private?const?byte?fctWriteMultipleRegister?=?16;
????????private?const?byte?fctReadWriteMultipleRegister?=?23;
????????///?Constant?for?exception?illegal?function.
????????public?const?byte?excIllegalFunction?=?1;
????????///?Constant?for?exception?illegal?data?address.
????????public?const?byte?excIllegalDataAdr?=?2;
????????///?Constant?for?exception?illegal?data?value.
????????public?const?byte?excIllegalDataVal?=?3;
????????///?Constant?for?exception?slave?device?failure.
????????public?const?byte?excSlaveDeviceFailure?=?4;
????????///?Constant?for?exception?acknowledge.
????????public?const?byte?excAck?=?5;
????????///?Constant?for?exception?slave?is?busy/booting?up.
????????public?const?byte?excSlaveIsBusy?=?6;
????????///?Constant?for?exception?gate?path?unavailable.
????????public?const?byte?excGatePathUnavailable?=?10;
????????///?Constant?for?exception?not?connected.
????????public?const?byte?excExceptionNotConnected?=?253;
????????///?Constant?for?exception?connection?lost.
????????public?const?byte?excExceptionConnectionLost?=?254;
????????///?Constant?for?exception?response?timeout.
????????public
評(píng)論
共有 條評(píng)論