Differenze tra le versioni di "Ottenere i valori di baud rates del flusso in entrata ed in uscita dei file-device terminali"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "Per ottenere i valori di baud rates del flusso in entrata ed in uscita dei file-device terminali, è possibile utilizzare la funzione ''tcgetattr()'' della libreria dinamica c...") |
|||
(6 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
− | Per ottenere i valori di baud rates del flusso in entrata ed in uscita dei file-device terminali, è possibile utilizzare la funzione | + | Per ottenere i valori di baud rates del flusso in entrata ed in uscita dei file-device terminali, è possibile utilizzare la funzione "tcgetattr()" della libreria dinamica condivisa ''libc.so.6'', che pertanto dovrà essere specificatamente richiamata in Gambas. |
− | |||
Mostriamo un esempio pratico: | Mostriamo un esempio pratico: | ||
Library "libc:6" | Library "libc:6" | ||
− | + | ||
− | ' int tcgetattr (int __fd, struct termios *__termios_p) | + | <FONT Color=gray>' ''int tcgetattr (int __fd, struct termios *__termios_p)'' |
− | ' Put the state of FD into *TERMIOS_P. | + | ' ''Put the state of FD into *TERMIOS_P.''</font> |
− | Private Extern tcgetattr(__fd As Integer, __termios_p As Pointer) As Integer | + | Private Extern tcgetattr(__fd As Integer, __termios_p As Pointer) As Integer |
− | + | ||
− | + | ||
− | Public Sub Main() | + | Public Sub Main() |
− | + | ||
Dim fl As File | Dim fl As File | ||
Dim termios As Pointer | Dim termios As Pointer | ||
Dim baud As New Collection | Dim baud As New Collection | ||
Dim dev As String | Dim dev As String | ||
+ | |||
+ | With baud | ||
+ | .Add(0, "0") | ||
+ | .Add(600, "10") | ||
+ | .Add(1200, "11") | ||
+ | .Add(1800, "12") | ||
+ | .Add(2400, "13") | ||
+ | .Add(4800, "14") | ||
+ | .Add(9600, "15") | ||
+ | .Add(19200, "16") | ||
+ | .Add(38400, "17") | ||
+ | .Add(57600, "10001") | ||
+ | .Add(115200, "10002") | ||
+ | .Add(230400, "10003") | ||
+ | .Add(460800, "10004") | ||
+ | .Add(500000, "10005") | ||
+ | End With | ||
+ | |||
+ | <FONT Color=gray>' ''Verifichamo per esempio il file-device "/dev/tty0"''</font> | ||
+ | dev = "/dev/tty0" | ||
− | + | <FONT Color=gray>' ''Se il file-device è protetto, allora gli attribuiamo i permessi più ampi.'' | |
− | + | ' ''Nella riga di comando seguente si dovrà sostituire la parola "PASSWORD" con la password dell'utente:''</font> | |
− | + | Repeat | |
− | + | Shell "echo <FONT Color=gray>PASSWORD</font> | sudo -S chmod 666 " & dev | |
− | + | Wait 0.01 | |
− | + | Until Access(dev, gb.Read) | |
− | + | ||
− | + | fl = Open dev For Read | |
− | + | ||
− | + | termios = Alloc(SizeOf(gb.Byte), 60) | |
− | + | ||
− | + | <FONT Color=#B22222>tcgetattr</font>(fl.Handle, termios) | |
− | + | Print "\n"; dev; ":\n" | |
− | + | Print "Baud rate in Entrata: ", baud[Int@(termios + 52)];; "baud" | |
− | + | Print "Baud rate in Uscita: ", baud[Int@(termios + 56)];; "baud" | |
− | + | ||
− | + | Free(termios) | |
− | + | fl.Close | |
− | + | ||
− | + | End | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | End | ||
− | |||
=Riferimenti= | =Riferimenti= | ||
− | * | + | * http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap11.html |
+ | * http://www.tldp.org/HOWTO/Text-Terminal-HOWTO-7.html | ||
+ | * http://osr600doc.sco.com/en/SDK_sysprog/CONTENTS.html | ||
+ | * http://www.linux.it/~rubini/docs/pty/pty.html (in particolare il paragrafo: "Cos'è un terminale") | ||
+ | * https://www.debian.org/doc/manuals/debian-reference/ch01.it.html#_device_files |
Versione attuale delle 15:33, 8 giu 2023
Per ottenere i valori di baud rates del flusso in entrata ed in uscita dei file-device terminali, è possibile utilizzare la funzione "tcgetattr()" della libreria dinamica condivisa libc.so.6, che pertanto dovrà essere specificatamente richiamata in Gambas.
Mostriamo un esempio pratico:
Library "libc:6" ' int tcgetattr (int __fd, struct termios *__termios_p) ' Put the state of FD into *TERMIOS_P. Private Extern tcgetattr(__fd As Integer, __termios_p As Pointer) As Integer Public Sub Main() Dim fl As File Dim termios As Pointer Dim baud As New Collection Dim dev As String With baud .Add(0, "0") .Add(600, "10") .Add(1200, "11") .Add(1800, "12") .Add(2400, "13") .Add(4800, "14") .Add(9600, "15") .Add(19200, "16") .Add(38400, "17") .Add(57600, "10001") .Add(115200, "10002") .Add(230400, "10003") .Add(460800, "10004") .Add(500000, "10005") End With ' Verifichamo per esempio il file-device "/dev/tty0" dev = "/dev/tty0" ' Se il file-device è protetto, allora gli attribuiamo i permessi più ampi. ' Nella riga di comando seguente si dovrà sostituire la parola "PASSWORD" con la password dell'utente: Repeat Shell "echo PASSWORD | sudo -S chmod 666 " & dev Wait 0.01 Until Access(dev, gb.Read) fl = Open dev For Read termios = Alloc(SizeOf(gb.Byte), 60) tcgetattr(fl.Handle, termios) Print "\n"; dev; ":\n" Print "Baud rate in Entrata: ", baud[Int@(termios + 52)];; "baud" Print "Baud rate in Uscita: ", baud[Int@(termios + 56)];; "baud" Free(termios) fl.Close End
Riferimenti
- http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap11.html
- http://www.tldp.org/HOWTO/Text-Terminal-HOWTO-7.html
- http://osr600doc.sco.com/en/SDK_sysprog/CONTENTS.html
- http://www.linux.it/~rubini/docs/pty/pty.html (in particolare il paragrafo: "Cos'è un terminale")
- https://www.debian.org/doc/manuals/debian-reference/ch01.it.html#_device_files