Zum Inhalt springen

Benutzer:Dirk Huenniger/devices

Aus Wikibooks

This is my little page on device control

What is device control

[Bearbeiten]

Think of a personal computer that is connected with to various machines via varous means of IO. Those machnies are able to manufacture various kinds of productions depending on the way they are operated. The question this wiki is about is: "How to program that computer"

Requirements

[Bearbeiten]
  • It must be possible to write a script that controls the operation of the devices.
  • A user must be able to control the devices directly in a graphical user interface.
  • The user does not need to be at the same location as the computer controlling the devices.

Model of the devices

[Bearbeiten]

We need to find a model of our devices that we can program in a computer.

Reading and writing

[Bearbeiten]

On operating system level we usually have got the following methods to interact with the devices.

  • We can ask if some kind of information was received from a device
  • We can install a callback that is called when information is received from a device
  • We can write data to the device.

There are three way of writing.

  • We can write an wait until the process of writing is completed.
  • We can install a callback that is called when the device is ready for writing so that we likely won't need to wait for long until our write completes
  • We can write and install a callback that is called when the process of writing has finished

You see there are many alternatives to pick from.

Example devices

[Bearbeiten]

Think of the thermometer and a stepper motor as examples of our devices. The purpose of the thermomenter is to provide us with a value, the temperature. The provided value will usually be a positive integer that gives the temperature in units specific to our device. And we will have to process it further to get the actual physical temperature which we will represent as a floating point number. The stepped Motor will take the number of steps to go forward or backward, so a signed integer number. It will not necessarily be able to tell its current position, and for now we will assume it can not. The length in steps that the stepper Motor accepts will usually need to be converted from a physical unit usually Meters.

Of course there are also problems that can arise using out devices. The stepper motor may reach its limiting position so not be able to move in one particular direction anymore. We might have to handle a request to put the stepper motor in a position which can not be reached by an integer number of steps. The Thermometer will have limiting temperatures, and out of that range it will not be able to measure the temperature anymore.

Here we also see that there are many different cases to handle, and many decisions to take.

Procedural Model

[Bearbeiten]

Often we try to look at a device as a set of procedures. A thermometer has the ability to give us the current temperature. So you can model it by giving it a method called

double getTemperature()

A stepper motor might be able to move forward by various steps. So you can model it as a method

void moveMotor(int steps)