From: hasan (hasanyetisen@yahoo.com)
Date: Wed 21 Aug 2002 - 22:42:19 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
Konnektör baðlantýsý : Pin:3----------
receive data
Pin:5---------- data ground
Aşagıdaki kodda birçok deneme yapmama ragmen bir sonuc
alamadım. Dosyayı açarkenki parametrelerde ve
settingslerinde emin degilim. Boardun kabul ettigi
mesaj formatı ise attach ettigim dosyada mevcut.
Yardımlarınız icin teşekkürler...
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h> /* Standard input/output
definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function
definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control
definitions */
struct termios options,oldone;
int fd,n; /* File descriptor for the port */
int open_port(void)
{
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY |
O_NONBLOCK);
if (fd < 0)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, FASYNC);
return (fd);
}
int main()
{
open_port();
tcgetattr(fd, &oldone);
tcgetattr(fd, &options);
options.c_cflag &= ~CBAUD;
options.c_cflag &= ~CSIZE;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CLOCAL;
options.c_cflag &= ~HUPCL;
options.c_cflag |= (B2400 | CS8 | CSTOPB | CLOCAL |
HUPCL);
tcflush(fd, 2);
tcsetattr(fd, TCSANOW, &options);
if (cfgetispeed(&options) != B2400)
printf("input speed is not 2400 bps.\n");
n=write(fd,
"02303030311747475252522020202020202020202020202020202020202004",
62);
tcdrain(fd);
tcsetattr(fd, TCSANOW, &oldone);
close(fd);
return(0);
}
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
-- Binary/unsupported file stripped by Ecartis --
-- Type: text/richtext
-- File: Infoboard_attributes.rtf
-- Desc: Infoboard_attributes.rtf