3 Ekim 2017 Salı

termios yapısı

termios yapısı
POSIX seri port API'sinde (örneğin RS232) herşey termios yapısı etrafında döner. Yapı şöyle
struct termios {
  tcflag_t    c_iflag;    /* input flags */
  tcflag_t    c_oflag;    /* output flags */
  tcflag_t    c_cflag;    /* control flags */
  tcflag_t    c_lflag;    /* local flags */
  cc_t        c_cc[NCCS]; /* control chars */
  speed_t     c_ispeed;   /* input speed */
  speed_t     c_ospeed;   /* output speed */
};
Linux'ta Posix standardından daha fazla bir çok bayrak var.

canonical kullanım
Şöyle yaparız.
newtio.c_cflag |= CLOCAL | CREAD;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;         /* 8-bit characters */
newtio.c_cflag &= ~PARENB;     /* no parity bit */
newtio.c_cflag &= ~CSTOPB;     /* only need 1 stop bit */
newtio.c_cflag &= ~CRTSCTS;    /* no hardware flowcontrol */

newtio.c_lflag |= ICANON | ISIG;  /* canonical input */
newtio.c_lflag &= ~(ECHO | ECHOE | ECHONL | IEXTEN);

newtio.c_iflag &= ~INPCK;
newtio.c_iflag |= ICRNL;
newtio.c_iflag &= ~(INLCR | IGNCR | IUCLC | IMAXBEL);
newtio.c_iflag &= ~(IXON | IXOFF | IXANY);   /* no SW flowcontrol */

newtio.c_oflag &= ~OPOST;

c_cflag Alanı
Kontrol bayrakları içindir. Posix şu bayrakları tanımlar.

CSIZE Bayrağı: Bir karakter büyüklüğünü tanımlar. 5,6,7,8 bit olabilir. 5 ve 6 bit veri büyüklükleri çok eskiden kullanılırdı.
CSTOPB Bayrağı: İki veya bir stop biti kullanır. Açıklaması şöyle. Tüm veri alındıktan sonra start bit'in tekrar gözlemlenmesi için ne kadar süre geçmesi gerektiğini belirtir.
With this kind of communication, both the sender and receiver have to agree ahead of time on a few parameters. The two key parameters here are the baud rate and the number of data bits.

The line starts out in the idle level. The transmitter first sends the start bit, which is at the opposite level. It then sends the data bits, followed by the stop bit.

Unlike what others have said, the stop bit is not a checksum. It is required so that there is always a transition at the leading edge of the start bit. Otherwise, if the last data bit ov the previous character happened to be of the same polarity as a start bit, the receiver wouldn't be able to see the start bit if a new character was sent immediately. The stop bit is essentially enforced line idle time between characters. That time is also used to absorb some clock mismatch between the sender and receiver.

When idle, the receiver monitors the line looking for it to change to the non-idle state. When that happens, it starts a stopwatch. Since it is configured for the same bit rate as the transmitter, it knows when each data bit is sent, whether it differs from a previous bit or not. The middle of the first data bit is at 1½ bit times from the leading edge of the start bit. The second at 2½ bit times, etc.

After the last data bit is received, the receiver waits for the line to go back to the idle state, then waits for the next start bit again.
Start Bit Gelince
1.5 cycle beklenir ve sonra okuma işlemi başlar. Açıklaması şöyle
The start bit is used to trigger the read cycle in the receiver. The receiver synchronises itself on the start bit and then waits 1.5 cycles to start sampling bits. Thereafter the bits are sampled at the baud rate. This initial delay means that even with a 5% clock error the receiver should still be within the bit timing for the last bit.

CREAD : Açıklama yaz
PARENB : Parity kontrolünü etkinleştirir.
PARODD : Parity etkinse odd veya even olabilir.
HUPCL : Açıklama yaz
CLOCAL : Açıklama yaz

8N1 8 bit data, No Parity, 1 Stop bit anlamına gelir.

c_oflag alanları
Raw Output
Açıklaması şöyle. Text Editor tarzı işlerde kullanılır
Up next is understanding how to set your terminal into "raw mode." By default, your terminal processes text line-by-line, echoing every character that we type and much more. We don't want all of that. However, to enter raw mode, we'll need to learn about native Unix APIs and how to access them with Java.

One such API is the Termios API. It effectively lets you set your terminal into raw mode; hence, I'll show you how to use JNA to access the Termios API — and do a fair amount of bit-wise ANDs to get your terminal into the right mode.

With ANSI escape codes and terminal raw mode knowledge under our belts, we can finally create our terminal editor skeleton. When we start the editor, we want to see a clear screen. In addition, all empty rows should start with a "~" sign, and we should also have a nice little status bar at the bottom of the screen — time for implementation!
Şöyle yaparız
port_settings.c_oflag &= ~OPOST; //enable raw output 
cfmakeraw yazısına da bakılabilir.

Hiç yorum yok:

Yorum Gönder