Conversation
Remove Cflag settings of baudrate.
cmaglie
left a comment
There was a problem hiding this comment.
Hi @picohive thanks for the patch!
Do you actually have 12 serial ports installed?
/dev/tty00 serial Serial Port Unknown
/dev/tty01 serial Serial Port Unknown
/dev/tty02 serial Serial Port Unknown
/dev/tty03 serial Serial Port Unknown
/dev/ttyU0 serial Serial Port (USB) Unknown
/dev/ttyU1 serial Serial Port (USB) Unknown
/dev/ttyU2 serial Serial Port (USB) Unknown
/dev/ttyU3 serial Serial Port (USB) Unknown
/dev/ttyU4 serial Serial Port (USB) Unknown
/dev/ttyU5 serial Serial Port (USB) Unknown
/dev/ttyU6 serial Serial Port (USB) Unknown
/dev/ttyU7 serial Serial Port (USB) Unknown
it looks like those are preallocated devices that are not connected to any actual port (more or less what Linux does with the ttySxx devices). Is there a way to filter those from the list output?
| func nativeGetPortDetails(portPath string) (*PortDetails, error) { | ||
| result := &PortDetails{Name: portPath} | ||
|
|
||
| if strings.Contains(result.Name, "U") { | ||
| result.IsUSB = true | ||
| } | ||
| return result, nil | ||
| } |
There was a problem hiding this comment.
It would be great to get the USB VID, PID, and ISerial number is this possible?
There was a problem hiding this comment.
Indeed, they are just available precreated node. There is no sysfs on NetBSD yet, maybe have a better solution in the future.
There was a problem hiding this comment.
It is possible, what you need to do is to open /dev/usb0 and issue the DRVLISTDEV ioctl. example code in C
I can send a separate PR to add support for that after the basic support is merged.
| import "golang.org/x/sys/unix" | ||
|
|
||
| const devFolder = "/dev" | ||
| const regexFilter = "(dty|tty|dtyU|ttyU)[0-9]{1,2}" |
There was a problem hiding this comment.
What's the difference between dty and tty?
There was a problem hiding this comment.
From man tty(4) on NetBSD:
The /dev/ttyXX special file is used for dial-in modems and terminals.
The /dev/dtyXX special file is a SunOS-compatible dial-out device.
There was a problem hiding this comment.
Hi,
Please consider using this implementation instead. It supports arbitrary BAUD rates and allows to remove the mapping table.
const tcCMSPAR uint32 = 0 // not supported
const tcIUCLC uint32 = 0 // not supported
const tcCRTSCTS uint32 = unix.CRTSCTS
const ioctlTcgetattr = unix.TIOCGETA
const ioctlTcsetattr = unix.TIOCSETA
const ioctlTcflsh = unix.TIOCFLUSH
const ioctlTioccbrk = unix.TIOCCBRK
const ioctlTiocsbrk = unix.TIOCSBRK
func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) {
// see https://nxr.netbsd.org/xref/src/lib/libc/termios/cfsetspeed.c
if speed < 50 || speed > math.MaxInt32 {
return &PortError{code: InvalidSpeed}, true
}
settings.Ispeed = int32(speed)
settings.Ospeed = int32(speed)
return nil, false
}
func (port *unixPort) setSpecialBaudrate(speed uint32) error {
if speed < 50 || speed > math.MaxInt32 {
return &PortError{code: InvalidSpeed}
}
// see https://nxr.netbsd.org/xref/src/lib/libc/termios/tcgetattr.c
settings, err := unix.IoctlGetTermios(port.handle, ioctlTcgetattr)
if err != nil {
return err
}
if err, ok := setTermSettingsBaudrate(int(speed), settings); !ok {
return err
}
return unix.IoctlSetTermios(port.handle, ioctlTcsetattr, settings)
}
|
Hi there! What is the status on this PR? I would like to see it merged as I have a use for it. Looks like perhaps it could be merged and then tnn2 could send a PR for improvements. Thanks! |
Test with arduino-cli 0.35.3:
picohive: {/home/rxg} uname -a
NetBSD picohive 9.3 NetBSD 9.3 (GENERIC) #0: Thu Aug 4 15:30:37 UTC 2022 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
picohive: {/home/rxg} arduino-cli board list
Port Protocol Type Board Name FQBN Core
/dev/dty00 serial Serial Port Unknown
/dev/dty01 serial Serial Port Unknown
/dev/dty02 serial Serial Port Unknown
/dev/dty03 serial Serial Port Unknown
/dev/dtyU0 serial Serial Port (USB) Unknown
/dev/dtyU1 serial Serial Port (USB) Unknown
/dev/dtyU2 serial Serial Port (USB) Unknown
/dev/dtyU3 serial Serial Port (USB) Unknown
/dev/dtyU4 serial Serial Port (USB) Unknown
/dev/dtyU5 serial Serial Port (USB) Unknown
/dev/dtyU6 serial Serial Port (USB) Unknown
/dev/dtyU7 serial Serial Port (USB) Unknown
/dev/tty00 serial Serial Port Unknown
/dev/tty01 serial Serial Port Unknown
/dev/tty02 serial Serial Port Unknown
/dev/tty03 serial Serial Port Unknown
/dev/ttyU0 serial Serial Port (USB) Unknown
/dev/ttyU1 serial Serial Port (USB) Unknown
/dev/ttyU2 serial Serial Port (USB) Unknown
/dev/ttyU3 serial Serial Port (USB) Unknown
/dev/ttyU4 serial Serial Port (USB) Unknown
/dev/ttyU5 serial Serial Port (USB) Unknown
/dev/ttyU6 serial Serial Port (USB) Unknown
/dev/ttyU7 serial Serial Port (USB) Unknown
picohive: {/home/rxg} arduino-cli monitor -p /dev/ttyU0 -c baudrate=115200
Monitor port settings:
baudrate=115200
Connected to /dev/ttyU0! Press CTRL-C to exit.
Bpm:0,SPO2:90.00
Bpm:0,SPO2:90.00
Bpm:0,SPO2:90.00