Modbus Serv Fnc a575

Embed Size (px)

Citation preview

  • 8/2/2019 Modbus Serv Fnc a575

    1/9

    White PaperUsing the Modbus/TCP PCWorx Server function block

    2008 PHOENIX CONTACT

  • 8/2/2019 Modbus Serv Fnc a575

    2/9

    1

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

    The information given herein is based on data believedto be reliable, but Phoenix Contact makes no warrantiesexpressed or implied as to its accuracy and assumes noliability arising out of its use by others. This publication isnot to be taken as a license to operate under, orrecommendation to infringe, any patent.

  • 8/2/2019 Modbus Serv Fnc a575

    3/9

    2

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

    Using the Modbus/TCP PCWorx Server function block

    Introduction

    The Modbus Client function block allows data (variables) which are being used within a PCWorxprogram to be accessed via Modbus/TCP commands. The information in this document was derived

    through the use of an ILC 150 ETH controller, PCWorx 5.20.17, and the Modbus function block freedownload Pc_worx_5x_Communication_V1_01.zip.This document contains a quick-start procedure forthe basic operation of only the Modbus Server block. To use the function block for Modbuscommunication, the following operations must be performed in the following order:

    Executing the self-extracting zip file, Pc_worx_5x_Communication_V1_01.zip............ Page: 3Compiling the library project, Communication_V1_01.mwt. Page: 3Moving the compiled library to the standard library folder...... Page: 3Creating a PCWorx project.. Page: 3Adding the library to a PCWorx project.. Page: 3Placing the Modbus Server Function Block on the worksheet Page: 4Configuring the block (assigning variables)... Page: 6Reading and writing to the Function Blocks data array.. Page: 7Understanding the Array Memory mapping Page: 8

    It is also suggested that you read the following pdf files, which are included as part of the self-extractingPc_worx_5x_Communication_V1_01.zip file:

    MODBUS_TCP_Client_V1_1x_001.pdfMODBUS_TCP_Server_V1_1x_001.pdf

  • 8/2/2019 Modbus Serv Fnc a575

    4/9

    3

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

    Extracting and Compiling

    1. Locate and download the following communication library:Pc_worx_5x_Communication_V1_01.zip

    2. Extract the self-install Pc_worx_5x_Communication_V1_01.zipfile. By default, it should extractto the following destination folder:

    C:\PCWORX5.x\Libraries\Libraries

    3. Open PCWorx.

    4. Use the File/Open Project option to open the Pc_worx_5x_Communication_V1_01 project.This project should now be located in the default install folder:

    C:\PCWORX5.x\Libraries\LibrariesThe project name is:

    Communication_V1_01.mwtIt will be necessary to compile this library project.

    5. Once the project Communication_V1_01.mwt is loaded into PCWorx, perform a Build/Make.6. Once the project has compiled (made) successfully, perform a File/Save All.

    The Communication_V1_01.mwtproject should now be compiled and saved back into theC:\PCWORX5.x\Libraries\Libraries folder.

    Moving Files and Folders

    For convenience, the Communication_V1_01 library project can be moved to the PCWorx standardlibrary folder. To perform this step, follow the procedure below:

    1. Open PCWorx and click on the Extras (top menu)/Options/Directories (tab).2. Make note of the path to the Library Directory. By default, on an XP system it should be:

    C:\Documents and Settings\All Users\Documents\PCWORX\LibrariesIf the path specified in the Library directory setting differs, use the path specified.

    3. Copy the following files from theC:\PCWORX5.x\Libraries\Libraries\Communication_1.01 to the:

    C:\Documents and Settings\All Users\Documents\PCWORX\Libraries (or specified path).

    Files and folders to copy:Folder: Communications_V1_01File: Communications_V1_01.mwt

    Adding the Library to a Project

    1. Create a project for the controllers being used.2. Once the project has been created, the communication path has been configured, and the bus

    has been configured, do the following: Click on View (top menu bar) / IEC Programming Expand all sub folders in the Project Tree Window (left screen)

    Right click on the Libraries folder and select Insert thenselect User Library Click on the Communications_V1_01.mwt file that was previously moved to thestandard library folder, then click the Include button.

    The Communications_V1_01 file should appear as a sub file to the Libraries folder.

  • 8/2/2019 Modbus Serv Fnc a575

    5/9

    4

    In addition to the Library file, you must also add a firmware library. To do this, perform thefollowing steps:

    Once again, right click on the Libraries folder and select Insert thenselect FirmwareLibrary

    Now open the Bit_Util folder. Click on the Bit_Util.fwl file and then click the Include button.

    In the Project Tree window you should now see the Communications_V1_01 library and theBit_Util libraryshown as sub files to the Libraries folder.

    Placing the Modbus Server Function Block on a worksheet

    1. Click on View (top menu bar) / IEC Programming2. Open the project worksheet located under the Logical_POUs folder.

    (This document does not discuss in detail programming procedures in PCWorx.)3. Place a cross on the worksheet as you normally would do to add an object.4. Locate the Edit Wizard window (window on right of screen by default) and click on the dropdown

    menu from which you normally select function groups.5. Locate and click the Communication_V1_01 group. You should now see all of the MODBUS

    function blocks.6. Double click on the MODBU_TCP_ Server_V1_10 block.

    7. Use the default name for the block: MODBU_TCP_ Server_V1_10_xand click OK on the Variable Properties window.The Server block should now appear in the main program sheet window as follows:

    The block contains six inputs (on left) and six outputs (on right). The MODBUS_Data variable is an in/outarray of words and therefore appears on both the input side and the output side.

    In order to compile (make) and use the block, local or global variables must be assigned to the functionblocks local inputs and outputs. The variable used to gain access to the function block must be of thesame type. Following is a description of each variable associated with the block.

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

  • 8/2/2019 Modbus Serv Fnc a575

    6/9

    5

    Modbus Server FC Variable Descriptions

    Activate (input):Variable type: BOOLSetting this variable to TRUE enables the block. In the enabled state the block is capable ofresponding to the following Modbus/TCP request:

    Quit (input)Variable type: BOOL

    Setting this variable to TRUE clears an error and leaves the block in a disabled mode.For basic operation, this variable can be set to a VAR, initial value = 0.

    AutoQuit (input)Variable type: BOOLSetting this variable to TRUE will cause an error to be acknowledged automatically.It also results in a one cycle presents of diagnostic codes. For basic operation this input can betied to the Error output.

    Port (input)Variable type: INTThis variable can be set to the Ethernet port required. If no initial value is assigned to thisvariable, the function block will set it to 502 by default.

    TimeOut (input)Variable type: TIMEThis is the blocks Watch Dog Timer. After the first Modbus write request, the block must receivean additional Modbus request within the time set here. If a request does not occur within this time,a timeout Error will occur. Setting this variable to an initial value of T#0s will disable it.

    Active (output)Variable type: BOOLThis variable will be set to TRUE by the block when the block becomes enabled.(Activate input = 1)

    Connection (output)Variable type: BOOLThis variable will be set to TRUE when a Modbus client (master) connects to the IP address ofthe controller.

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

  • 8/2/2019 Modbus Serv Fnc a575

    7/9

    6

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

    Error (output)Variable type: BOOLThis variable will be set to TRUE in the event that an error occurs.

    DiagCode (output)Variable type: WORDThis variable will hold an error code after the occurrence of an error.

    AddDiagCode (output)Variable type: WORDThis variable will hold additional information about the error code after the occurrence of an error.

    Input / Outputs

    Modbus_dataVariable type: COM_ARR_W_0_2004This variable is an array of 2005 words. Addressed 0 to 2004. These array cells can be written toor read from using any of the Modbus/TCP commands specified on page three.

    Configuring the Block

    Configuring the block consist of assigning variables to the inputs and outputs of the block.The information in this section is based on a basic single block application. There a number ofalternatives to these suggestions:

    1. Once the Modbus Server FC has been added to the worksheet, the following variables can beassigned to the inputs and outputs. The Usage of the variable; VAR or VAR_GLOBAL, dependson the way in which the block is to be used. The following are only suggestions:

    FC Variable onblock

    NameAssigned(optional)

    Type Usage InitValue

    Usage

    Activate (in) START BOOL VAR 1 The block willalways be enabled

    Quit (in) RS_STOP BOOL VAR 0 Will not be usedAutoQuit (in) Connected to

    the ERRORoutput

    BOOL VAR Will become TRUEon an error

    Port (in) PORT_502 INT VAR 502 by defaultTimeOut (in) Watch_DOG TIME VAR T#0s DisabledActive (out) EN BOOL VAR_GLOBAL Can be connected to

    a discrete out pointConnection(out) CONNECTED BOOL VAR_GLOBAL Can be connected to

    a discrete out pointError (out) ERROR BOOL VAR Linked to the

    AutoQuitDiagCode DIAG WORD VAR_GLOBAL Can be displayed

    AddDiagCode DIAG_EXT WORD VAR_GLOBAL Can be displayedMODBUS_Data MB_data See

    page :4

    VAR_GLOBAL Can be accessedwith Modbus

    Table T-1

  • 8/2/2019 Modbus Serv Fnc a575

    8/9

    7

    2. Once all the variables have been assigned, a compile (make) should be performed to confirm thatthe variables were added correctly.

    Reading and Writing

    Below is an explanation of how a Modbus read and a Modbus write can be performed. This exampleassumes that the variable names in the previous table (T-1) are being used:

    Placing data in the MODBUS_Data array:

    In table T-1, the MODBUS_Data array was given the variable name MB_data. This caused a variablearray with the name MB_data to be created in the image of COM_ARR_W_0_2004. If an array celladdress is used as the name of a variable, data written to that variable will be placed in the celladdressed by the variable name. The cells of the MB_data array can now be accessed as follows:

    MB_data[0] = cell 0MB_data[1] = cell 1MB_data[n] = cell etc.

    The example below shows a MOVE command being used to move an integer (7) into the function blocks

    data array. Any data place in variable REG_0004 will be moved to cell [4] of the MB_data array. This datawill now be available for a Modbus read. This data will be located at Modbus holding register 40004because it has been placed in cell [4] of the array.

    MOVE

    Name: REG_0004_

    D_type: WORD_

    Usage: VAR_GLOBAL

    Init Val: 7

    Name: MB_data[4]

    Variable Properties Variable Properties

    In the example below, the data located in cell address of MB_data[6] is being moved to the variableWritten_data. If a Modbus write command is used to write data to holding register 40006, that data canthen be accessed via local variable Written_data.

    MOVE

    Name: Written_data

    D_type: WORD_

    Name: MB_data[6]

    Variable Properties Variable Properties

    Usage: VAR

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

  • 8/2/2019 Modbus Serv Fnc a575

    9/9

    8

    PHOENIX CONTACT P.O. Box 4100 Harrisburg, PA 17111-0001717-944-1300 Fax: 717-944-1625 e-mail: [email protected] www.phoenixcon.com

    2008 PHOENIX CONTACT

    Paper Title: Using the Modbus/TCP PCWorx Server function blockRev 1.00

    ow the Data Array is MappedH

    the preceding example an array variable called MB_data was created. This variable is of the type

    oil status

    Modbus command 03, read multiple registers of address 0 were performed for these three elements,

    7 (HEX) cell MB_data[0]

    a Modbus command 01, read single coil of address 0 were performed, it would return the LSB of cell

    ommand 01, read single coil of address 16 were performed, it would return the LSB of cell

    mmand 01, read single coil of address 36 were performed, it would return the fifth bit of cell

    herefore it is up to the user to organize or manage this memory array as to their own needs.

    InCOM_ARR_W_0_2004. Therefore, MB_data is an array with 2005 elements. The elements areaddressed MB_data[0] to MB_data[2004]. Modbus holding register reads and writes as well as Csets and clears all communicate to this same area of memory. The diagram below depicts 3 elements ofthe MB_data array.

    Ifthe three values read would be:

    15 (HEX) cell MB_data[1]10 (HEX) cell MB_data[2]

    IfMB_data[0].If a Modbus cMB_data[1].If a Modbus co

    MB_data[2].

    T

    MB_data[0]

    MB_data[1]

    MB_data[2]

    0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1

    0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0

    0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1

    Coil read of address 0 = 1Coil read of address 16 = 1

    Coil read of address 36 =