Software Design and Development

Home > Software Design and Development > Options > Software Developers View of the Hardware > Data Streams

Software Developer’s View of the Hardware: Programming of Hardware Devices.

Outcomes:

H1.1    Explains the interrelationship between hardware and software.
H1.3    Describes how the major components of a computer system store and manipulate data.
H3.2    Constructs software solutions that address legal, social and ethical issues.
H4.1    Identifies needs to which software solutions are appropriate.

Source: Board of Studies NSW (1999) Software Design and Development, Preliminary and HSC Courses. Board of Studies, Sydney

After reading notes describing the structure of data streams in general, you will have exercises in analyzing and designing data streams for specific purposes and exercises involving the development of algorithms relevant to analyzing data streams.

Introductory notes on Data Streams

Processors receive data from various input devices, such as keyboards and sensors, and send data to output devices, such as printers and actuators (motors). Such data is part of a DATA STREAM, which consists of three main sections:

  1. Header information
  2. Data and control characters
  3. Trailer information

Header information typically can include:

The data block typically will include:

Trailer information typically can include:

Device Drivers

Drivers are required to correctly interpret data streams or correctly structure a data stream. They provide the interface between applications and peripheral devices.

For output devices, they are programs that translate the generic commands used by applications (such as word processors) into the commands that specific devices (such as printers) can execute. Printing a page of text would be achieved quite differently using a dot matrix printer or a laser printer.

Similarly, drivers for input devices allow the correct interpretation of the signals sent by the device. For example, a mouse with one button would send a different set of signals than a two-button mouse. A driver is needed for the specific mouse being used.

Go To Top


ACTIVITY 1   Tank

The diagram shows a series of jars on a conveyor belt.

hopper

There are three actuators (motors) to move the conveyor belt, open or close the lower valve and open or close the upper valve.

There are four sensors to detect whether a jar is present, the jar is full, the tank is empty or the tank is full.
The containers are filled with liquid from a large tank.

When a jar is detected by sensor #0, the conveyor belt motor is switched off and valve #1 opens. When sensor #1 detects that the jar is full, valve #1 closes and the conveyor belt motor is switched on.

If sensor #2 detects that the tank is empty, valve #1 closes and valve #2 opens.
If sensor #3 detects that the tank is full, valve #2 closes and, provided there is an unfilled container in place, valve #1 opens.

The system is controlled by a processor that detects the signals from the sensors and sends pulses to the stepper motors. The system continues to operate until it is switched off.

Question 1
The structure of the data stream coming from the sensors is as follows.
One start bit (0)
Two bits to identify the sensor (00 for sensor #0, 01 for sensor #1 etc)
One bit of data ( 1 for container or liquid detected, 0 for no container or no liquid)
One parity bit (using even parity)

What do the following data streams indicate?

  1. 01001
  2. 00110
  3. 01101

ANSWER

Question 2
a) Using a similar structure to that described above, design a data stream for the data sent to the various actuators.
b) Using your data stream structure, show a data stream for closing the lower valve and opening the upper valve.

ANSWER

Question 3
Given below is the mainline of an algorithm to describe the operation of the system.

begin

initialize

turn off conveyor belt motor
close lower valve
close upper valve
JarPresent = false
JarFull = false
TankEmpty = false
TankFull=false

end initialize

while the system is operating

check JarPresent sensor
if JarPresent = false then

GetNextJar

else

turn on conveyor belt motor

end if
open lower valve
FillJar
close lower valve
turn on conveyor belt motor

end while

end

Write appropriate algorithms for the subroutines GetNextJar and FillJar

ANSWER

Go To Top


ACTIVITY 2   Robot Arm

A robot arm is used to pick up and move parcels.

robotarm

For the purposes of this exercise, there are three stepper motors that control the robot arm.
The arm can move left and right.
The arm can move up or down.
The jaw at the end of the arm can open or close.

The data stream to control the robot arm consists of five bytes.
Byte #1 consists of header information. We will ignore its details.
Byte #2 controls left and right movement.
Byte #3 controls up and down.
Byte #4 opens or closes the jaw.
For bytes #2, #3 and #4, the leftmost bit indicates direction (1 for left / up / open, 0 for right / down /  close).
The remaining bits indicate the number of pulses sent to the relevant stepper motor. Each pulse moves the arm or jaw 1 cm.
Byte #5 is a checksum, found by adding all the 1s in the first four bytes.

Question 4
 If the following data streams are sent to the robot arm, what will happen?

  Byte #1 (Header) Byte #2 (left/right) Byte #3 (up/down) Byte #4 (open/close) Byte #5 (checksum)

a)

0111 1110

0000 1111

1000 0000

1010 1000

0000 1110

b)

0111 1110

0000 0000

0011 1100

0000 0000

0000 1010

c)

0111 1110

0000 0000

0000 0000

0001 0100

0000 1010

ANSWER

Question 5
What data stream will open the jaw by 12 cm, while moving the arm 30 cm left and 100 cm up? (use the same header byte as in the examples above.)

ANSWER

Question 6
Write an algorithm that receives the five byte data stream as a string of bits and outputs whether the checksum is correct.

ANSWER

Go To Top


ACTIVITY 3   Dot Matrix Printer

A simple dot matrix printer uses the following codes (shown as hexadecimal numbers) to produce text on a page:
ASCII codes between 20 and 7F produce the appropriate characters.
ASCII codes below 20 are control codes.
ASCII codes above 7F have 80 subtracted from them before they are processed.

The control codes include
0D       Carriage return (without line feed)
09        Line feed (without carriage return)
0F        Form feed (start a new page)
Other codes, such as those for TAB are not included here.

Escape sequences are used to change text characteristics such as style, font and line spacing and for graphics.

To change font:
1B 46 nn          (nn identifies the font )
00 is Courier, 01 is Arial, 02 is Geneva and 03 is Bookman

To change style:
1B 53 nn          (nn identifies the style)
00 is plain, 01 is underlined, 02 is italic and 04 is bold.
Combinations of styles involve adding appropriate numbers.

You will need access to a table of ASCII codes to answer the following questions.

Question 7

What is the effect of the following sequence of bytes sent to a dot matrix printer?
1B 46 01 47 6F 6F 64 09 1B 53 01 44 61 79

ANSWER

Question 8

What sequence of bytes would you need to print the word FAST in Bookman, bold and italic, with the letters below each other on the left of the page, starting on a new page?

F
A
S

T

ANSWER

Question 9

Shown below is the start of an algorithm that analyses a data stream for a dot matrix printer. Complete the algorithm, assuming that the only control codes needed are the ones described above. (If an inappropriate byte appears, an error message is generated.)

begin

while there are more bytes

get next byte
if byte >7F then

byte = byte – 80

end if
casewhere byte is

1B : get next byte

casewhere byte is

46 : get next byte

casewhere byte is

00 : set font to courier

ANSWER

Go To Top



Neals logo | Copyright | Disclaimer | Contact Us | Help