Hi,
I used a MOD5213 talk to a device through RS232 (UART 1). MOD5213 sent a command to the device and device feedback status. MOD5213 will write feedback status on UART 0. Problem is: when MOD5213 read the feedback from the device (on UART1), it sent back the readout content to the device (on UART1), which caused problem. I use NBEClipse and the code is as follow:
{
SimpleUart(1, 19200); // Initialize UART1
writestring(1, "GetStatus\r\n"); // Send command to UART1
OSTimeDly(2);
assign_stdio(1);
if ( charavail(1) ) // Listen to UART1
{
gets(buffer); // Read UART1 if feedback detected
assign_stdio(0);
}
else
{
assign_stdio(0);
writestring(0, "Communication ERROR\r\n");
return 1;
}
writestring(0, buffer); // Write device feedback value to UART0
writestring(0, "\r\n");
}
Thanks.
MOD5213: RS232 communication
Re: MOD5213: RS232 communication
Look at the function "int ioctl( int fd, int cmd );" in:
C:\nburn\include_nn\iosys.h
STDIN FD = 0
STDOUT FD = 1
STDERR FD = 2
So all you need to turn off echo on stdin:
#include <iosys.h>
...
ioctl( 0, IOCTL_CLR | IOCTL_RX_ECHO );
Also it is not a good idea to keep swapping stdio between ports like you are doing. The inner workings of the stdio library must manipulate the data before sending it to the UART buffer. By swapping stdio you open up the possibility that not all the stdio data makes it to the correct UART buffer before you swap. I believe if you keep all the swapping in the same task you should be OK but you will definitely run into problems if you start swapping stdio in mutliple tasks without some sort of flush before the swap.
The safer method of using stdio with multiple UARTs is to create file pointers to the UARTs:
FILE *create_file( int portnum );
You can then use the file stdio function on this file such as fprintf or fgets without having to swap your stdio UART.
-Larry Gitlitz
C:\nburn\include_nn\iosys.h
STDIN FD = 0
STDOUT FD = 1
STDERR FD = 2
So all you need to turn off echo on stdin:
#include <iosys.h>
...
ioctl( 0, IOCTL_CLR | IOCTL_RX_ECHO );
Also it is not a good idea to keep swapping stdio between ports like you are doing. The inner workings of the stdio library must manipulate the data before sending it to the UART buffer. By swapping stdio you open up the possibility that not all the stdio data makes it to the correct UART buffer before you swap. I believe if you keep all the swapping in the same task you should be OK but you will definitely run into problems if you start swapping stdio in mutliple tasks without some sort of flush before the swap.
The safer method of using stdio with multiple UARTs is to create file pointers to the UARTs:
FILE *create_file( int portnum );
You can then use the file stdio function on this file such as fprintf or fgets without having to swap your stdio UART.
-Larry Gitlitz
Re: MOD5213: RS232 communication
Hi Larry,
Thanks for the reply. I tried to use ioctl( 0, IOCTL_CLR | IOCTL_RX_ECHO ) in my program, but there is an Error during compiling: undefined reference to `ioctl(int, int)'
I included <iosys.h>
Thanks,
Yi
Thanks for the reply. I tried to use ioctl( 0, IOCTL_CLR | IOCTL_RX_ECHO ) in my program, but there is an Error during compiling: undefined reference to `ioctl(int, int)'
I included <iosys.h>
Thanks,
Yi
Re: MOD5213: RS232 communication
It looks like there was a bug that is corrected in the newer version of the NNDK release. This function is written in a C file but you are using them in a C++ file. This is fine but you must do an extern "C" to avoid the C++ name mangling.
An easy way to do this is to add the following to the beginning of the iosys header file:
#ifdef __cplusplus
extern "C"
{
#endif
Then add the following at the end of the iosys header file:
#ifdef __cplusplus
}
#endif
An easy way to do this is to add the following to the beginning of the iosys header file:
#ifdef __cplusplus
extern "C"
{
#endif
Then add the following at the end of the iosys header file:
#ifdef __cplusplus
}
#endif