need a sample code

hai all This is my first post to this group.I am very much new to embedded programming .Now i want to write data to com1 and want to read from com2 .Here i have connected a NULL-MODEM cable in between the two serial ports. The following is the code,which i am running on my Linux Box. I am getting the return value from read as -1.

#include #include #include #include #include #include

main() { int fd[2],n; char buff[4];

fd[0]=open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY); fd[1]=open("/dev/ttyS1",O_RDWR | O_NOCTTY | O_NDELAY); if (fd[0] || fd[1]

Reply to
emb in linux
Loading thread data ...
070906020105040002000405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit

Hi,

emb > hai all

I haven't analyzed your code, but hereafter you will find an example that works for me. I have separated the sending and the receiving parts in two separate processes, each with its own source file and binary. I start the receiving part first, and it receives the character from the sending part when I start it later on.

Good luck,

Alain

Sending part:

#include /* Standard input/output definitions */ #include /* String function definitions */ #include /* UNIX standard function definitions */ #include /* File control definitions */ #include /* Error number definitions */ #include /* POSIX terminal control definitions */

int main() { int fd; /* File descriptor for the port */ struct termios options;

/* * Open the first serial port, read/write, no controlling terminal, * not care about the Data Carrier Detect signal */ fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { /* * Could not open the port. */ perror("Unable to open /dev/ttyS0\n"); } else { /* * Set all flags to 0 for the read call to be blocking!??? * (according to "Serial Programming Guide for POSIX Operating Systems") */ fcntl(fd, F_SETFL, 0);

/* * Get the current options for the port... */ tcgetattr(fd, &options);

/* * Set the baud rates to 115200... */ cfsetispeed(&options, B115200); cfsetospeed(&options, B115200);

/* * Enable the receiver and set local mode... */ options.c_cflag |= (CLOCAL | CREAD);

/* * Set the option for 8N1 */ options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8;

/* * Set the option for raw input */ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

/* * Set the option for raw output */ options.c_oflag &= ~OPOST;

/* * Set the new options for the port... */ tcsetattr(fd, TCSANOW, &options);

if (write(fd,"A",1)

Reply to
Alain Mosnier

And what does errno/perror() say ?

PS: The code appears to have been typed in (misspelling of abort() as abrot())

Try pasting the _actual_ source code.

Simon.

--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP       
Microsoft: The Standard Oil Company of the 21st century
Reply to
Simon Clubley

hai

1st of all thanks for your sample code. i want to check my comports on the same system.i am getting receive program as "IN SERVER",but not getting the byte.how to acheive that!what might be the wrong here! waiting for ur reply with regards emb in linux.
Reply to
emb in linux

hai thanks for your code . i have acheived my startup task comports. once again thanks for your help.

with regards emb in linux

Reply to
emb in linux

Reply to
emb in linux

emb in linux wrote: hi using fgets i am able to do that.

Reply to
emb in linux

hello Alain can i do this more interactivelly. i did the following excercises.

1.i have open a port and a send a byte then closed it .By using receive program i opened other port read the charecter .(in between null modem cable is there) 2.same as above with string. 3.same as above with mutiple strings(sentence)

now i want do this little bit interactivelly. i will open ttyS0 and give a byte from keyboard and the same byte i have to recive from ttyS1 without closing ttyS0.here is it possible! if u have any suggesstions please help me out. thanks in advance.

with regards

emb in linux.

Reply to
emb in linux

A I said in my answer to the email to sent me directly:

To be honest I'm not sure whether I will have the time to help you out. My advice is to post your code on the mailing list and ask questions as specific as possible. Attach printouts from your program too. I guess if you post your code, explain what you expect, and also post what you get (exact printout from your program), people on the list will help you out. On the other hand, I don't think you should expect that people will give you code to answer your questions. In my case, you were lucky that I had a litle sample at hand when I read your message.

Best regards,

Alain

Reply to
Alain Mosnier

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.