There are 4 types of IP addresses (as shown in Figure 3): Class A is used to process very large networks, up to 16,387,064 hosts (1 to 126); Class B networks can have up to 64,516 hosts (the first segment of network addresses) It is 128 to 191); Class C is used for small networks, and there are up to 254 hosts (the first segment of the network address is 192 to 223); Class D is used for multicast transmission for multi-purpose information transmission. The all zero ("0.0.0.0") address corresponds to the current host, and the all 1 address ("255.255.255.255") is the broadcast address of the current subnet.
TCP is a transport layer-based protocol, and protocol files are available from RFC793 for a wide range of connection-oriented, reliable protocols. It can decompose the message into segments, reassemble the segments at the destination station, support resending the unreceived segments, and provide full-duplex connections between the two devices, allowing them to efficiently exchange large amounts of data. TCP uses the sliding window protocol to efficiently use the network. Since TCP seldom interferes with the operation of the underlying delivery system, it adapts to various delivery systems and provides flow control to enable communication at various rates. A segment is the basic transmission unit used by TCP to transmit data or control information.
3, MODBUS data frame format
It is transmitted over TCP/IP Ethernet and supports both Ethernet II and 802.3 frame formats. As shown in Figure 3, the Modbus TCP data frame contains the message header, function code, and data 3 parts.
4, MODBUS function code
4.1 3 types
(1) Common function code (as shown in Table 2): The defined function code guarantees its uniqueness and is recognized by Modbus.org.
(2) There are two sets of user-defined function codes, 65 to 72 and 100 to 110 respectively, without approval, but the uniqueness of the code is not guaranteed. If it becomes a public code, it must be approved by RFC.
(3) Reserved function codes, codes used by some companies in some traditional devices, are not for public use.
Table 2 Modbus Common Common Code Function
4.2 Function code division: According to the depth of application, it can be divided into 3 categories.
(1) Category 0, the smallest available subset for the client/server: read multiple holding registers (fc.3); write multiple holding registers (fc.16).
(2) Category 1, common code for basic reciprocal operation: read coil (fc.1); read digital input (fc.2); read input register (fc.4); write coil (fc.5) ; Write a single register (fc.6).
(3) Category 2, for routine operations and data transfer functions of the human-machine interface, monitoring system:
(4) Force multiple coils (fc.15); read general-purpose registers (fc.20); write general-purpose registers (fc.21); mask write registers (fc.22); read-write registers (fc.23).
5, the basic concept of VB
VB (Visual Basic) is an object-oriented programming language. It is used to develop applications under the WINOOWs operating system. It provides many interface members. Objects, properties, events, and methods are four important interfaces. VB provides many Commonly used controls.
5.1 Volume Control
As shown in Figure 4(a), the label control is dedicated to displaying text and numbers, and the display is shown in Figure 4(b).
5.2 button controls
The button control is shown in Figure 5(a). The control has a high usage rate and provides a button for the system user to operate, as shown in Figure 5(b).
6. TCP/IP Ethernet communication based on Winsock control
To complete the Ethernet communication between VB and PLC, Winsock control is needed. It is necessary to explain the control in detail. Winsock is an ActiveX control that requires many items to be added manually. The steps are as follows:
(1) Select [Project] of the menu.
(2) Select [Parts].
(3) In the pop-up dialog box, make the selection as shown in Figure 6.
Figure 6 dialog interface
(4) As shown in Figure 7, the Winsock control appears on the Parts tab.
7, the basic properties of the Winsock control
This control is invisible to the user at runtime and provides an easy way to access TCP and UDP web services without having to understand the underlying details. You only need to set the properties and call the methods provided at the appropriate time.
The main attributes are:
BytesReceived: Returns the number of bytes in the current buffer, we can use the GetData method to receive data. Read-only and not available at design time.
LocalHostName: Returns the native name string, which is not available at design time.
LocalIP: Returns the IP address string expressed in the format of (xxx.xxx.xxx.xxx). Not available at design time, read-only at runtime.
LocalPort: This unit uses the receiving port to read and write, and is available at design time, Long type. For customers, if you do not need to specify a port, send data with port 0. In this case, the control will randomly select a port. After a connection is determined, it is the port of TCP. For servers, the port used for listening. If set to 0, a random number is used. This property automatically includes the port used after calling the Listen method. Port 0 is always used to establish a dynamic connection between two computers. The client wants to get a random port through port 0 to connect to the server with a "callback".
Protocol: The type of socket, either TCP or UDP. The default is TCP. Set to sckTCPProtocol to indicate that the TCP protocol sckUDPProtocol represents the UDP protocol. Use the Close method to close this property before it is reset.
RemoteHost: The host that sends or receives data. You can provide a host name such as FTP://ftp.microsoft.com or an IP address string such as "100.0.1.1".
RemoteHostIP: The IP address of the remote host. For the client program, use the Connect method after the connection is determined. This property contains the IP name string of the remote host. For server programs, this property contains an IP string after the connection requirement is introduced (Connection Request event). When using a UDP socket, this property is the machine IP address string that sends UDP data after the Data Arrival event occurs.
RemotePort: Connects to the socket port value. For example, HTTP applications typically use port 80 and FTP uses 21.
MiFi stands for Mobile WiFi and it works in the same way as a WiFi router, with the difference that you can set up a wireless personal area network and get online where ever you are on the globe. 4G-LTE routers belong to the fourth generation routers that use the "long-Term Evolution Technology" (LTE). This LTE technology is the successor of 3G technologies such as UMTS, HSDPA and HSUPA. The latest generation 4 g LTE MiFi routers are very fashional and stylish.
4G WIFI Router, TDD Router, LTE Router, 4G HOTSPOT, WIFI Device, powerbank router
Shenhzhen Tongheng Weichuang Technology Co., Ltd , https://www.thwclte.com