Industrial Automation
Industrial Automation | Europe

myKnowledge

Main > Product Type > Software
Minimize Text   Default    Enlarge Text
 

Print
E-mail

Sample Programs for Host Link Commands


Introduction
This tutorial gives an introduction to Host Link and a sample program to demonstrate the protocol. The sample program has been written to be used in conjunction with the manuals (see reference section below for applicable manuals) to give an insight into what is involved for those wishing to write their own program to communicate with the Host Link protocol.
 
As the name implies, Host Link (referred hereafter as HL) allows a host device to communicate with OMRON equipment supporting the protocol. This includes all C and CV series PLCs and NT series of MMIs (Man Machine Interfaces).Some temperature controllers support a version of HL with a different set of commands, although the basic principle remains the same. With HL there is always one master (the Host) with between 1 and 32 slaves. The master can be a PC running CX-Programmer (CX-Programmer uses HL commands to up and download programs, monitor bits and words, etc.) or a SCADA package or an NT display. Note that although an NT display is a master it can only communicate with 1 slave in Host Link mode.

Examples of Host Link connections.



Host Link Command Format

The HL protocol is quite simple to use. The host sends a command block to which the receiving unit will reply with a response block. Each block takes the following format:



The unit number indicates to which unit the command is to/from and the header code specifies what type of command this is (for a command block) or a response error code (for a response block). FCS is the Frame Check Sum and is generated by XORing all the bytes of the FCS calculation range. The block is finished with the terminator - an asterisk followed by the carriage return character.

Host Link Commands

There are more than 40 HL commands to perform operations such as read/write bit status and word value, timer counter value and status and program read and write. The following sample program demonstrates the use of the RD command to read 10 consecutive data memories from a PLC. The program will work with any C series PLC (C20, C?K, C?H, CQM1, C200H/S, C500, C1000H, C2000H) and CV series PLCs in C mode. The program is written for QBASIC which is supplied with DOS version 6 upwards. To see the results simply connect COM1 of a PC to a Host Link Unit or PLC RS232 port, as you would with LSS for example, and run the program. For a complete list of available commands see any of the manuals listed below.

Manual References
  • Host Link manual for C-series PLCs: W143
  • Host Link manual for C20 and C?K: W182
  • Host Link Commands with the CQM1: W228 Section 6
  • Host Link Commands with the C200HS: W235 Section 11
  • Host Link Commands with the CV-Series: W205

Example

 

QBASIC program to communicate with OMRON PLC via a host link command.

The program simply sends a string to the PLC requesting the contents of DM0000 to DM0009. The PLC responds by sending back a string with the required information. Normally, it would be necessary to check the FCS of the received string to ensure that no data corruption has occurred. This has been omitted for the purpose of this example.

Start:

OPEN "COM2:96000,E,7,2,CD0,DS0" FOR RANDOM AS #1 'Open PC comms.port.

tx$="@00RD00000010"              'Set up command string,

GOSUB CalcFCS                       'work out frame check sum

tx$=tx$ + fcs$ + "*"                 'and put it at the end.

PRINT#1, tx$                            'Send string to PLC

INPUT#1, rx$                            'and wait for a response.

PRINT "Transmitted string was '";tx$;""    'Display the results.

PRINT "Received string was  '";rx$;""

FOR counter = 1 TO 10

PRINT "DM"; counter; "=";

PRINT MID$(rx$,(counter * 4 + 4),4)

NEXT

END

'-------------------------------------------------------------------------------

'Subroutine to calculate the frame check sum

CalcFCS:

length=LEN(tx$)

fcsnum=0

FOR counter=1 TO length

fcs$=MID$(tx$, counter, 1)

fcsnum=ASC(fcs$)XOR fcsnum

NEXT

fcs$=HEX$(fcsnum)

IF LEN(fcs$)=1 THEN fcs$="0" + fcs$

RETURN




Comments (View All Comments / Add Comment)

Related Articles
No related articles found.
Created 2008-10-13
Modified 2009-04-30
Views 25812

 

You are not logged in.