本文整理匯總了Golang中syscall.Termios類的典型用法代碼示例。如果您正苦於以下問題:Golang Termios類的具體用法?Golang Termios怎麽用?Golang Termios使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Termios類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setTermSettingsCtsRts
func setTermSettingsCtsRts(enable bool, settings *syscall.Termios) {
if enable {
settings.Cflag |= termiosMask(tcCRTSCTS)
} else {
settings.Cflag &= ^termiosMask(tcCRTSCTS)
}
}
示例2: Configure
// Configure configures f as a 8N1 serial port with the specified baudrate.
func Configure(f fder, baudrate uint32) error {
var termios syscall.Termios
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(f.Fd()), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios))); err != 0 {
return err
}
termios.Ispeed = baudrate
termios.Ospeed = baudrate
termios.Cflag &^= CBAUD
termios.Cflag &^= CBAUDEX
termios.Cflag |= baudrate
// set 8N1
termios.Cflag &^= syscall.PARENB
termios.Cflag &^= syscall.CSTOPB
termios.Cflag &^= syscall.CSIZE
termios.Cflag |= syscall.CS8
// Local connection, no modem control
termios.Cflag |= (syscall.CLOCAL | syscall.CREAD)
// Disable hardware flow control
termios.Cflag &^= CRTSCTS
// Block on a zero read (instead of returning EOF)
termios.Cc[syscall.VMIN] = 1
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(f.Fd()), syscall.TCSETS, uintptr(unsafe.Pointer(&termios))); err != 0 {
return err
}
return nil
}
示例3: Set
func (l *lflagSetter) Set(pty *os.File, termios *syscall.Termios, value uint32) error {
if value == 0 {
termios.Lflag &^= l.Flag
} else {
termios.Lflag |= l.Flag
}
return SetAttr(pty, termios)
}
示例4: Set
func (i *iflagSetter) Set(pty *os.File, termios *syscall.Termios, value uint32) error {
if value == 0 {
termios.Iflag &^= i.Flag
} else {
termios.Iflag |= i.Flag
}
return TcSetAttr(pty, termios)
}
示例5: setTermSettingsDataBits
func setTermSettingsDataBits(bits int, settings *syscall.Termios) error {
databits, ok := databitsMap[bits]
if !ok {
return &SerialPortError{code: ERROR_INVALID_PORT_DATA_BITS}
}
settings.Cflag &= ^termiosMask(syscall.CSIZE)
settings.Cflag |= termiosMask(databits)
return nil
}
示例6: Cfmakeraw
// Cfmakeraw modifies attr for raw mode.
func Cfmakeraw(attr *syscall.Termios) {
attr.Iflag &^= syscall.BRKINT | syscall.ICRNL | syscall.INPCK | syscall.ISTRIP | syscall.IXON
attr.Oflag &^= syscall.OPOST
attr.Cflag &^= syscall.CSIZE | syscall.PARENB
attr.Cflag |= syscall.CS8
attr.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG
attr.Cc[syscall.VMIN] = 1
attr.Cc[syscall.VTIME] = 0
}
示例7: setTermSettingsDataBits
func setTermSettingsDataBits(bits int, settings *syscall.Termios) error {
databits, ok := databitsMap[bits]
if !ok {
return &PortError{code: InvalidDataBits}
}
settings.Cflag &= ^termiosMask(syscall.CSIZE)
settings.Cflag |= termiosMask(databits)
return nil
}
示例8: rawModeTerm
// returns non-canonical mode term for keybind
func rawModeTerm(term syscall.Termios) syscall.Termios {
term.Iflag &= syscall.IGNCR // ignore received CR
term.Lflag ^= syscall.ICANON // disable canonical mode
term.Lflag ^= syscall.ECHO // disable echo of input
term.Lflag ^= syscall.ISIG // disable signal
term.Cc[syscall.VMIN] = 1 // number of bytes to read()
term.Cc[syscall.VTIME] = 0 // timeout of read()
return term
}
示例9: setTermSettingsStopBits
func setTermSettingsStopBits(bits StopBits, settings *syscall.Termios) error {
switch bits {
case OneStopBit:
settings.Cflag &= ^termiosMask(syscall.CSTOPB)
case OnePointFiveStopBits, TwoStopBits:
settings.Cflag |= termiosMask(syscall.CSTOPB)
}
return nil
}
示例10: setTermSettingsStopBits
func setTermSettingsStopBits(bits StopBits, settings *syscall.Termios) error {
switch bits {
case STOPBITS_ONE:
settings.Cflag &= ^termiosMask(syscall.CSTOPB)
case STOPBITS_ONEPOINTFIVE, STOPBITS_TWO:
settings.Cflag |= termiosMask(syscall.CSTOPB)
}
return nil
}
示例11: disableEcho
// disableEcho disables terminal echoing, which simplifies parsing by
// not having our inputs mixed into it.
func (b *Bash) disableEcho() error {
var termios syscall.Termios
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
b.pty.Fd(), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)))
if errno != 0 {
return errno
}
termios.Lflag &^= syscall.ECHO
_, _, errno = syscall.Syscall(syscall.SYS_IOCTL,
b.pty.Fd(), uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&termios)))
if errno != 0 {
return errno
}
return nil
}
示例12: setRawMode
func setRawMode(settings *syscall.Termios) {
// Set local mode
settings.Cflag |= termiosMask(syscall.CREAD | syscall.CLOCAL)
// Set raw mode
settings.Lflag &= ^termiosMask(syscall.ICANON | syscall.ECHO | syscall.ECHOE | syscall.ECHOK |
syscall.ECHONL | syscall.ECHOCTL | syscall.ECHOPRT | syscall.ECHOKE | syscall.ISIG | syscall.IEXTEN)
settings.Iflag &= ^termiosMask(syscall.IXON | syscall.IXOFF | syscall.IXANY | syscall.INPCK |
syscall.IGNPAR | syscall.PARMRK | syscall.ISTRIP | syscall.IGNBRK | syscall.BRKINT | syscall.INLCR |
syscall.IGNCR | syscall.ICRNL | tcIUCLC)
settings.Oflag &= ^termiosMask(syscall.OPOST)
// Block reads until at least one char is available (no timeout)
settings.Cc[syscall.VMIN] = 1
settings.Cc[syscall.VTIME] = 0
}
示例13: setTermSettingsBaudrate
func setTermSettingsBaudrate(speed int, settings *syscall.Termios) error {
baudrate, ok := baudrateMap[speed]
if !ok {
return &PortError{code: InvalidSpeed}
}
// revert old baudrate
var BAUDMASK uint
for _, rate := range baudrateMap {
BAUDMASK |= rate
}
settings.Cflag &= ^termiosMask(BAUDMASK)
// set new baudrate
settings.Cflag |= termiosMask(baudrate)
settings.Ispeed = termiosMask(baudrate)
settings.Ospeed = termiosMask(baudrate)
return nil
}
示例14: saneTerminal
// saneTerminal sets the necessary tty_ioctl(4)s to ensure that a pty pair
// created by us acts normally. In particular, a not-very-well-known default of
// Linux unix98 ptys is that they have +onlcr by default. While this isn't a
// problem for terminal emulators, because we relay data from the terminal we
// also relay that funky line discipline.
func saneTerminal(terminal *os.File) error {
// Go doesn't have a wrapper for any of the termios ioctls.
var termios syscall.Termios
if err := ioctl(terminal.Fd(), syscall.TCGETS, uintptr(unsafe.Pointer(&termios))); err != nil {
return fmt.Errorf("ioctl(tty, tcgets): %s", err.Error())
}
// Set -onlcr so we don't have to deal with \r.
termios.Oflag &^= syscall.ONLCR
if err := ioctl(terminal.Fd(), syscall.TCSETS, uintptr(unsafe.Pointer(&termios))); err != nil {
return fmt.Errorf("ioctl(tty, tcsets): %s", err.Error())
}
return nil
}
示例15: setTermSettingsBaudrate
func setTermSettingsBaudrate(speed int, settings *syscall.Termios) error {
baudrate, ok := baudrateMap[speed]
if !ok {
return &SerialPortError{code: ERROR_INVALID_PORT_SPEED}
}
// revert old baudrate
BAUDMASK := 0
for _, rate := range baudrateMap {
BAUDMASK |= rate
}
settings.Cflag &= ^termiosMask(BAUDMASK)
// set new baudrate
settings.Cflag |= termiosMask(baudrate)
settings.Ispeed = termiosMask(baudrate)
settings.Ospeed = termiosMask(baudrate)
return nil
}