Hi,
we tried to communicate between the PortuxG20 and a PC.
We are programming with eclipse in C and try communication over the serial port of portuxG20. (Remote Debugging over SSH)
After opening ttyS2 successfully, the following write command fails:
if (write(fd, "0\r", 2) < 2)
return -2;
We're using the following options:
fd = open("/dev/ttyS2", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
perror("open_port: Fehler beim Öffnen von: /dev/ttyS0 - ");
return -1; /* Kann Port nicht öffnen */
}
else
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &options); /* Get the current options for the port... */
cfsetispeed(&options, B115200); /* Set the baud rates to 115200... */
cfsetospeed(&options, B115200);
options.c_cflag |= (CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_oflag &= ~OPOST;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 10;
tcsetattr(fd, TCSANOW, &options); /* Set the new options for the port... */
Are there any hints?
With best regards
Mike

Re: PortuxG20: can't write to ttyS2
Please change your code the following to better debug this error:
if ((ret = write(fd, "0\r", 2) < 2) { if (ret < 0) perror("write failed"); printf("ret: %d\n", ret); }Please post the result here.
Re: PortuxG20: can't write to ttyS2
The result of ret is -1
The program is running correct on the development pc (with ttyS0).
I have changed ttyS0 to ttyS2 to avoid conflicts with the debugging channel.
Maybe this helps?
Re: PortuxG20: can't write to ttyS2
And what was the output of perror?
Can you try the following (after a reboot):
connect ttyS2 of PortuxG20 with your serial port of your PC. Change the settings of your termial program to 9600B (without the DBGU Adapter), log into the portux with ssh and type the following to test the serial port:
Now you should see a portux on your terminal. Then type the following on your ssh shell:
and type some characters on your terminal at the pc, these should appear now on the portux side.
BTW, the serial port in the front is ttyS3, not ttyS2, this is one of the IF ports, which are in LVTTL levels (3.3V) and won't work without RS232 level shifting.
Re: PortuxG20: can't write to ttyS2
The output of perror is "write failed: Input/output error".
The connection between portux and my pc works fine - all the tests you recommended were successfull.
I've tried these connection settings in my c-Programm (with 9600 Baud on ttyS3) - but the same error occures.
Re: PortuxG20: can't write to ttyS2
Maybe leaving out O_NDELAY and/or tcsetattr helps, at least to diagnose where the error comes from.
Re: PortuxG20: can't write to ttyS2
Hi,
after deleting the O_NDELAY it seams the write command is correct. But we already don't receive any data at our terminal. Also we don't receive any data from our terminal in our program.
The data we receive in the tcgetattr(fd, &options) command seems to be random (eg c_ispeed=12) - maybe the open command is already wrong?
Re: PortuxG20: can't write to ttyS2
If your port works with echo and cat, start programming by just open / close and read/write from your port. Leave beside all extra settings and features. This would be what cat and echo do. From there you can start to enable features as you like step by step to configure your port according to your needs.
You can gain a lot of information on the flags and their meanings in this excellent how-to:
http://www.easysw.com/~mike/serial/serial.html
These two may be also useful:
http://tldp.org/HOWTO/Serial-HOWTO.html
http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html
Re: PortuxG20: can't write to ttyS2
We have solved the problem by using the Angstrom-toolchain and setting up the remote connection as descriped in your documentation. Now ttyS3 works correct.
Thank you for your support.