Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

Khr1 Serial Comunication on linux and C

KHR-1, KHR-2HV, KHR-3HV, ICS servos, RCB controllers and other Kondo products
7 postsPage 1 of 1
7 postsPage 1 of 1

Khr1 Serial Comunication on linux and C

Post by pandolio » Wed Jul 05, 2006 8:40 am

Post by pandolio
Wed Jul 05, 2006 8:40 am

Hi for all.

I'm working in a C program to control my KHR-1 robot on linux.

Now, i only send a "Play Motion" function to my Khr1, and sometimes he plays the motions, but no always. I know that it isn´t a problem, because i have to wait for a reponse for the khr1, and then i know if he is playing the motion.

The problem is that he never response. I think that the configuration of the port it´s right (sometimes he plays the motions) but on linux, there is more parameter that on windows for the configuration of the serial port, like the canonical comunication...

Someone know something about this and what it´s the problem?

Some code example:

for write on the port:
/*Funcion que escribe en el puerto serie*/
int escribir(int IDpuerto, struct TX *accion)
{
int res;

printf("voy a escribir...");

res = write(IDpuerto,accion,sizeof(struct TX) );

if ( res > 0 ) //Todo ha ido bien
{
printf("HE ESCRITO EN EL PUERTO %d bytes\n",res);
return TRUE;
}
else
{
return FALSE;
}
}

for read for the port:
/* Funcion que lee del puerto serie
* Devuelve 1 si ha leido bien y en la variable lectura devuelve lo que ha leido*/
int leer(int IDpuerto, struct RX *lectura)
{
int res;

printf("Voy a leer...\n");

res = read(IDpuerto,lectura,sizeof(struct TX));

printf("Leidos %d bytes del puerto\n", res);

if ( res > 0 ) //Todo ha ido bien
{
printf("LEIDO EN RX %d bytes y son esto: %s\n",res,lectura);
return TRUE;
}
else
{
return FALSE;
}
}

for configure the port:
int puerto;
struct termios newtio;

/* Obtenemos la configuracion del puerto serial */
puerto = open(SERIALPORT, O_RDWR | O_NOCTTY );
tcgetattr(puerto,&oldtio);

/* inicializamos el struct de la nueva configuracion del puerto*/
bzero(&newtio, sizeof(newtio));

newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;

/* now clean the modem line and activate the settings for the port */
tcflush(puerto, TCIFLUSH);

/* se actualiza la configuracion del puerto */
tcsetattr(puerto,TCSANOW,&newtio)

return puerto;



thank you.

¡Hasta otra! (that is spanish)

I´m from spain and my english is bad, i´m sorry.
:oops:
Hi for all.

I'm working in a C program to control my KHR-1 robot on linux.

Now, i only send a "Play Motion" function to my Khr1, and sometimes he plays the motions, but no always. I know that it isn´t a problem, because i have to wait for a reponse for the khr1, and then i know if he is playing the motion.

The problem is that he never response. I think that the configuration of the port it´s right (sometimes he plays the motions) but on linux, there is more parameter that on windows for the configuration of the serial port, like the canonical comunication...

Someone know something about this and what it´s the problem?

Some code example:

for write on the port:
/*Funcion que escribe en el puerto serie*/
int escribir(int IDpuerto, struct TX *accion)
{
int res;

printf("voy a escribir...");

res = write(IDpuerto,accion,sizeof(struct TX) );

if ( res > 0 ) //Todo ha ido bien
{
printf("HE ESCRITO EN EL PUERTO %d bytes\n",res);
return TRUE;
}
else
{
return FALSE;
}
}

for read for the port:
/* Funcion que lee del puerto serie
* Devuelve 1 si ha leido bien y en la variable lectura devuelve lo que ha leido*/
int leer(int IDpuerto, struct RX *lectura)
{
int res;

printf("Voy a leer...\n");

res = read(IDpuerto,lectura,sizeof(struct TX));

printf("Leidos %d bytes del puerto\n", res);

if ( res > 0 ) //Todo ha ido bien
{
printf("LEIDO EN RX %d bytes y son esto: %s\n",res,lectura);
return TRUE;
}
else
{
return FALSE;
}
}

for configure the port:
int puerto;
struct termios newtio;

/* Obtenemos la configuracion del puerto serial */
puerto = open(SERIALPORT, O_RDWR | O_NOCTTY );
tcgetattr(puerto,&oldtio);

/* inicializamos el struct de la nueva configuracion del puerto*/
bzero(&newtio, sizeof(newtio));

newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;

/* now clean the modem line and activate the settings for the port */
tcflush(puerto, TCIFLUSH);

/* se actualiza la configuracion del puerto */
tcsetattr(puerto,TCSANOW,&newtio)

return puerto;



thank you.

¡Hasta otra! (that is spanish)

I´m from spain and my english is bad, i´m sorry.
:oops:
pandolio
Newbie
Newbie
User avatar
Posts: 5
Joined: Wed Jul 05, 2006 1:00 am

Post by inaki » Wed Jul 05, 2006 9:02 am

Post by inaki
Wed Jul 05, 2006 9:02 am

You must set DTR line to LOW. Otherwise you will not receive any data.
You must set DTR line to LOW. Otherwise you will not receive any data.
inaki
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 233
Joined: Sun Mar 06, 2005 1:00 am
Location: EH

how to set DTR line to low on linux?

Post by pandolio » Mon Jul 10, 2006 9:37 am

Post by pandolio
Mon Jul 10, 2006 9:37 am

Hi again,

I was reading about the DTR line, but i´m not sure how to set DTR line to low and why i have to do it.

It seem like if i had to change the DTR line for read and wirte continuosly. is it true?.

Could you tell me how to set the DTR line to low?.

Thank you very much...
Hi again,

I was reading about the DTR line, but i´m not sure how to set DTR line to low and why i have to do it.

It seem like if i had to change the DTR line for read and wirte continuosly. is it true?.

Could you tell me how to set the DTR line to low?.

Thank you very much...
pandolio
Newbie
Newbie
User avatar
Posts: 5
Joined: Wed Jul 05, 2006 1:00 am

Post by inaki » Mon Jul 10, 2006 7:46 pm

Post by inaki
Mon Jul 10, 2006 7:46 pm

Theoretically you should put DTR to LOW ony for reading but actually you can leave it LOW just after communication starts. DTR line can be put to LOW by means of an Escape function, like EscapeCommFunction in Windows.
Theoretically you should put DTR to LOW ony for reading but actually you can leave it LOW just after communication starts. DTR line can be put to LOW by means of an Escape function, like EscapeCommFunction in Windows.
inaki
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 233
Joined: Sun Mar 06, 2005 1:00 am
Location: EH

DTR again!!

Post by pandolio » Tue Jul 11, 2006 2:31 pm

Post by pandolio
Tue Jul 11, 2006 2:31 pm

Hi, i was loking more about DTR and linux. It seem like if DTR it's not supported by linux. the manual say... maybe it will be supported in the future, or could have a driver for it.

Someone have a api on linux?. C or other languaje, it's only for know if it's possible.

Maybe some of the API's could run on linux... i don't know...

Thanks for all.
Hi, i was loking more about DTR and linux. It seem like if DTR it's not supported by linux. the manual say... maybe it will be supported in the future, or could have a driver for it.

Someone have a api on linux?. C or other languaje, it's only for know if it's possible.

Maybe some of the API's could run on linux... i don't know...

Thanks for all.
pandolio
Newbie
Newbie
User avatar
Posts: 5
Joined: Wed Jul 05, 2006 1:00 am

Post by limor » Tue Jul 11, 2006 8:14 pm

Post by limor
Tue Jul 11, 2006 8:14 pm

running by google the terms: dtr linux driver serial
i get a lot of links. The "Serial Howto" document clearly states that there is support for setting DTR as of kernel 2.4 and that you can test it with command line
stty -F /dev/ttyS1 -a
and check for the clocal value.
dont have a linux installed with me to test this at the moment..
running by google the terms: dtr linux driver serial
i get a lot of links. The "Serial Howto" document clearly states that there is support for setting DTR as of kernel 2.4 and that you can test it with command line
stty -F /dev/ttyS1 -a
and check for the clocal value.
dont have a linux installed with me to test this at the moment..
limor
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1845
Joined: Mon Oct 11, 2004 1:00 am
Location: London, UK

Post by DanAlbert » Sat Jul 15, 2006 11:03 pm

Post by DanAlbert
Sat Jul 15, 2006 11:03 pm

I posted on this problem somewhere else in this forum.

I'll bet either you are not using the KHR-1 cable or you have no signal control on the DTR pin. There is a 10k resistor inside the cable. It connects the DTR to the receive line. Without it you will most likely not see a response even though the robot gets the command.
I posted on this problem somewhere else in this forum.

I'll bet either you are not using the KHR-1 cable or you have no signal control on the DTR pin. There is a 10k resistor inside the cable. It connects the DTR to the receive line. Without it you will most likely not see a response even though the robot gets the command.
DanAlbert
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 70
Joined: Fri Feb 04, 2005 1:00 am


7 postsPage 1 of 1
7 postsPage 1 of 1