我们如何通过 USB 端口启用 XBee S2C 和 Raspi 3 之间的串行通信?
为此,我使用Sparkfun 的 XBee explorer dongle。我有几个这样的组合来创建一个 ZigBee 网络并测试一个用 C 编码的协议。但是,我在读取/dev/ttyUSB0
. 顺便说一句,问题可能出在发送方。
XBees 使用下面给出的串行接口配置运行:
115200 baudrate
No parity
1 stop bit
3 character times for packetization timeout
CTS flow control is enabled
RTS flow control is disabled
API mode is enabled
API output mode is native
因此,我在代码中初始化了端口,如下所示:
int initport(int fd)
{
int portstatus = 0;
struct termios options;
// Get the current options for the port...
tcgetattr(fd, &options);
// Set the baud rates to 9600...'textB' un
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
// Enable the receiver and setSTX local mode...
options.c_cflag |= (CLOCAL | CREAD);
//options.c_cflag &= ~PARENB;
//options.c_cflag &= ~CSTOPB; //When these are disabled the XBee receives data.
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
//options.c_cflag |= SerialDataBitsInterp(8); /* CS8 - Selects 8 data bits */
options.c_cflag &= ~CRTSCTS; // disable hardware flow control
options.c_iflag &= ~(IXON | IXOFF | IXANY); // disable XON XOFF (for transmit and receive)
//options.c_cflag |= CRTSCTS; /* enable hardware flow control */
options.c_cc[VMIN] = 200; //min carachters to be read
options.c_cc[VTIME] = 5; //Time to wait for data (tenths of seconds)
// Set the new options for the port...
//tcsetattr(fd, TCSANOW, &options);
//Set the new options for the port...
tcflush(fd, TCIFLUSH);
if (tcsetattr(fd, TCSANOW, &options)==-1)
{
perror("On tcsetattr:");
portstatus = -1;
}
else
portstatus = 1;
return portstatus;
}
我想在这里问这个问题,因为我认为我需要对某些文件进行一些修改,例如/boot/config.txt
和/或/boot/cmdline.txt
. 在我在网络上的搜索中,出现了这种修改,但在我的情况下它们不起作用。
最后,Raspis 运行最新版本的 Raspbian Jessie 和 Linux 内核 4.9.35-v7+。
$uname -a
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
$cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
请不要犹豫,询问有关我的设置的任何其他详细信息。
先感谢您。