Transtronics, Inc.
Computer Link Protocol

The computer link protocol is very useful.  Well programmed PLC's are basically meant to dependably run on their own without the need for a more advanced host computer to intervene and tell it what to do. For the Lidar project we had to be able to start the PLC's program and control it over a computer network. Presented here is a crash course along with an example C program designed for the Linux operating system. 

If you want to know more or get further information see the -Computer Link Function- user's manual.  It has helpful  diagrams, tables and technical information. 

Computer link is so easy to that the hardest part is setting up the ports  correctly in software.  The manual has a sample basic program with it. This program is written in GW basic. I couldn't make it work. Some where along the line of computer evolution the ancient language just can't access the new hardware right. I tried the program on 3 pc's and a laptop and the port timed out on all of them. The program won't work in Q basic either. (Qbasic won't even allow the necessary port settings.) However, if you get the manual and your dead set on getting the sample program to work Toshiba assured us that it does work in Intel Basic 52.

The serial RS232 port needs to be set to 9600 baud rate, 1 stop bit, 1 start bit (note in Linux and it seems in other platforms you don't need to explicitly set the start bit), 8 data bits.

Once you have the port set up right though it's smooth sailing. If you're using Linux you are all set just use the C program as a basis for your own project.

ASCII strings

The computer link function works by sending the PLC a string of ASCII characters over a serial port connection that tells the PLC to either change the registers values or to send you back a register's contents or status information.

There are five commands you have to keep in mind

  1. TS test,
  2. ST PLC status read,
  3. ER PLC error status read,
  4. DR data read
  5. DW data write

Let me give you an example of something that you might send to the PLC and what it's output would be.

(A01TS55)
(A01TS55&01)
Note that instead of new line or new line and carriage return you want only a carriage return (that turned out to be my big problem) after the string.

Each command string must start with a '(' and end with a ')' along with a carriage return. The 'A01' specifies the address of the PLC you want to talk to. You set the PLC's address in the Ladder Logic program.  It's possible to control many PLC's on one RS232 port. The PLC will only accept the command string or send something back when it's address is in the string. 

After the address is the actual command, in this case TS (for Test Command). The test command lets you send the PLC a series of characters that it echoes back to you. This is great for testing the PLC to computer link.  The '&' and the numbers after it are a check sum. (A check sum is the simple addition of the string throwing away any carries)  for error checking. It is optional for commands you send to the PLC.

Tests are nice, but the whole point is to read and write to the PLC's registers

(A01DWD0ED,3,0001,0002,0003)

You'll notice that where 'TS' was before we are now requesting a 'DS' (data write). We tell it the first register we want to write to 'D100' and then  the ' 3' tells how many registers we want to write to. The first number 0001 is put into register D0ED and the number 0003 is put in register D0EE and number 0002 is put in register D0ED. If the numbering of the data registers seems confusing that's because  all numbering in the command string has to be done in hexadecimal.

(If you don't know hexadecimal  here is a quick run through: Instead of base ten: 0 1 2 3 4 5 6 7 8 9 you have base sixteen 0 1 2 3 4 5 6 7 8 9 A B C D E F. So, instead of there being nine tens in 90 there would be nine sixteen's in 90, about 54 more. )

The PLC's response is a status message telling us that it didn't find an error with our command and will execute it.

To find out if the values of the registers have actually changed you need to do a data read. Simply replace DW with DR and don't specify any values for the registers (A01DRD100,3) in this case the PLC's output would be (A01DR001002003&33). To give a relay or an input or output an on state give it the value of 0001 and to turn them off give them a value of 0000. However I don't recommend that you directly change the state of the inputs or outputs through the computer link function. There's no need for it in debugging, the T-PDS ladder logic programming software will let you change registers values while the PLC is running for debugging. If in the field you make a mistake while writing to an internal relay or data register then probably, depending on you program, nothing will happen. If you make a mistake while writing to an output you could start turning on machines you don't want on and depending on what you're automating that that can be very dangerous. In the ladder logic have the outputs wired to internal relays or conditional data statements. This may be confusing if you don't keep good notes but this way you can have an output turn on by more than just one condition throughout the ladder logic.

Here is the sample C program under Linux. Even if you're not using Linux it might be a good idea to look through the annotations in the code while I'm setting up the port so you can get an idea of what you need to put in your own program.
 


Sample Function
Header File
 A sample C program to use the PLC computer link function
 

Transtronics, Inc. 3209 W.9th street
Lawrence, KS 66049
USA

Ph
FAX
Email
WEB

(785) 841 3089
(785) 841 3089
inform@xtronics.com
https://xtronics.com
Bookmark this page