ioctl linux without device control

Sometimes the sequence control device to the device itself is preferably achieved by writing control. For example, this technique is used in driving the console, where a so-called escape sequence is used to move a cursor, change the default colors, or perform other configuration tasks the benefits achieved control device is the user can only control the device by writing data without using (or sometimes write) program to configure the device only established when such a device can be controlled, or even issue commands often need to run the program on the same system and its equipment to be controlled is located.

 

For example, setterm-acting console program (or other terminals) configuration, control program and may be located on a computer different from the printing apparatus is controlled by the escape sequence, as a simple data stream redirection can complete the configuration. this is what happens every time you run a remote tty session: escape sequence is printed but the impact to the local tty at the distal end; however, this technique is not limited to ttys.

 

Drawback is controlled by printing it to the device increases the policy limits; for example, it is only when you are sure that sequence does not appear in the data being written to the device's control during normal operation this is only partially true for ttys despite. a text display means displays only ASCII characters, sometimes control characters can sneak into the data being written, and may, therefore, affect the console For example, this may occur when you display a binary file to the screen;. produce the garbage can contain anything, and finally you often appear in the wrong font on your console.

 

By controlling the writing of course to use, and not for data transmission only in response to a command device, such as a remote device.

 

For example, are you among authors to write a fun drive, move the camera a 2-axis. In this drive in, the "device" is a pair of old-fashioned stepper motor, they can not really read or write. To a stepper motor concept "transmission stream" has no meaning. in this case, the drive to interpret the data being written as ASCII commands and transforms the request to a pulse sequence, to manipulate the stepper motor. the concept is similar, some, you AT commands sent to the cat to establish communications, the main difference is that cats and serial communications must also transfer the actual data. benefits direct device control is that you can use cat to move the camera, without having to write and compile code to issue special ioctl call.

 

When writing command-oriented drivers, there is no reason to implement ioctl commands an interpreter in additional command easier to implement and use.

 

Sometimes, however, you may choose to use other methods: Do not change the write method as an interpreter and avoid ioctl, you may choose to completely avoid writing and special use ioctl command, and the realization driver to use a special command-line tool to send these command to the drive. this method of transferring the complexity from kernel space to user space, there may be easier to process, and helps to maintain the drive pinion, and the cat or rejected using simple echo command.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11141827.html