Previously, Zheng Motion Technology discussed "firmware upgrades," "ZBasic program development," and "ZPLC program development" for motion controllers. Today, we will learn about communication between motion controllers and touchscreens.
Video tutorials : www.zmotion.com.cn
I. Introduction to Communication between Controller and Touch Screen
1. Touchscreen supported by the controller
Any touchscreen that supports the MODBUS communication protocol can be connected to a positive motion controller. When the controller communicates with the touchscreen using the MODBUS protocol, the data needs to be placed in the MODBUS register for transmission.
2. Address relationship between the controller and the touchscreen Modbus register
The MODBUS address mapping of the controller differs from that of touchscreens from other manufacturers.
The controller's MODBUS address starts from 0. When communicating with the Weintek touchscreen, the address also starts from 0, so there is a one-to-one correspondence.
The controller MODBUS_BIT(0) corresponds to the Weintek touchscreen MODBUS_0X_0, which is a boolean type.
The controller MODBUS_REG(0) corresponds to the Weintek touchscreen MODBUS_4X_0 word register.
When communicating with the Kunlun Tongtai touchscreen, the Kunlun Tongtai address starts from 1, and the controller address starts from 0, so the touchscreen address is incremented by 1.
The controller MODBUS_BIT(0) corresponds to the Kunlun Tongtai touchscreen MODBUS_0x_1, which is a boolean type.
The controller MODBUS_REG(0) corresponds to the Kunlun Tongtai touchscreen MODBUS_4x_1, word register.
The controller program can be programmed using the Basic language or PLC ladder diagram supported by ZDevelop software.
In the Basic language, MODBUS_BIT(0) corresponds to M0 in the PLC ladder diagram.
In the Basic language, MODBUS_REG(0) corresponds to D0 in the PLC ladder diagram.
3. Controller MODBUS Register
MODBUS communication data is stored in MODBUS registers. The controller's MODBUS registers conform to the MODBUS standard communication protocol and are divided into two categories: bit registers and word registers.
Bit register: MODBUS_BIT, commonly referred to as MODBUS_0X on touchscreens, Boolean type.
Word registers include MODBUS_REG (16-bit integer), MODBUS_LONG (32-bit integer), MODBUS_IEEE (32-bit floating-point), and MODBUS_STRING (8-bit byte). Touchscreens typically use MODBUS_4X.
In the controller, all MODBUS word registers occupy the same system variable space . One LONG register occupies two REG addresses, and another IEEE register occupies two REG addresses. When using them, care should be taken to stagger the word register number addresses.
⊙MODBUS_LONG(0) occupies two REG addresses, MODBUS_REG(0) and MODBUS_REG(1).
⊙MODBUS_LONG(1) occupies two REG addresses, MODBUS_REG(1) and MODBUS_REG(2).
⊙MODBUS_IEEE(0) occupies two REG addresses, MODBUS_REG(0) and MODBUS_REG(1).
⊙MODBUS_IEEE(1) occupies two REG addresses, MODBUS_REG(1) and MODBUS_REG(2).
Therefore, it is important to note that the MODBUS_REG, MODBUS_LONG, and MODBUS_IEEE addresses must not overlap in user applications.
The controller's MODBUS storage space is arranged as follows:
II. Connection method between touch screen and controller
Optional serial port connection or network port connection.
1. Network port connection
The controller's default IP address is 192.168.0.11, which can be viewed in the software's "Controller Status" window. The IP address can be modified using the IP_ADDRESS command or in the IP address modification window; changes are permanent. The controller must have at least two network ports, port number 502, supporting MODBUS-TCP protocol connections for the touchscreen.
View the number of network port channels
Different controller models support different numbers of serial port channels and network port channels. You can check the number of channels by sending "?*port" in the online command prompt; the number of channels determines the number of devices the controller can connect to simultaneously.
Send "?*port_status" in the online command bar to check if the communication port is already in use.
View current network port protocol
Use the PROTOCOL command to return the communication protocol of the current channel, and determine the protocol based on the return value.
2. Serial port connection
The serial port is typically selectable as either RS232 or RS485. The default parameters are: baud rate 38400, 8 data bits, 1 stop bit, and no parity. Serial port parameters are configured using the SETCOM command. The SETCOM parameters will revert to their default values after the controller is powered on again, so please include the SETCOM setting at the beginning of your program. The MODBUS protocol station number (ADDRESS) for all serial ports on the controller ranges from 1 to 127, with a default of 1.
MODBUS Master/Slave Selection
In addition to configuring the basic parameters of serial port communication, the SETCOM command can also configure the communication protocol, set the controller as the master or slave device, and enable a custom communication mode (i.e., mode=0 no protocol mode).
Syntax: SETCOM
(baudrate,databits,stopbits,parity,port[,mode] [,variable] [,timeout])
mode parameter selection protocol: When communicating with the touchscreen, the mode parameter selection protocol is: 4
Port0: setcom(9600,8,1,0,0,4,2,1000)
Port1: setcom(9600,8,1,0,1,4,2,1000)
Serial port retains configuration even when power is lost
The SETCOM instruction can select a register, which defaults to the MODBUS register. It can be configured to use a power-down retainable register to store data.
The variable parameter selection register: the controller defaults to 2 at the factory. In this case, the system MODBUS register and VR are two independent ranges.
Example of variable parameter selection:
Port0: setcom(9600,8,1,0,0,4,2,1000)
III. Controller connection to touchscreen
General usage procedure:
The controller program was written using ZDevelop software and downloaded to the controller.
Once the program for the touchscreen is written using the corresponding programming software, it is downloaded to the touchscreen and saved.
After the program download is complete, select either the serial port or the network port to connect the touch screen and the controller for offline operation.
IV. Communication Examples between Controller and Weintek Screen
The following is an explanation of how to use a touchscreen, taking the communication between the controller and the Weintek screen as an example.
Step 1: The program on the controller side is written using ZDevelop software and downloaded to the controller.
Step 2: Download the touchscreen program. The program for the Weintek touchscreen is written using EasyBuilder programming software. After the program is completed, open the "System Parameter Settings" window, as shown in the image below.
1) Add the device to be connected to the touchscreen.
The device list will display the local touchscreen and local devices. If a local device is listed, double-click the row. If no local device is listed, click "New Device/Server..." to bring up the device properties window.
2) Set device properties
When selecting the device type, first choose the MODBUS IDA communication protocol, and then select the appropriate protocol based on the actual connection method between the touchscreen and the controller.
The types of devices selected for serial communication and network communication are different; see subsequent explanations for details.
If using a serial port connection:
⊙Device Type: Select Mode MODBUS RTU (Zero-based Addressing)
⊙Interface type: Select the serial port type (RS485 or RS232)
⊙COM: Communication port settings include matching baud rate and other parameters.
At this point, the parameters must be consistent with the parameters of the port connected to the controller. After setting, confirm and close the system parameter setting window.
If using a network port connection:
⊙Device type: Select mode MODBUS TCP/IP (Zero-based Addressing).
The interface type was automatically changed to Ethernet.
⊙IP: Enter the IP address of the controller you want to connect to.
Once the settings are complete, confirm and close the system parameter settings window.
3) After setting the system parameters, compile the written configuration program, connect the touch screen to the PC, and disconnect after the program is downloaded to the touch screen.
Step 3: Connect the touchscreen and the controller. At this point, the touchscreen and the controller can communicate with each other.
If there is no controller or touchscreen, a simulator can be used for simulation. Download the ZDevelop program to the simulator, and when setting the system parameters in the EasyBuilder software, select the device type as MODBUS IDA—MODBUS TCP/IP (Zero-based Addressing), enter the simulator's IP address: 127.0.0.1, and select "Online Simulation" to connect the controller program and the configuration program for simulation.
V. Communication Routines
1. Touchscreen Sample Program
The configuration procedure for Weintek is as follows:
2. Controller-side sample program (basic sample program)
The controller program is divided into five modules:
1) Initialization module: Axis parameter setting, variable definition, button reset.
2) Key scanning module: Press to start, stop, return to zero, save data and trigger the execution of the corresponding program.
3) Motion module: Press the start button to invoke and execute motion commands.
4) Zero Return Module: Pressing the zero return button will trigger the axis to return to zero.
5) Manual motion module: Manually trigger the axis to move in the positive or negative direction.
A. Program task allocation
Automatically run task 0:
If you are setting the mode and variable in the SETCOM parameters for a serial connection...
Clear the motion buffer and initialize each axis.
Initialization of custom variables and reading initialization variables from FLASH memory
Initialization of MODBUS_BIT/REG/IEEE related variables
Start Task 2 as a manual task
Loop scanning program:
B. Program resource allocation
Custom MODBUS_BIT resource:
MODBUS_BIT(0) Start Button
MODBUS_BIT(1) Stop button
MODBUS_BIT(4) Return to Zero Button
MODBUS_BIT(5) Save Data Button
MODBUS_BIT(10) Negative X-axis motion
MODBUS_BIT(11) X-axis positive motion
MODBUS_BIT(20) Negative Y-axis motion
MODBUS_BIT(21) Y-axis positive motion
MODBUS_BIT(1000) X-axis zero-return flag
MODBUS_BIT(1001) Y-axis zero-return flag
Custom MODBUS_REG/LONG/IEEE resources:
MODBUS_REG(0) run_state displays the running status.
MODBUS_IEEE(2) radius displays and sets the machining radius.
MODBUS_IEEE(4) length displays and sets the machining length.
Task Resources:
Task 0: Initialize variables and Task 2, main loop
Continuously scan external variables to run
Task 1: Started from Task 0, the automatic program is used for processing.
Started by Task 0, the zeroing program is used to reset to zero.
Task 2: Initiated by Task 0, used for manual scanning.
Global variable resources used:
run_state (running state)
0 Stop, 1 Run, 2 Return to zero
MODBUS_REG(0) displays
`home_done` is a flag indicating that the home-to-zero process is complete.
0 Not yet returned to zero, 1 Returned to zero
radius MODBUS_IEEE(2) The radius of the machined part.
length MODBUS_IEEE(4) The length of the machined part
Flash resources:
sector 0 radius, length
Read and write data
Axis resources used:
Axis 0: X-axis
Axis 1: Y-axis
VR Resources:
none
Interrupted resources:
none
C. Oscilloscope sampling waveform
Task 1 is started, the automatic processing module is run, and the waveform acquired by the oscilloscope is shown in the following figure:
Curve 0 (red): Target position DPOS(0) on axis 0
Curve 1 (purple): Target position DPOS(1) on axis 1
That concludes our sharing on motion controller and touchscreen communication from ZhengMotion Technology. For more exciting content, please follow our official WeChat account.
This article was originally created by Zheng Motion Assistant. We welcome everyone to reprint it for mutual learning and to improve China's intelligent manufacturing capabilities. Copyright belongs to Zheng Motion Technology. Please indicate the source if you reprint this article.