From: hasan (hasanyetisen@yahoo.com)
Date: Thu 22 Aug 2002 - 16:32:37 EEST
merhabalar;
C ile seri porttan elektronik boarda iletiler
göndermek istiyorum.
Infoboardun Seri Haberlesme Standardi: RS 232-C,
asynchronous, simplex
Iletim hızı : 2400 bps
Çerçeve yapısı : 1 start bit, 8 data bits, no parity,
2 stop bits
Konnektör tipi : DB-09 / female
Aşagıdaki kodda birçok deneme yapmama ragmen bir sonuc
alamadım. Dosyayı açarkenki parametrelerden ve
settingslerinden emin degilim.
Yardımlarınız icin teşekkürler...
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/time.h>
#define DATASTRING1 "02"
#define DATASTRING2 "30303031"
#define DATASTRING3
"1747475252522020202020202020202020202020202020202004"
void mdelay(int milliseconds)
{
struct timeval tv;
if (milliseconds) {
tv.tv_sec = 0;
tv.tv_usec = milliseconds * 1000;
select(1, NULL, NULL, NULL, &tv);
}
}
int open_port(void)
{
int fd;
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY |
O_NONBLOCK);
if (fd == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
exit(0);
}
return (fd);
}
int main()
{
struct termios options,oldone;
int fd,n;
fd = open_port();
tcgetattr(fd, &oldone);
memset(&options, 0, sizeof(options));
options.c_cflag |= CS8;
options.c_cflag |= CSTOPB;
options.c_cflag |= CLOCAL;
options.c_oflag |= OPOST;
options.c_lflag |= ECHO;
cfsetospeed(&options, B2400);
cfsetispeed(&options, B2400);
tcsetattr(fd, TCSANOW, &options);
if (cfgetospeed(&options) != B2400)
printf("output speed is not 2400 bps.\n");
n=write(fd, DATASTRING1 , strlen(DATASTRING1));
printf("%d",n);
tcdrain(fd);
mdelay(5);
n=write(fd, DATASTRING2 , strlen(DATASTRING2));
printf("%d",n);
tcdrain(fd);
mdelay(5);
n=write(fd, DATASTRING3 , strlen(DATASTRING3));
printf("%d",n);
tcdrain(fd);
tcsetattr(fd, TCSANOW, &oldone);
close(fd);
return(0);
}
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
-----------------------------------------------------------------------
Liste üyeliğiniz ile ilgili her türlü işlem için
http://liste.linux.org.tr adresindeki web arayüzünü kullanabilirsiniz.
Listeden çıkmak için: 'linux-request@linux.org.tr' adresine,
"Konu" kısmında "unsubscribe" yazan bir e-posta gönderiniz.
-----------------------------------------------------------------------