Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Sep 2006 22:33:24 +0600
From:      =?koi8-r?b?88XSx8XKIPPPwsvP?= <bug2bug@bug2bug.tk>
To:        backyard1454-bsd@yahoo.com
Cc:        freebsd-questions@freebsd.org
Subject:   Re: A question about programming RS-232
Message-ID:  <200609042233.24740.bug2bug@bug2bug.tk>

next in thread | raw e-mail | index | archive | help
On Monday 04 September 2006 02:39, you wrote:
> --- stan <stanb@panix.com> wrote:
> > On Sun, Sep 03, 2006 at 11:26:04PM +0600, ??????
> >
> > ????? wrote:
> > > Hello.
> > > I have a question I can't deal myself.
> > > And nobody can help me in resolving my problem.
> > >
> > > Problem:
> > > I have a hand-made device, I want to control from
> >
> > FreeBSD 6.1
> >
> > > (I am porting this application from Windows
> >
> > equivalent).
> >
> > > But I don't know, in what device /dev/ I should
> >
> > write to get reults.
> >
> > > I tryed to write bytes into /dev/ttyd0,
> >
> > /dev/cuad0, but got nothing. :(
> >
> > Start off by using minicom (or cu) to talk to the
> > device. By doing
> > this you can sort through baud rate/parity,hardware
> > issues.
> >
> > Once you have that working, then move on to code.
> >
> > --
> > Unix is very simple, but it takes a genius to
> > understand the simplicity.
> > (Dennis Ritchie)
> > _______________________________________________
> > freebsd-questions@freebsd.org mailing list
>
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
>
> > To unsubscribe, send any mail to
> > "freebsd-questions-unsubscribe@freebsd.org"
>
> does your handmade device use RS-232? If its PIC or
> some such microcontroller based they claim to be
> RS-232 compliant but they do not always use +12V and
> -12V levels. MAX-232 chips can correct this. I assume
> if it worked in windows for you this might not the
> case, but you never know.
>
>
> -brian

Yes, you are partialy right, I'm using an old Atmel AT89C4051 microcontroll=
er,=20
I'm trying to control from through RS-232. The levels are correct as I know=
=2E=20
But I don't know if the code is correct :(
I want to send 6 bytes through RS-232 with the following characteristics:

Port: COM1
Data Bits: 8
Stop Bits: 1
Parity: None
=46low Control: None

Please, say me if this code is incorrect:

#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>

int main(void) {
=9Aint t =3D 0, num =3D 10, fd, iOut; char *ch;
=9Astruct termios my_termios;
=9Ach =3D (char *)malloc(6);
=9Amemset(ch, 250, 6);
=9Afd =3D open("/dev/cuad0", O_RDWR | O_NONBLOCK);
=9Aprintf("Opened com port\n");
=9Aif(fd < 0) return 0;
// tcflush(fd, TCIFLUSH);
=9Amy_termios.c_cflag =3D CS8 | CLOCAL;
=9Aif(cfsetspeed(&my_termios, B9600) < 0) return 0;
=9Aif(tcsetattr(fd, TCSANOW, &my_termios) < 0) return 0;
=9AiOut =3D write(fd, ch, 6);
=9Aif(iOut < 0) return 0;
=9Aprintf("Number of bytes =3D %d\n", iOut);
=9Aprintf("Writed %s!\n", ch);
=9Aclose(fd);
=9Aprintf("Closed!\n");
=9Areturn 0;
}

Thank you for any help.
With best regards, Sergei Sobko

P.S. Sorry for my bad English as I'm only 16 and I'm from Russia ;)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609042233.24740.bug2bug>