1.0 Communication Components Overview
Communication components for PC and programmable controller (PLC), intelligent instrument and other data communication, suitable for high-level PC-based industrial automation control system. The component takes a dynamic-link library file (*. DLL) in the form of a PC system Project engineering reference the component, call the corresponding property and method function, can quickly realize the high-efficient data exchange between PC and PLC.
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, directly call functions, and application development seamless; many years of engineering experience in the software team development testing, through the company and the customer's massive actual engineering application inspection, 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 Communication Component Name
3.0 data Types
The communication component can read and write to the PLC input and output port, as well as the internal intermediate relay storage area, internal data storage area, and extended storage area, and supports the following data types:
0 bool1:1-bit boolean data;
1 int16:16-bit signed integer;
2 uint16:16 bit unsigned integer;
3 dint32:32-bit signed integer;
4 hex32:32 bit 16 binary characters;
5 real32:32 bit single precision floating point data;
6 bin16:16 bit binary string;
7 Char8:8 bit single character (ASCII)
8 Byte8:8 bit single byte data;
9 string: Multiple characters or numbers of strings (ASCII)
4.0 functions and Parameters
4.1 Function parameters
[Entlink] set up the communication parameters of PC and PLC, establish Ethernet connection with PLC;
Parameters: pcip,string, local address, IP address on PC side
Pcport, Uint16, local port, PC-side network port, default is 0
PLCIP, String, remote address, which is the IP address of the PLC
Plcport, Uint16, remote port, or PLC communication port
Rack, Uint16, PLC rack number
Slot, UINT16, PLC socket number of the CPU
Handle, Integer, DLL component returns the connection handle of the PLC in the network *
SN, String, call sequence number, can contact the company to obtain
Overtime,uint16, communication time-out limit, milliseconds unit, default 1000
Return value: Int16, function execution result, see 4.3 detailed description.
[Comlink] set up 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 sequence number, by contacting the company to obtain
Return value: Int16, function execution result, see 4.3 detailed description
[delink] disconnection from the PLC connection;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Return value: Int16, function execution result, see 4.3 detailed description
[Cmdread] Bulk reading of PLC data;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
ValType, DataType, data type enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, where to read the start of the storage area
Count, Uint16, number to read, in Valtype corresponding data type
Redata (), object/string, read data (form parameter for address mode)
Return value: Int16, function execution result, see 4.3 detailed description
[Cmdwrite] Bulk write data to the PLC;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
ValType, DataType, data type enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, where to write the start of the storage area
Count, Uint16, number to write, in valtype corresponding data type
Data (), object/string, to be written to the PLC (the form parameter of the address method)
Return value: Int16, function execution result, see 4.3 detailed description
[bit_test] reads the state of a bit as bit (bit);
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, the word or byte addresses where the bits to read are located
Bit,uint16, the bit number to be read in address
State, Boolean, read the status of the bit (the form parameter of the address mode)
Return value: Int16, function execution result, see 4.3 detailed description
[Bit_set] sets its state to on in bit (bit) mode;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, the word or byte addresses to which the bit is to be set
Bit,uint16, the bit number to be set in address
Return value: Int16, function execution result, see 4.3 detailed description
[Bit_reset] resets its status to off in bit (bit) mode;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, the word or byte addresses where the bit to reset is located
Bit,uint16, the bit number in address to reset
Return value: Int16, function execution result, see 4.3 detailed description
[cmdreadstring] Read the string in the PLC;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, where to read the start of the storage area
Plcdatasize, Uint16, PLC the maximum number of characters that are defined in a stored character
Return value: String, which is read as normal, empty when the exception is
[cmdwritestring] write String to PLC;
Parameters: Handle, Integer, the handle of the PLC in the network obtained by the Entlink function * *
Memory, Plcmemory, PLC data area enumeration, see 4.2 Detailed description
block, Uint16, number of DB blocks, non-DB data 0
Address, Uint16, where to write the start of the storage area
Plcdatasize, Uint16, PLC the maximum number of characters that are defined in a stored character
Data, String, the number of characters to be written to the PLC, the length should be ≤plcdatasize
Return value: String, which is read as normal, empty when the exception is
[Dataconvert] data type conversion function;
Parameters: Sourtype,datatype, data type enumeration, see 4.2 Detailed description
Sourdata, Object, the source data that needs to be converted
Desttype, DataType, data type enumeration, see 4.2 in detail.
Destdata, object, converted target data (form parameter for address mode)
Startbyte, Int16, the starting byte from which the target data is taken from the source data (optional parameters)
Return value: Int16, function execution result, see 5.3 detailed description.
*1:handle parameter Description
In order to facilitate the use of the same application to connect more than one plc set parameters, when called outside the communication components, define a global variable, DLL after the network connection with the PLC, automatically assign the plc handle data, external programs through the handle to distinguish between the operation of different plc; variable is input output type parameter, That is, the form parameter of the address method, the external assignment is invalid.
4.2 Enumeration struct-Body parameter description:
--plcmemory the type of memory area of the PLC to be operated:
DI: digital input port;
DQ: Digital output port;
MR: Internal intermediate relay area;
DR: Internal data register v/db region;
--prttype Serial Communication Verification mode
None: No check
ODD: Odd Check
Even: even test
4.3 Description of return value:
0 implementation Success;
-1 IP address or port parameter error;
-2 wrong network connection error;
-3 Connection parameter error causes connection failure (e.g. rack>7, slot>15, etc.);
-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;
-18 the network handle parsing error of PLC;
-19 PLC network handle data 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;
-28 the network handle parsing error of PLC;
-29 PLC network handle data error;
-31 source data processing error when conversion;
-32 error in data processing when conversion;
-Parameter error of 41-bit operation function;
-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;
5.0 component use steps
5.1 Basic Steps
A. copy DLL, OCX file to the project directory that needs to use the component;
B. Register DLL, OCX file (VS. NET Platform DLL assembly component is not registered);
C. referencing DLL files in the project development environment, different development environment reference methods differ, refer to the Help document of the language used;
D. Define and instantiate the communication component with reference to the routine, and write the relevant communication code;
5.2 DLL Registration method
Vs. NET Platform DLL assembly components are not registered, the ActiveX COM component (*.dll/*.ocx) needs to be registered under the system for normal use, there are two main methods of registration:
A. Code registration: The full path and file name of the shell "regsvr32 \s" + Component with the shell command provided by Windows;
B. Manual registration: At the same time press "Win" key + "R" built, in the Popup Run dialog box, enter:
"Regsvr32" + space + the full path and file name of the component, then click "Confirm" button;
Windows7 and above system registration, we recommend the following settings for the user account:
Control Panel-user account and Family Safety-user accounts-change user Account Control settings, drag the slider to the bottom, i.e. "Never notify".
Windows7 and above system 64-bit registration method:
A. Create a new directory under C:\Windows\SysWOW64\ (take Regdll as an example), copy the DLLs that need to be registered to this directory (take WinTcpS7.dll for example);
B. Click Start, type cmd in the "Search programs and Files", and then right-click on the cmd menu that is searched and run with administrator's permission;
C. At this point the cmd prompt is C:\Windows\System32, type: Regsvr32 C:\Windows\System32\regdll\WinTcpS7.dll
D. Press Enter and then prompt to register successfully (note that at this point you are using Regsvr32.exe in the SysWow64 directory, not regsvr32.exe under System32).
C # communicates with Siemens PLC