Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binary data over serial terminal

My only way of communication with my embedded device is a serial port. By default, embedded Linux uses this port as a terminal. How do I disable this terminal and use the serial link to transfer binary data? I heard of commands like rx and tx but i cannot find them.

I think I can just read() from and write() stuff to /dev/tty but I want to make sure no error messages or whatever mess with my data stream.

like image 315
Atilla Filiz Avatar asked Feb 03 '09 11:02

Atilla Filiz


2 Answers

Can't you just set the terminal to raw?

Have a look at this tutorial.

like image 38
dsm Avatar answered Sep 26 '22 23:09

dsm


You can use an application like xmodem to transfer file over any terminal. Is the serial port you speak off a terminal, or is it also the kernel console.

If you're kernel is not noisy, then you can use your current connection to make xmodem like transfer. On the host side, you can use kermit, which is nice AND scriptable.

If you want to make your serial port raw, and you have file descriptor ttyfd opened, here is one way to do it :

struct termios tty, orig_tty;

...

if(tcgetattr(ttyfd, &tty) < 0)
{
    // error checking
}
// backup tty, make it raw and apply changes
orig_tty = tty;
cfmakeraw(&tty);
if(tcsetattr(ttyfd, TCSAFLUSH, &tty) < 0)
{
    // error checking
}

...
//end of program or error path :
tcsetattr(ttyfd, TCSAFLUSH, &orig_tty)

Don't forget to restore the setting at the end of your program if you still want a good behaved terminal.

like image 111
shodanex Avatar answered Sep 24 '22 23:09

shodanex