[clug] modifying serial.c

caloy diaz caloykoy_one at pacific.net.ph
Tue Feb 24 13:27:32 GMT 2004


thanks very much for the advice sir francis. i think i sorta like it because
it sounds less complicated. now i am looking at the different device
drivers' codes (like serial.c, busmouse.c) however my problem is i don't
know which of these lines is the "minimum" i have to use to say that 1) this
is a device driver and 2) as suggested, this will control the serial driver

i've pasted below the C code we use to control the arm, maybe it might help.
"OG" in move("OG\n"); is the command that we send for example, in this case
it's "open grip" :)

somehow i feel more and more enlightened but still am kinda groping in the
dark. there's this linux device drivers book on the web, i'm reading it but
sometimes i get confused...

thanks very much guys.

caloykoy

#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#define BAUDRATE B9600
#define PORT1 "/dev/ttyS1"
#define _POSIX_SOURCE 1

main(){

move("OG\n");

}

void move(char com1[23])
{
  int fd, c, byte_count;
  struct termios oldtio,newtio;
 byte_count = strlen(com1);

 fd = open(PORT1, O_RDWR | O_NOCTTY | O_NDELAY );
 if (fd <0) {perror(PORT1); exit(-1); }
 tcgetattr(fd,&oldtio); /* save current serial port settings */
 bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */


 newtio.c_cflag = BAUDRATE | CRTSCTS | CS7 | CLOCAL | CREAD | PARENB |
CSTOPB;

 newtio.c_iflag = 0;

 newtio.c_oflag = 0;

 newtio.c_lflag = 0;

 tcsetattr(fd,TCSADRAIN,&newtio);

 c =  write(fd,com1,byte_count);



}


----- Original Message -----
From: "Francis James Whittle" <fudje at phreaker.net>
To: "caloy diaz" <caloykoy_one at pacific.net.ph>
Cc: <inux at lists.samba.org>
Sent: Tuesday, February 24, 2004 7:17 PM
Subject: Re: [clug] modifying serial.c


> On Tue, 2004-02-24 at 21:40, caloy diaz wrote:
> > it's more of a requirement that i be able to write a modularized driver
for
> > it. i'm really kind of scared because i'm a beginner in Linux. i've
heard
> > that i should just modify the serial.c code because there's a section
there
> > where the code sort of creates this flag where the baud rates parity
stop
> > bits etc can be set by whoever wants to use the serial driver. so i'm
> > thinking then maybe i should just sort of "fix" those values to those of
the
> > robot arm's. would it be better if i send the c code we use to control
the
> > arm?
>
> I would suggest that rather than modify serial.c, you could actually
> write the driver to access the arm through the serial device driver.
> This will create a lot less headaches in the modularity department.
>
> Although I do agree with Martin, there is no real point in writing this
> as a device driver at all....




More information about the linux mailing list