PC high-level language with Schneider, Rockwell, Delta and Other PLC's Modbus communication source code (Modbustcp.dll/modbusrtu.dll)

Source: Internet
Author: User

1.0 Communication Components Overview

This kind of communication component is suitable for the industrial automation control system based on PC advanced language, which is used for data communication between PC and programmable controller (PLC), intelligent instrument and so on. The component takes a dynamic-link library file (*. DLL) in the form of a PC system project engineering reference to the component, call the corresponding properties and methods functions, can quickly realize the PC and PLC data efficient exchange.

DLL communication components do not need to be installed, directly copied to the project file directory, easy to package installation and deployment, without any configuration, direct call function, and application development seamless interface; many years of engineering experience in the software team development testing, through the company and the customer's massive practical application test, stable and reliable, the use of stable and efficient internal protocol, No need to write PLC internal program coordination, direct access to the PLC memory, communication response fast; built-in dynamic management of multi-independent thread connections, while supporting the external application of multi-threaded structure calls; compatible with all development environments under the Windows system, including various versions of vb.net, C #, VC + +, As well as Deiphi, VB, LabVIEW, etc. support almost all of the PLC's CPU comes with communication port, communication expansion module.

2.0 Related Information

MODBUSTCP client DLL: ModbusTCP.DLL

Modbustcp server-side DLL: modbustcp_server.dll

Modbusrtu DLL Program: ModbusRTU.DLL

Network Port transmission RTU DLL Program: TransModRTU.DLL

The Modbus Address Table of Delta, Yonghong, Shun Jie and other plc: plc Address Table

3.0 data Types

INT16:16-bit signed integer; dint32:32-bit signed integer;

uint16:16-bit unsigned integer; hex32:32 bit 16 binary character;

bin16:16 bit binary string; real32:32 bit single precision floating point data;

Features supported by the 4.0 DLL

01 Read coil Status Get the current state of a set of logic coils (on/off)

02 Read input state gets the current state of a set of switch inputs (on/off)

03 Read hold register gets the current binary value in one or more hold registers

04 read input Register to get the current binary value in one or more input registers

15 strong multi-coils to strongly set the continuity of a series of continuous logic coils

16 preset multiple registers load specific binary values into a continuous sequence of hold registers

5.0 functions and Parameters

5.1 Function parameters

[Entlink] set the communication parameters of PC and PLC, establish Ethernet connection with PLC;

Parameter: IP address of the pcip,string,pc end

Pcport, Uint16, PC-side network port

PLCIP, String, PLC IP address

Plcport, Uint16, PLC communication port

Rack, Uint16, PLC rack number (other than Siemens, other brands are 0)

Slots, UINT16, PLC socket number of the CPU (other than Siemens, other brands are 0)

Handle, Integer, returns the network handle, the multi-PLC network when using the handle to operate a different plc

SN, String, call the serial number, and use the DLL in pairs, you can contact the company to obtain

Return value: Int16, function execution result, see 5.3 detailed description.

[Comlink] set the communication parameters of PC and PLC, establish serial connection with PLC;

Parameters: Commport,uint16, PC communication port connected to PLC

Commrate,int32, the rate of communication with the PLC

Databit, Uint16, number of communication data bits

Stopbit,uint16, number of stop bits for data

Parity,prttype, data Check mode

Station, UINT16, PLC stations number

Overtime,uint16, communication time-out limit, millisecond units

SN, String, call the serial number, by contacting the company to obtain

Return value: Int16, function execution result, see 5.3 detailed description.

[delink] disconnection from the PLC connection;

Parameters: Handle, Integer, network handle, multi-PLC network when the corresponding plc is operated by the handle

Return value: Int16, function execution result, see 5.3 Detailed description

[Cmdread] read multiple plc memory data;

Parameters: Handle, Integer, network handle, multi-PLC network when the corresponding plc is operated by the handle

Memory, Plcmemory, PLC data area enumeration, see 5.2 Detailed description

ValType, DataType, data type enumeration, see 5.2 Detailed description

block, Uint16, number of DB blocks, non-DB data 0

Address, Uint16, the beginning of the word to manipulate

Count, Uint16, number of words to manipulate

Redata (), Object, read data (address parameter)

Return value: Int16, function execution result, see 5.3 Detailed description

[Cmdwrite] Bulk write data to the PLC memory;

Parameters: Handle, Integer, network handle, multi-PLC network when the corresponding plc is operated by the handle

Memory, Plcmemory, PLC data area enumeration, see 5.2 Detailed description

ValType, DataType, data type enumeration, see 5.2 Detailed description

block, Uint16, number of DB blocks, non-DB data 0

Address, Uint16, the beginning of the word to manipulate

Count, Uint16, number of words to manipulate

Data (), Object, to be written to the PLC (address parameter)

Return value: Int16, function execution result, see 5.3 Detailed description

[bit_test] reads its state as bit (bit);

Parameters: Handle, Integer, network handle, multi-PLC network when the corresponding plc is operated by the handle

Memory, Plcmemory, PLC data area enumeration, see 5.2 Detailed description

block, Uint16, number of DB blocks, non-DB data 0

Address, Uint16, the word addresses of the bits to be manipulated

bit,uint16, bit numbers in the word address to be manipulated

State, Boolean, read the status of the bit (address parameter)

Return value: Int16, function execution result, see 5.3 Detailed description

[Bit_set] sets its state to on in bit (bit) mode;

Parameters: Handle, Integer, network handle, multi-PLC network when the corresponding plc is operated by the handle

Memory, Plcmemory, PLC data area enumeration, see 5.2 Detailed description

block, Uint16, number of DB blocks, non-DB data 0

Address, Uint16, the word addresses of the bits to be manipulated

bit,uint16, bit numbers in the word address to be manipulated

Return value: Int16, function execution result, see 5.3 Detailed description

[Bit_reset] resets its status to off in bit (bit) mode;

Parameters: Handle, Integer, connection handle, multi-PLC network when using this handle to operate the corresponding PLC

Memory, Plcmemory, PLC data area enumeration, see 5.2 Detailed description

block, Uint16, number of DB blocks, non-DB data 0

Address, Uint16, bit number to manipulate bit in Word address

bit,uint16, number of digits to be manipulated

Return value: Int16, function execution result, see 5.3 Detailed description

5.2 Enumeration struct-Body parameter description:

--plcmemory the type of memory area of the PLC to be operated:

DI: Input port;

DQ: Output port;

DR: Data Register D region

HR: Maintain area H zone

5.3 Description of return value:

0 implementation Success;

-1 IP address or port parameter error;

-2 network connection error;

-3 Connection parameter error causes connection failure;

-4 plc handshake Connection Abnormal;

-5 plc handshake is not responding;

-6 plc handshake response Error;

-10 read data exceeds the maximum data volume limit;

-11 data sending exception when reading data;

-12 read the data when the PLC response time-out;

-13 Read Data plc return format error;

-14 Read Data plc return data error;

-15 Read Data plc return data check error;

-20 write data exceeds the maximum data volume limit;

-21 data sending exception when writing data;

-22 Write Data plc response timeout;

-23 Write Data plc return format error;

-24 Write Data plc return data error;

-25 Write Data the PLC return data check error;

-31 source data processing error when conversion;

-32 error in data processing when conversion;

-70 plc Memory area function is limited;

-80 no network card in PC system;

-81 the IP address format of the PC is wrong;

-82 plc IP address format is wrong;

-83 ping command returns an error;

-99 Connection Serial number error or test number exceeds trial limit;

6.0 component use steps

A. Copy the DLL file to the project directory where the component is needed;

B. Registering DLLs and their associated resources (the DLL assembly component of the dotnet framework does not need to be registered);

C. Refer to the component in the project programming software, different programming language reference methods, see the MSDN Help documentation for the language in use;

D. Define and instantiate the communication component with reference to the routine, and write the relevant communication code;

7.0 Technical Support

This DLL component is suitable for automation software engineers with high-level language Foundation, and the company provides customized solutions for PC and PLC communication, including customized OPC data server software, Ethernet data Server software, etc. Industrial data Acquisition project, etc. welcome to exchange consultation.

Any DLL communication component, as well as the company's OPC data server Development Kit and other industrial data services products will be available in multiple languages with the product sample, while providing 24-hour technical support through the following methods:

PC high-level language with Schneider, Rockwell, Delta and Other PLC's Modbus communication source code (Modbustcp.dll/modbusrtu.dll)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.