I’ve been trying to get rs485 working on my verdin through the dedicated rs485 dbus9 connector on the dev board for a few days now. Some of this is definitely down to my confusion and inexperience but if anyone can offer some guidance it would be greatly appreciated.
I’ve added the device to my dockerfile:
version: "3.9"
services:
qttemp-debug:
build:
context: .
dockerfile: Dockerfile.debug
image: ${LOCAL_REGISTRY}:5002/qttemp-debug:${TAG}
ports:
# SSH debug
- 2231:2231
# gdbserver
- 2232:2232
# qml debug
- 2233:2233
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
device_cgroup_rules:
# ... for tty0
- "c 4:0 rmw"
# ... for tty7
- "c 4:7 rmw"
# ... for /dev/input devices
- "c 13:* rmw"
- "c 199:* rmw"
# ... for /dev/dri devices
- "c 226:* rmw"
depends_on: [
weston
]
devices:
- "/dev/verdin-uart1:/dev/verdin-uart1"
- "/dev/video0:/dev/video0"
- "/dev/video1:/dev/video1"
restart: on-failure
qttemp:
build:
context: .
dockerfile: Dockerfile
image: ${DOCKER_LOGIN}/qttemp:${TAG}
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
device_cgroup_rules:
# ... for tty0
- "c 4:0 rmw"
# ... for tty7
- "c 4:7 rmw"
# ... for /dev/input devices
- "c 13:* rmw"
- "c 199:* rmw"
# ... for /dev/dri devices
- "c 226:* rmw"
depends_on: [
weston
]
devices:
- "/dev/verdin-uart1:/dev/verdin-uart1"
- "/dev/video0:/dev/video0"
- "/dev/video1:/dev/video1"
restart: on-failure
weston:
image: torizon/weston${GPU}:2
environment:
- ACCEPT_FSL_EULA=1
# Required to get udev events from host udevd via netlink
network_mode: host
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
- type: bind
source: /run/udev
target: /run/udev
cap_add:
- CAP_SYS_TTY_CONFIG
# Add device access rights through cgroup...
device_cgroup_rules:
# ... for tty0
- "c 4:0 rmw"
# ... for tty1
- "c 4:1 rmw"
# ... for tty7
- "c 4:7 rmw"
# ... for /dev/input devices
- "c 13:* rmw"
- "c 199:* rmw"
# ... for /dev/dri devices
- "c 226:* rmw"
I’m pretty sure this actually works because when I “open” the serial device in qt5 now it doesn’t throw an error.
Here is the relevant qt5 code. It’s a bit of a mess but you’ll see what I’m trying to accomplish:
int fd;
fd = open("/dev/verdin-uart1", O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC);
qDebug() << fd;
struct serial_rs485 rs485conf;
rs485conf.flags |= SER_RS485_ENABLED;
rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);
rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
rs485conf.flags |= SER_RS485_RX_DURING_TX;
ioctl(fd, TIOCSRS485, &rs485conf);
serialDevice = new QSerialPort(this);
qDebug() << "Number of serial ports: " << QSerialPortInfo::availablePorts().length() << "\n";
foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
qDebug() << "Description: " << serialPortInfo.description() << "\n";
qDebug() << "Has vendor id?: " << serialPortInfo.hasVendorIdentifier() << "\n";
qDebug() << "Vendor ID: " << serialPortInfo.vendorIdentifier() << "\n";
qDebug() << "Has product id?: " << serialPortInfo.hasProductIdentifier() << "\n";
qDebug() << "Product ID: " << serialPortInfo.productIdentifier() << "\n";
}
QString portName;
foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts())
{
if(serialPortInfo.hasProductIdentifier() && serialPortInfo.hasVendorIdentifier())
{
qDebug() << serialPortInfo.vendorIdentifier();
qDebug() << serialPortInfo.productIdentifier();
if((serialPortInfo.productIdentifier() == product_id) && (serialPortInfo.vendorIdentifier() == vendor_id))
{
portName = serialPortInfo.portName();
}
}
}
qDebug() << portName;
qDebug() << vendor_id;
qDebug() << product_id;
qDebug() << serialDevice->error();
//serialDevice->setPortName(portName);
serialDevice->setPortName("/dev/verdin-uart1");
qDebug() << serialDevice->open(QSerialPort::ReadWrite);
qDebug() << serialDevice->error();
serialDevice->setBaudRate(QSerialPort::Baud9600);
serialDevice->setDataBits(QSerialPort::Data8);
serialDevice->setFlowControl(QSerialPort::NoFlowControl);
serialDevice->setParity(QSerialPort::NoParity);
serialDevice->setStopBits(QSerialPort::OneStop);
QObject::connect(serialDevice, SIGNAL(readyRead()), this, SLOT(readSerial()));
void MainWindow::openLock(int lockNumber, int boardNumber)
{
qDebug() << lockNumber;
qDebug() << boardNumber;
QByteArray myHexArray = QByteArray::fromHex("8A0100119A");
qDebug() << myHexArray;
qDebug() << serialDevice->error();
qDebug() << serialDevice->write(myHexArray);
qDebug() << serialDevice->error();
}
Firstly I had set this up just using the qt serial control code. It worked fine using a usb to rs485 adapter or using gpio pins on a raspberry pi. However, the toradex verdin does not appear to send any message at all when I invoke openLock. I know this because I am looking at the rs485 debug that I have running from the usbc port which shows output while the verdin is booting up but nothing when I runt he function.
I added the ioctl code after reading this doc on torizon-core:
From what I can tell from those docs the flags I’m setting are the only ones that are necessary. I couldn’t figure out a way to do that from the qt serial lib, but perhaps one does exist. And help or direction on this would be much appreciated.