Пример #1
0
// GetISpeed returns the input (receiver) baudrate in Termios
// structure t as a numerical (integer) value in
// bits-per-second. Returns err == syscal.EINVAL if the baudrate in t
// cannot be decoded. See also getispeed(3).
func (t *Termios) GetISpeed() (speed int, err error) {
	code := C.cfgetispeed(&t.t)
	speed, ok := stdSpeeds.Speed(spdCode(code))
	if !ok {
		return 0, syscall.EINVAL
	}
	return speed, nil
}
Пример #2
0
// Getispeed returns the input baud rate in the Termios
// structure referenced by src.
func Getispeed(src *Termios) (result C.speed_t) {
	result = C.cfgetispeed(&src.i)
	return
}
Пример #3
0
func (s *Serial) Baud() uint32 {
	var baud uint32 = 0
	if s.Opened {
		var tios C.struct_termios
		getTermios(s.f, &tios)
		switch C.cfgetispeed(&tios) {
		case C.B0:
			baud = 0
		case C.B50:
			baud = 50
		case C.B75:
			baud = 75
		case C.B110:
			baud = 110
		case C.B134:
			baud = 134
		case C.B150:
			baud = 150
		case C.B200:
			baud = 200
		case C.B300:
			baud = 300
		case C.B600:
			baud = 600
		case C.B1200:
			baud = 1200
		case C.B1800:
			baud = 1800
		case C.B2400:
			baud = 2400
		case C.B4800:
			baud = 4800
		case C.B9600:
			baud = 9600
		case C.B19200:
			baud = 19200
		case C.B38400:
			baud = 38400
		case C.B57600:
			baud = 57600
		case C.B115200:
			baud = 115200
		case C.B230400:
			baud = 230400
		case C.B460800:
			baud = 460800
		case C.B500000:
			baud = 500000
		case C.B576000:
			baud = 576000
		case C.B921600:
			baud = 921600
		case C.B1000000:
			baud = 1000000
		case C.B1152000:
			baud = 1152000
		case C.B1500000:
			baud = 1500000
		case C.B2000000:
			baud = 2000000
		case C.B2500000:
			baud = 2500000
		case C.B3000000:
			baud = 3000000
		case C.B3500000:
			baud = 3500000
		case C.B4000000:
			baud = 4000000
		}
	}
	return baud
}
Пример #4
0
// Cfgetispeed returns the input baud rate stored in the termios structure.
func Cfgetispeed(attr *syscall.Termios) uint32 {
	solTermios := (*unix.Termios)(attr)
	return uint32(C.cfgetispeed((*C.termios_t)(unsafe.Pointer(solTermios))))
}