Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Jack H.Integration and automation of manufacturing systems.2001.pdf
Скачиваний:
86
Добавлен:
23.08.2013
Размер:
3.84 Mб
Скачать

page 129

serial = new serial_io("B9600,F/dev/ttyS0"); while(flag == 0){

if(serial->reader(in, 100) != ERROR){ if(strlen(in) > 0){

printf("Got String: %s", in); sprintf(out, "ECHO: %s\n", in); printf("Sending String: %s", out); serial->writer(out);

}

}

}

delete serial;

}

Figure X.12 - A Serial Communication Program (serial.c)

These programs can be compiled with the makefile in Figure X.13.

all:

serial

CC=g++

 

CFLAGS=

 

serial:

serial.c serial_io.o

 

$(CC) $(CFLAGS) serial.c -o serial serial_io.o

serial_io.o:

serial_io.c serial_io.h

 

$(CC) $(CFLAGS) -c serial_io.c

Figure X.13 - A Makefile

6.3 PARALLEL COMMUNICATIONS

Parallel data transmission will transmit multiple bits at the same time over multiple wires. This does allow faster data transmission rates, but the connectors and cables become much larger, more expensive and less flexible. These interfaces still use handshaking to control data flow.

These interfaces are common for computer printer cables and short interface cables, but they are uncommon on PLCs. A list of common interfaces follows.

Centronics printer interface - These are the common printer interface used on most personal computers. It was made popular by the now defunct Centronics printer company.

page 130

GPIB/IEEE-488 - (General Purpose Instruments Bus) This bus was developed by Hewlett Packard Inc. for connecting instruments. It is still available as an option on many new instruments.

6.4 LABORATORY - SERIAL INTERFACING AND PROGRAMMING

Purpose:

To achieve a basic understanding of the serial communication hardware and software.

Overview:

Please review the chapter

Pre-Lab:

1. Enter the C++ code found in the chapter.

In-Lab:

1.Set up two computers beside each other, at least one should be a Linux computer.

2.Select the right connectors for the serial ports (9 or 25 pin, and male or female) on the computers and build a null modem RS-232 cable to connect the two computers.

3.Start a serial communication program on both of the computers, and establish communications - this will require you to change communication settings.

3a. (Linux) You may use ’minicom’, you will have to be logged in as root, or change the settings for the serial port with ’chmod 666 /dev/ttyS0’ or ’chmod 666 /dev/ttyS1’.

3b. (Windows) Use the hyperterm program ’hypertrm.exe’. When prompted for connection information select ’cancel’.

4.Enter and run the C++ program to echo serial data.

5.Modify the number guess game developed in a previous lab to operate over the serial port.

Submit (individually):

1. The source code listings for the game running on the serial port.

6.5 LABORATORY - STEPPER MOTOR CONTROLLER

Purpose:

To use a serial interface to communicate with a stepper motor controller.

Overview:

page 131

A stepper motor is unlike other motors. When a voltage is applied the motor does not turn continuously, it only moves a small increment. There are normally a set of four or more inputs. When these are turned on-off in a set pattern the motor shaft will rotate forward or backwards. A typical stepper motor might have 200 steps per revolution, or steps of 1.8 degrees. These motors often require somewhat sophisticated controllers. One type of controller is called an indexer. It can be given commands to move the motor, and then it takes care of pulsing the motor outputs to drive the motion.

The stepper motor controllers to be used in this laboratory are integrated into the turntables in the material handling system. The controller is integrated into the turntable stations so that it can rotate the turntable up to 360 degrees with a stepped motor, eject a cart using two outputs to solenoid valves, and detect a cart present with a diffuse photoelectric sensor. The controller has an RS-422 port that can be used to communicate, and load programs. This will be connected to an RS-232C port using a special interface cable that converts the current loop to voltage values. The communication settings for the turntables are 9600 baud, 8 data bits, no parity, 1 stop bits, no flow control.

The programming commands for the controller are summarized below.

DCB-241 Commands

 

<ESC> abort

G go from address

@ soft stop

I initial velocity

<CTL>C reset

K ramp slope

+ move in positive direction

L loop on port

- move in negative direction

M move at constant speed

[ read nonvolatile memory

O set origin

] read hardware limits

P program mode

\ write to nonvolatile memory

Q query program

^ read moving status

R index to target position

A port read/write

S store parameters

B jog speed

T set trip point

C restore

V slew velocity

D divide step rates

W wait

E enable auto power off

X examine parameters

F find home

Z display position

Figure X.14 - Stepper Motor Control Board Commands (DCB-241)

When writing programs command lines can be up to 15 characters long, including spaces. Spaces are used to separate commands and arguments. Characters used in programs can be either upper or lower case. A sample program is given below.

page 132

Pre-Lab:

1. Go to the web site www.stepcontrol.com and look at the product documents for the DCB-241 stepper driver.

In-Lab:

1.Use a terminal program to communicate with the stepper motor controller. You will need a special communication cable, and the boxes can be opened with a flat bladed screwdriver. Plug the communication cable into the lower connector. (Note: if the unit already has power don’t touch the exposed 120Vac power on the power supply.) Connect an air supply and power to the unit. (Note: don’t forget to turn on the power on the front of the cabinet.)

2.Use the following commands (in sequence) to verify that the turntable is operating properly, and to explore basic commands. (Note: comments are provided for understanding, but should not be entered into the controller.)

<CTRL>C -- this should reset the unit

<SPACE> -- this should print out the line ’V2.03’, if not there are problems <ENTER> -- this should print ’#’

Z -- read the current position

O -- set the current position as the origin Z -- print the current position

R1000 -- this should rotate the turntable Z -- should now be 1000

R-1000 -- this should rotate the turntable the other way Z -- should be zero again

A8 - kicks the cart one way (notice the lights on the solenoids) A16 - kicks the cart the other way

A0 - turns off all solenoids

] -- this will check the input ports, bits 7 and 8 are for the cart present detectors

3.Enter the following program so that the turntable operates automatically. The list below also includes the commands to download and enter the program. Again comments should not be entered, and line numbers are automatically generated. When the program has been entered it can be run with the command ’G0’.

P0 -- put the controller in programming mode and start the program at location ’0’ 0 O0 -- set the current position to the origin with a value of 0

4 R10000 -- more the controller 10000 steps in the positive direction 8 W0 -- wait until ’0’ ms after the motion is complete

11 R-10000 -- move 10000 steps in the opposite direction 15 W100 -- wait until ’100’ ms after the motion is complete

18 J 4 3 -- jump to address ’4’ four (3+1) times, a basic for loop (you may need to change ’4’ if your line numbers don’t match)

22 A8 -- eject the cart

24 W1000 - wait for 1 second

27 A0 - shut off the solenoid valve

29 P0 -- the end of the program

4.Write a C++ program to communicate with the stepper motor controller over RS-232. It

page 133

should allow the user to enter a motor position from the keyboard, and the controller should automatically move.

Submit (individually):

1. The source code listings for the motor control program.