السلام عليكم و رحمة الله و بركاته
إنني أحاول أن أربط جهازي حاسوب فيما بينهما عبر أو عن طريق serial interface وهو المكان الذي كنا نربط فيه الفأرة (mouse) وذلك تحت لغة البرمجة C و نظام التحكم Linux.
وهذا هو البرنامج الذي كان يجب أن يرسل معلومات بسيطة وهو طبقا لما وجدته في الكتب و الإنترنت و أنا لست أدري أين ممكن أن يكون الخطء.
هل ممكن أن ترشدوني, فإنني لا أري ماذا أفعل,
وبارك الله فيكم
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
void init_port(int fd)
{
struct termios my_t;
tcgetattr(fd, &my_t);
my_t.c_cflag = 0;
my_t.c_iflag = 0;
my_t.c_oflag = 0;
my_t.c_lflag = 0;
cfsetospeed(&my_t, B1200);
/* 8E1 */
my_t.c_cflag |= PARENB;
my_t.c_cflag &= ~PARODD;
my_t.c_cflag &= ~CSTOPB;
my_t.c_cflag &= ~CSIZE;
my_t.c_cflag |= CS8;
/* RTS/CTS */
my_t.c_cflag |= CRTSCTS;
/* LOCAL */
my_t.c_cflag |= (CLOCAL | CREAD);
tcsetattr(fd, TCSANOW, &my_t);
}
int main()
{
int fd, iOut;
char buf[] ="try 2 send smtg "
fd = open("/dev/ttyS0", O_WRONLY | O_NOCTTY | O_NDELAY);
if ( fd < 0)
{
fprintf(stderr, "Couln't open COM0");
}
else
{
init_port(fd);
iOut = write(fd, buf, 19);
if( iOut < 0);
{
printf("Couln't write in COM0: %d, %s\n", errno, strerror(errno);
}
else
{
printf("%d characters was written\n", strlen(buf);
printf(": %s\n", buf);
}
}
close(fd);
return 0;
}