pi 4 rts control just werks
parent
67e9159dad
commit
ef5cdb3bc8
@ -0,0 +1,7 @@
|
||||
# Raspberry Pi Serial Bus Manager
|
||||
|
||||
Pinout - we're using uart2, aka ttyAMA1
|
||||
|
||||
| TX | RX | CTS | RTS |
|
||||
| --- | --- | --- | --- |
|
||||
| GPIO0/PIN 27 | GPIO1/PIN 28 | GPIO2/PIN 3 | GPIO3/PIN 5 |
|
Binary file not shown.
@ -1,7 +1,63 @@
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <linux/serial.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
uint8_t send_buffer[14] = {0x7E, 0x01, 0x02, 8, 0x01, 0x02, 0x03,
|
||||
0x7D, 0x5E, 0x05, 0x06, 0x07, 0x08, 0xFF};
|
||||
|
||||
/* Open your specific device (e.g., /dev/mydevice): */
|
||||
int fd = open("/dev/ttyAMA1", O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
/* Error handling. See errno. */
|
||||
fprintf(stderr, "Failed... error:%s", strerror(errno));
|
||||
}
|
||||
|
||||
struct serial_rs485 rs485conf;
|
||||
|
||||
/* Enable RS485 mode: */
|
||||
rs485conf.flags |= SER_RS485_ENABLED;
|
||||
|
||||
/* Set logical level for RTS pin equal to 1 when sending: */
|
||||
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
|
||||
/* or, set logical level for RTS pin equal to 0 when sending: */
|
||||
rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);
|
||||
|
||||
/* Set logical level for RTS pin equal to 1 after sending: */
|
||||
rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
|
||||
/* or, set logical level for RTS pin equal to 0 after sending: */
|
||||
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
|
||||
|
||||
// /* Set rts delay before send, if needed: */
|
||||
// rs485conf.delay_rts_before_send = ...;
|
||||
|
||||
// /* Set rts delay after send, if needed: */
|
||||
// rs485conf.delay_rts_after_send = ...;
|
||||
|
||||
/* Set this flag if you want to receive data even while sending data */
|
||||
// rs485conf.flags |= SER_RS485_RX_DURING_TX;
|
||||
|
||||
if (ioctl(fd, TIOCSRS485, &rs485conf) < 0)
|
||||
{
|
||||
std::cout << "Hello" << std::endl;
|
||||
std::cout << "Hello" << std::endl;
|
||||
/* Error handling. See errno. */
|
||||
}
|
||||
|
||||
/* Use read() and write() syscalls here... */
|
||||
ssize_t rc = 0;
|
||||
write(fd, send_buffer, 14);
|
||||
|
||||
/* Close the device when finished: */
|
||||
if (close(fd) < 0)
|
||||
{
|
||||
/* Error handling. See errno. */
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue