You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#include "p_serial_bus.h"
|
|
#include <cstring>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <iostream>
|
|
#include <linux/serial.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */
|
|
#include <sys/ioctl.h>
|
|
|
|
ps_bus::ps_bus(const char* dev)
|
|
{
|
|
/* Open your specific device (e.g., /dev/mydevice): */
|
|
int fd = open(dev, O_RDWR);
|
|
if (fd < 0)
|
|
{
|
|
/* Error handling. See errno. */
|
|
fprintf(stderr, "Creation of the bus 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)
|
|
{
|
|
/* Error handling. See errno. */
|
|
}
|
|
}
|
|
|
|
ps_bus::~ps_bus()
|
|
{
|
|
/* Close the device when finished: */
|
|
if (close(dev_fd) < 0)
|
|
{
|
|
/* Error handling. See errno. */
|
|
}
|
|
}
|
|
|
|
void ps_bus::ps_bus_start()
|
|
{}
|