विफल रहता है मैं निम्नलिखित सी कार्यक्रम है:सीरियल पोर्ट से पढ़ना
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
int main()
{
int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
if(fd < 0)
{
perror("Could not open device");
}
printf("Device opened\n");
struct termios options;
tcgetattr(fd, &options);
cfmakeraw(&options);
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
tcsetattr(fd, TCSANOW, &options);
char txpacket[] = {0x23, 0x06, 0x00, 0x00, 0xdd, 0xf9};
ssize_t written = write(fd, txpacket, sizeof(txpacket));
printf("Written %d bytes\n", written);
printf("Starting to wait for target to respond\n");
while(1)
{
fd_set readset;
FD_ZERO(&readset);
FD_SET(fd, &readset);
int nCount = select(fd + 1, &readset, NULL, NULL, NULL);
if(nCount > 0)
{
if(FD_ISSET(fd, &readset))
{
int i;
char buffer[128];
ssize_t bytesread = read(fd, buffer, sizeof(buffer));
printf("Received %d bytes\n", bytesread);
for(i = 0; i < bytesread; i++)
{
printf(" %02x", buffer[i]);
}
}
}
}
}
इस कार्यक्रम के धारावाहिक डिवाइस/dev/ttyS0, यह करने के लिए डेटा का एक अनुक्रम लिखते हैं और एक प्रतिक्रिया के लिए सुन शुरू होता है खोलता है। मुझे निम्न आउटपुट मिलता है:
Device opened
Written 6 bytes
Starting to wait for target to respond
Received 0 bytes
Received 0 bytes
Received 0 bytes
Received 0 bytes
Received 0 bytes
Received 0 bytes
...
और एप्लिकेशन 100% CPU का उपभोग करता है। मैं कोई डेटा प्राप्त करने में सक्षम नहीं हूं, भले ही लक्ष्य हार्डवेयर वास्तव में इसे प्रसारित करता है।
क्या गलत है?
धन्यवाद! वास्तव में समस्या का कारण क्या था। – anorm
अरे, क्लॉकल चीज़ नहीं देखी! – shodanex
एक ही समस्या थी, टिप के लिए धन्यवाद। Cfmakeraw उन दो स्पष्ट झंडे को नहीं देखते थे। – RishiD