From owner-freebsd-questions@FreeBSD.ORG Mon Sep 4 16:31:30 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4CAE516A4DD for ; Mon, 4 Sep 2006 16:31:30 +0000 (UTC) (envelope-from bug2bug@bug2bug.tk) Received: from ns.vega-int.ru (ns.vega-int.ru [62.148.228.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 302E143D5C for ; Mon, 4 Sep 2006 16:31:29 +0000 (GMT) (envelope-from bug2bug@bug2bug.tk) Received: from localhost (localhost.localdomain [127.0.0.1]) by ns.vega-int.ru (Postfix) with ESMTP id C870D100048; Mon, 4 Sep 2006 22:31:27 +0600 (YEKST) Received: from ns.vega-int.ru ([127.0.0.1]) by localhost (ns [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13967-10; Mon, 4 Sep 2006 22:31:24 +0600 (YEKST) Received: from [172.17.12.179] (unknown [172.17.12.179]) by ns.vega-int.ru (Postfix) with ESMTP id 35AE9100043; Mon, 4 Sep 2006 22:31:24 +0600 (YEKST) From: =?koi8-r?b?88XSx8XKIPPPwsvP?= To: backyard1454-bsd@yahoo.com Date: Mon, 4 Sep 2006 22:33:24 +0600 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200609042233.24740.bug2bug@bug2bug.tk> X-Virus-Scanned: by amavisd-new at vega-int.ru Cc: freebsd-questions@freebsd.org Subject: Re: A question about programming RS-232 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Sep 2006 16:31:30 -0000 On Monday 04 September 2006 02:39, you wrote: > --- stan 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 #include #include #include 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 ;)