DWIN HMI Touch Displays can be used as MODBUS RS485 MASTER.

PYMODSLAVE simulator software is used in this demo as Modbus slave.

Modbus is protocol and RS485 is physical electrical media for data transmission. It is industry standard and can run up to maximum 1000 meters length. Compared to RS232 it is less prone to noise.

In this demo we have 3 background images. Note the naming of images start from 00.jpg.

DWIN Display used here is 5-inch 800 x 480 resolution capacitive touch model. Background images are matched to this resolution. Using ICL tool we first create 32.icl file for background images and save it inside DWIN_SET folder of the project.

In the first image 00.jpg we define some VP address locations for Analog Input and Analog Output values.

The Modbus command to Read Analog Input is 0x04. We define 3 locations as DATA VARIABLES with VP address 2000, 2001 & 2002.

For Reading Holding Registers AO , command is 0x03 and 2 VP address as DATA VARIABLES 2200 & 2201.

To WRITE Single Holding Register AO , command is 0x06 and we use data variable with VP 2500.

A keyboard pop up is used to feed in the value.

For writing to multiple registers , the command is 0x10 and VP address we use 2600, 2601 & 2602 , all contiguous.

For keyboard pop up we use VARIABLE INPUT from Touch Control menu over the Data varibale.

The VP address for Data INput must be same as that of Data Variabel.

For command 0x06 the VP used is 2500.

For command 0x10 VP used is 2600, 2601 & 2602.

Page 3 is 02.jpg and here we have a KEYBOARD .The elements of keyboard are defined using BASIC TOUCH module and respective key code HEX values are provided.For e.g no. 1 hex value is 0x0031, 2 is 0x0032 , etc as given in the note below.

Here is the KEYBOARD pop up configuration.

VP address is same as Data variable.

Data uploading is Enabled. Variable type is INTEGER 8 digits.

Font ID is 0 and font size is set to 20.

Cursor color is set to White. Display method is Direct Display , which means we can see what we type.

Keyboard location is set to OTHER PAGE.

Now click on Keyboard setting. Select the 02.jpg image where we have configured keyboard.

Select the area of display of Keyboard and click OK.

Now you can see the page id as 2 and keyboard area coordinates..

Against Show location click on SET.

Click on any area of image .This is to select the coordinate for left top area of keyboard. click OK.

Now the Show location coordinates are set.

Enable limits is optional. If required you can provide the minimum and maximum values that keyboard can input.

Scroll up to another show location on top and click SET.

Enable the Display Keyboard.

Keyboard is displayed on screen. Now click a dot on the keyboard area where numbers will be displayed.

Save the project.

Under Display , click on Preview from Current page.

You can preview your project. Click on AO 0x06 command location. A keyboard pops up. Feed in some value, which appears at the VP location.

Double click preview window border to close preview.

Same way you can implement keyboard pop up for VP 2600, 2601 & 2602.

Copy and paste the Data input over the new VP and just change the VP address.

Next page is 01.jpg.Here we define VP address locations for slave 3.

To READ DISCRETE Output Coil command is 0x01.

Read Discrete Input Contact 0x02

Write Single Discrete Coil is 0x05. Write Multiple Coils command is not yet implemented in DWIN.

VP address locations to be defined as per BIT AREA 1 and 2 .

As Read and Write Coils are BIT oriented ( 1 AND 0) , DWIN has 2 BIT areas.

AREA 1 is from 0x100 to 0x10F

AREA 2 is from 0x110 TO 0X11F.

And we have to provide the command in 22_Config.bin file atarting location 0x1C000.

The VP address location to be used in config file is as per table below.

For e.g AREA 1 , if we use VP as 0x101 , then we have to use vp as 0010 in config file.

Now in page 2, 01.jpg we will define the VP address locations as per table .

For Reading Discrete Output Coil we use BIT ICONs.

VP address we use from AREA 1 , 0X101.

Under Biticon ON OFF click on SETTING.

Select the BIT POSITION.

FOR FIRST ICON BIT POSITION SELECTED IS 0.

Icon file is selected as 42.icl.

ICON0S and ICON1S are used.

Click on the + symbol.

Select the icon for 0S and then for 1S. (OFF icon and ON icon).

Same way select the bit 1 for next bit icon

Bit 2 for the 3rd , Bit3 for the 4th biticon.VP remains the same 0x101.

For Reading Discrete input contact we use BITICON and now we use VP 0X102 from AREA 1.

Bit settings done for bit 0 and bit 1.

For Writing Single Discrete Coil , we must use VP from AREA 2..

Bit ICON is used and VP we select from AREA 2 as 0X110.

Bit setting is done as 0, 1 and 2 for the 3 Bit icons.

As we have to Write to Slave we implement Incremental Adjustment over these 3 Bit icons for Write Coil.

Incremental ADj VP is same as Bit icon 0x0110.

Respective BIT position is selected as 0, 1 & 2.

Adjustment method is ++.

Overlimit operation is Cycle , Adj step length is 1.

Lower limit 0 and upper limit 1.

Click save project and then GENERATE.

Inside DWIN_SET folder you can see the .bin files generated.

Add 0.HZK file for fonts.

Most important is the OS bin file. From official website download the Kernel files for MODBUS Master.

Download link here

Select the correct bin file.Here we use baud rate 9600 and our 5 inch model supports RS485 at UART5.

So we have copied and pasted the correct OS bin file.

SAS

0.HZK font file can be generated from under the Welcome screen.

The 22_Config file to be copied and pasted outside DWIN_SET folder.This file has to be modified for commands at location starting 0x1C000 and placed back to DWIN_SET folder .Finally this DWIN_SET folder is downloaded to DWIN HMI using SD card method.

To edit 22_Config file , we use PSPAD Hex editor.

http://www.pspad.com/en/download.php

open the 22_Config.bin file with PSPAD Hex editor and go to location 0x1C000

where the Modbus instruction command starts.

The first command is

5A02 0403 5001 0000 2000 0064

D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11

D0 : 5A Execute this Instruction
D1 : SLAVE ID (here it is 02)
D2 : Command 0x01,0x02,0x03,0x04,0x05,0x06,0x10 (04 is used here)
D3: Length of Data in word (03 means 3 word or VP address locations)
D4 : Receive Time out 2 -255 msec ( 50 msec used here)

D5 : Command Execute Mode 00 – 04 ( 01 mode means , next 2 bytes mention the page id)
0x00=Execute unconditionally.
0x01=Execute under the page specified by D6.D7.
0x02=Execute when the key value specified by D6.D7 is non-zero,
and the key value will be cleared after the command is executed.
0X03=In the 0x06 command, when the value of the variable
pointed to by D 8 .D 9 is non-zero, it will be sent automatically.

D6.D7: When D5=00, no configuration is required.
When D5=01, the configuration is page number (0002).
When D5=02, it is configured as the key address for trigger sending.
When D5=03, no configuration is required.
When D5=04, no configuration is required.0

D8.D9: This command operates the source variable address ( VP 2000 used here)
or starting address ( 1000H) allocated in the DGUS screen .
D10.D11: The slave address point table (0x0064 = decimal 100 ) operated by this instruction.
D12.D13.D14.D15: Undefined.

The second instruction is

5A02 0302 5001 0000 2000 006E

5A is start instruction and 02 is SLAVE ID.

03 is command to READ HOLDING Registers , following 02 means 2 words or 2 VP address locations

50 is 50 msec timeout

00 is mode , which means applicable on all pages .Following 2 bytes are 0000 when mode is 00.

2000 is the starting VP address

006E is slave address decimal equal to 110.

Copy this 22_Config.bin file and paste it to DWIN_SET folder.

Already we have stored the correct OS file for 9600 baud UART5 Modbus Master.

Save this DWIN_SET folder to the SD card.Note that maximum 16GB card is supported and it has to be formatted as FAT32 file system and allocation units 4096 bytes.

Plug the SD card on to DWIN and power on.

Blue download screen appears.

When download is completed , remove power and then remove SD card.

Now if you power up DWIN , you can see the project images on screen.

Next we shall connect the display to PC using an USB-RS485 converter. A B pins of DWIN is configured for RS485 communication at baud 9600.

The RS485-USB device used here is built on CP2102 driver.On connecting to PC a COM port is allotted.Here it is COM8 .Note it down.

pyModSlave software is downloaded from link :

https://sourceforge.net/projects/pymodslave/files/latest/download

Open the pyModSlave software .Click options –> Modbus RTU

Set the serial port as COM8 , as that of USB-RS485 and baud rate 9600.

Slave address is set to 2 and Start address 100 (hex 0x064) which is used in the instruction command in 22_Config.bin file.

Click Connect.

Select AI Input Registers & Type in some values at address 100, 101 ,102.

These values appear on the DWIN display at the VP address as per the instruction command.

Now select AO – Holding Registers and type in some values at address 110, 111.

These values appear at DWIN VP locations.

Next is the command instruction to write Holding Registers.

For this , instruction command to be stored in 22_Config.bin file

5A02 0601 5000 0000 2500 0078

5A02 1003 5000 0000 2600 0082

06 is the command to Write Single Holding Register.

10 is the command to Write Multiple Holding Registers.

Include this 22.bin file within DWIN_SET folder and download it to hardware.

From DWIN display touch on the Write single Register VP location. A Keyboard pops up as per design.

Feed in some value.

Same way feed in some values at Multiple Write VP locations.

On PyMod slave select AO Holding Registers.

At decimal address location 120 and 130 you can see the values entered on DWIN.

Next we shall feed in the command instructions for page 2 .We will use SLAVE ID 3.

DD

dd

FF

EE

SS

DD

SS

SS

SS

AA

SS

DD

DD

SS

DD

AA