本文整理匯總了Golang中syscall.Termios.Cflag方法的典型用法代碼示例。如果您正苦於以下問題:Golang Termios.Cflag方法的具體用法?Golang Termios.Cflag怎麽用?Golang Termios.Cflag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類syscall.Termios
的用法示例。
在下文中一共展示了Termios.Cflag方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setTermSettingsCtsRts
func setTermSettingsCtsRts(enable bool, settings *syscall.Termios) {
if enable {
settings.Cflag |= termiosMask(tcCRTSCTS)
} else {
settings.Cflag &= ^termiosMask(tcCRTSCTS)
}
}
示例2: Init
func (s *Screen) Init() error {
var err error
ttyIn, err = os.OpenFile("/dev/tty", os.O_RDWR, 0666)
if err != nil {
return err
}
ttyOut, err = os.OpenFile("/dev/tty", os.O_RDONLY, 0666)
if err != nil {
return err
}
orig = new(syscall.Termios)
err = tcgetattr(ttyIn.Fd(), orig)
if err != nil {
return err
}
tios := new(syscall.Termios)
*tios = *orig
tios.Iflag &= ^uint32(syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG)
tios.Iflag &= ^uint32(syscall.BRKINT | syscall.ICRNL | syscall.ISTRIP | syscall.IXON)
tios.Cflag &= ^uint32(syscall.CSIZE | syscall.PARENB)
tios.Cflag |= syscall.CS8
tios.Oflag &= ^uint32(syscall.OPOST)
tios.Cc[syscall.VMIN] = 1
tios.Cc[syscall.VTIME] = 0
err = tcsetattr(ttyIn.Fd(), tios)
if err != nil {
return err
}
s.HideCursor()
s.Clear()
return nil
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例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: OpenSerial
func OpenSerial(device string, baud uint) (s *serial, err error) {
myBaud := getBaud(baud)
if myBaud == 0 {
err = errInvalidBaud
return
}
fd, err := syscall.Open(
device,
os.O_RDWR|syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NDELAY|syscall.O_NONBLOCK,
0666)
if err != nil {
return
}
defer func() {
if err != nil {
syscall.Close(fd)
}
}()
term := syscall.Termios{}
if err = sys.Ioctl(uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&term))); err != nil {
return
}
term.Ispeed = myBaud
term.Ospeed = myBaud
term.Cflag |= (syscall.CLOCAL | syscall.CREAD)
term.Cflag = uint32(int32(term.Cflag) & ^syscall.PARENB & ^syscall.CSTOPB & ^syscall.CSIZE)
term.Cflag |= syscall.CS8
term.Lflag = uint32(int32(term.Lflag) & ^(syscall.ICANON | syscall.ECHO | syscall.ECHOE | syscall.ISIG))
term.Oflag = uint32(int32(term.Oflag) & ^syscall.OPOST)
term.Cc[syscall.VMIN] = 0
term.Cc[syscall.VTIME] = 100
if err = sys.Ioctl(uintptr(fd), syscall.TCSETS, uintptr(unsafe.Pointer(&term))); err != nil {
return
}
status := 0
if err = sys.Ioctl(uintptr(fd), syscall.TIOCMGET, uintptr(unsafe.Pointer(&status))); err != nil {
return
}
status |= syscall.TIOCM_DTR | syscall.TIOCM_RTS
if err = sys.Ioctl(uintptr(fd), syscall.TIOCMSET, uintptr(unsafe.Pointer(&status))); err != nil {
return
}
s = &serial{uintptr(fd)}
runtime.SetFinalizer(s, func(this *serial) {
this.Close()
})
return
}
示例9: Set
func (c *cflagSetter) Set(pty *os.File, termios *syscall.Termios, value uint32) error {
switch c.Flag {
// CSIZE is a field
case syscall.CS7, syscall.CS8:
termios.Cflag &^= syscall.CSIZE
termios.Cflag |= c.Flag
default:
if value == 0 {
termios.Cflag &^= c.Flag
} else {
termios.Cflag |= c.Flag
}
}
return SetAttr(pty, termios)
}
示例10: 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
}
示例11: 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
}
示例12: 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
}
示例13: 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
}
示例14: setRawMode
func setRawMode(settings *syscall.Termios, mode *Mode) {
// 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 | tc_IUCLC)
settings.Oflag &= ^termiosMask(syscall.OPOST)
if mode.Vmin == 0 && mode.Vtimeout == 0 {
// Switch to default mode
// Block reads until at least one char is available (no timeout)
mode.Vmin = 1
}
settings.Cc[syscall.VMIN] = mode.Vmin
settings.Cc[syscall.VTIME] = mode.Vtimeout
}
示例15: setTermSettingsParity
func setTermSettingsParity(parity Parity, settings *syscall.Termios) error {
switch parity {
case PARITY_NONE:
settings.Cflag &= ^termiosMask(syscall.PARENB | syscall.PARODD | tc_CMSPAR)
settings.Iflag &= ^termiosMask(syscall.INPCK)
case PARITY_ODD:
settings.Cflag |= termiosMask(syscall.PARENB | syscall.PARODD)
settings.Cflag &= ^termiosMask(tc_CMSPAR)
settings.Iflag |= termiosMask(syscall.INPCK)
case PARITY_EVEN:
settings.Cflag &= ^termiosMask(syscall.PARODD | tc_CMSPAR)
settings.Cflag |= termiosMask(syscall.PARENB)
settings.Iflag |= termiosMask(syscall.INPCK)
case PARITY_MARK:
settings.Cflag |= termiosMask(syscall.PARENB | syscall.PARODD | tc_CMSPAR)
settings.Iflag |= termiosMask(syscall.INPCK)
case PARITY_SPACE:
settings.Cflag &= ^termiosMask(syscall.PARODD)
settings.Cflag |= termiosMask(syscall.PARENB | tc_CMSPAR)
settings.Iflag |= termiosMask(syscall.INPCK)
}
return nil
}