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...")
 
Riga 5: Riga 5:
 
  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
Riga 17: Riga 17:
 
   Dim dev As String
 
   Dim dev As String
 
    
 
    
    With baud
+
  With baud
      .Add(0, "0")
+
    .Add(0, "0")
      .Add(600, "10")
+
    .Add(600, "10")
      .Add(1200, "11")
+
    .Add(1200, "11")
      .Add(1800, "12")
+
    .Add(1800, "12")
      .Add(2400, "13")
+
    .Add(2400, "13")
      .Add(4800, "14")
+
    .Add(4800, "14")
      .Add(9600, "15")
+
    .Add(9600, "15")
      .Add(19200, "16")
+
    .Add(19200, "16")
      .Add(38400, "17")
+
    .Add(38400, "17")
      .Add(57600, "10001")
+
    .Add(57600, "10001")
      .Add(115200, "10002")
+
    .Add(115200, "10002")
      .Add(230400, "10003")
+
    .Add(230400, "10003")
      .Add(460800, "10004")
+
    .Add(460800, "10004")
      .Add(500000, "10005")
+
    .Add(500000, "10005")
    End With
+
  End With
 
      
 
      
    dev = "/dev/tty0"
+
  dev = "/dev/tty0"
 
+
 
    If Access(dev, gb.Read) = False Then Shell "echo ploppo | sudo -S chmod 666 " & dev Wait
+
  If Access(dev, gb.Read) = False Then Shell "echo <FONT Color=gray>PASSWORD</font> | sudo -S chmod 666 " & dev Wait
 
+
 
    fl = Open dev For Read
+
  fl = Open dev For Read
 
      
 
      
    termios = Alloc(60)
+
  termios = Alloc(60)
 
+
 
    tcgetattr(fl.Handle, termios)
+
  tcgetattr(fl.Handle, termios)
    Print "\n"; dev; ":\n"
+
  Print "\n"; dev; ":\n"
    Print "Baud rate in Entrata: ", baud[Int@(termios + 52)];; "baud"
+
  Print "Baud rate in Entrata: ", baud[Int@(termios + 52)];; "baud"
    Print "Baud rate in Uscita:  ", baud[Int@(termios + 56)];; "baud"
+
  Print "Baud rate in Uscita:  ", baud[Int@(termios + 56)];; "baud"
+
 
    Free(termios)
+
  Free(termios)
    fl.Close
+
  fl.Close
 
+
 
End
+
'''End'''
  
  
Riga 57: Riga 57:
 
=Riferimenti=
 
=Riferimenti=
 
*
 
*
 +
* http://osr600doc.sco.com/en/SDK_sysprog/CONTENTS.html

Versione delle 21:59, 30 ott 2015

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.6.so, 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
   
  dev = "/dev/tty0"
  
  If Access(dev, gb.Read) = False Then Shell "echo PASSWORD | sudo -S chmod 666 " & dev Wait
  
  fl = Open dev For Read
   
  termios = Alloc(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