История изменений
Исправление Alex_Golubev, (текущая версия) :
В общем что сделал:
- Изменил
/boot/config.txt
enable_uart=1
dtoverlay=disable-bt
gpio=17=a3
dtoverlay=miniuart-ctsrts
2.Проверил GPIO
root@pi:~# raspi-gpio get 17
GPIO 17: level=1 fsel=7 alt=3 func=RTS0 pull=DOWN
- Изменил
/boot/cmdline.txt
добавилdwc_otg.lpm_enable=0 console=tty1
и получил общее:wc_otg.lpm_enable=0 console=tty1 root=PARTUUID=f2412780-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
4.Далее выполнил скрипт: - git clone https://github.com/mholling/rpirtscts.git
- cd rpirtscts
- make получил make: «rpirtscts» не требует обновления.
- ./rpirtscts on
- chown root rpirtscts
- chmod 4755 rpirtscts
- stty -F /dev/ttyAMA0 crtscts далее вышел
- Далее запустил:
#include "mainwindow.h"
#include <QApplication>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/serial.h>
#include <sys/ioctl.h>
#include <QDebug>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
struct serial_rs485 rs485conf;
memset(&rs485conf, 0, sizeof(rs485conf));
int fd = open ("/dev/ttyAMA0", O_RDWR);
if (fd < 0) {
qDebug()<<"Error: Can't open: /dev/ttyAPP1";
}
if (ioctl (fd, TIOCGRS485, &rs485conf) < 0) {
qDebug()<<"Error: TIOCGRS485 ioctl not supported";
}
rs485conf.flags |= SER_RS485_ENABLED;
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
rs485conf.delay_rts_before_send = 100;
rs485conf.delay_rts_after_send = 100;
if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
// qDebug()<<"Error: TIOCSRS485 ioctl not supported.";
qDebug()<< errno << strerror( errno );
}
for(;;) {
int n = write(fd, "ABC\r\n", 5);
if (n < 0) {
/* Error handling */
break;
}
usleep(50000);
}
}
Не увидал изменений на GPIO17. Сигнал передачи есть. Проверял осцилографом. Строчка ioctl (fd, TIOCSRS485, &rs485conf)
вернула ошибку 25 Неприменимый к данному устройству ioctl
Исправление Alex_Golubev, :
В общем что сделал:
- Изменил
/boot/config.txt
enable_uart=1
dtoverlay=disable-bt
gpio=17=a3
dtoverlay=miniuart-ctsrts
2.Проверил GPIO
root@pi:~# raspi-gpio get 17
GPIO 17: level=1 fsel=7 alt=3 func=RTS0 pull=DOWN
- Изменил
/boot/cmdline.txt
добавилdwc_otg.lpm_enable=0 console=tty1
и получил общее:wc_otg.lpm_enable=0 console=tty1 root=PARTUUID=f2412780-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
4.Далее выполнил скрипт: - git clone https://github.com/mholling/rpirtscts.git
- cd rpirtscts
- make получил make: «rpirtscts» не требует обновления.
- ./rpirtscts on
- chown root rpirtscts
- chmod 4755 rpirtscts
- stty -F /dev/ttyAMA0 crtscts далее вышел
- Далее запустил:
#include "mainwindow.h"
#include <QApplication>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/serial.h>
#include <sys/ioctl.h>
#include <QDebug>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
struct serial_rs485 rs485conf;
memset(&rs485conf, 0, sizeof(rs485conf));
int fd = open ("/dev/ttyAMA0", O_RDWR);
if (fd < 0) {
qDebug()<<"Error: Can't open: /dev/ttyAPP1";
}
if (ioctl (fd, TIOCGRS485, &rs485conf) < 0) {
qDebug()<<"Error: TIOCGRS485 ioctl not supported";
}
rs485conf.flags |= SER_RS485_ENABLED;
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
rs485conf.delay_rts_before_send = 100;
rs485conf.delay_rts_after_send = 100;
if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
// qDebug()<<"Error: TIOCSRS485 ioctl not supported.";
qDebug()<< errno << strerror( errno );
}
for(;;) {
int n = write(fd, "ABC\r\n", 5);
if (n < 0) {
/* Error handling */
break;
}
usleep(50000);
}
}
Не увидал изменений на GPIO17. Сигнал передачи есть. Проверял осцилографом.
Исходная версия Alex_Golubev, :
В общем что сделал:
- Изменил
/boot/config.txt
enable_uart=1
dtoverlay=disable-bt
gpio=17=a3
dtoverlay=miniuart-ctsrts
2.Проверил GPIO
root@pi:~# raspi-gpio get 17
GPIO 17: level=1 fsel=7 alt=3 func=RTS0 pull=DOWN
- Изменил
/boot/cmdline.txt
добавилdwc_otg.lpm_enable=0 console=tty1
и получил общее:wc_otg.lpm_enable=0 console=tty1 root=PARTUUID=f2412780-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
4.Далее выполнил скрипт: - git clone https://github.com/mholling/rpirtscts.git
- cd rpirtscts
- make получил make: «rpirtscts» не требует обновления.
- ./rpirtscts on
- chown root rpirtscts
- chmod 4755 rpirtscts
- stty -F /dev/ttyAMA0 crtscts далее вышел
- Далее добавил кот для запуска:
#include "mainwindow.h"
#include <QApplication>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/serial.h>
#include <sys/ioctl.h>
#include <QDebug>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
struct serial_rs485 rs485conf;
memset(&rs485conf, 0, sizeof(rs485conf));
int fd = open ("/dev/ttyAMA0", O_RDWR);
if (fd < 0) {
qDebug()<<"Error: Can't open: /dev/ttyAPP1";
}
if (ioctl (fd, TIOCGRS485, &rs485conf) < 0) {
qDebug()<<"Error: TIOCGRS485 ioctl not supported";
}
rs485conf.flags |= SER_RS485_ENABLED;
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
rs485conf.delay_rts_before_send = 100;
rs485conf.delay_rts_after_send = 100;
if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) {
// qDebug()<<"Error: TIOCSRS485 ioctl not supported.";
qDebug()<< errno << strerror( errno );
}
for(;;) {
int n = write(fd, "ABC\r\n", 5);
if (n < 0) {
/* Error handling */
break;
}
usleep(50000);
}
}