vinayby
Newbie level 4
HI all,
a simple problem but has been troubling me since long..
trying to test serial port in Loopback mode.. normally simple transmit works
here is the https://www.captain.at/howto-simple-serial-port-test-example.php
and myversion of the code..
help would be appreciated.. ( i wonder if loopback is supported atall in linux!)
------code--
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <asm-ppc/delay.h>
#include<asm-ppc/termios.h>
uint8 WriteString[255];
uint8 ReadString[30];
unsigned char EndChar[] = {0x0d};
main()
{
int dev_tty2;
uint8 BytesWritten = 0;
uint8 ReadChars = 0;
uint8 BytesRead = 0;
uint8 Index;
uint8 Loop;
dev_tty2 = open("/dev/ttl1", O_RDWR);
if(dev_tty2 < 0)
{
printf("Cannot open the COM2 Port\n");
return -1;
}
Loop = 0;
do
{
printf("Loop %d\n", Loop);
for(Index = 0; Index < 4; Index++)
ReadString[Index] = '1' + Loop;
ReadString[Index] = 0x0D;
ReadString[Index + 1] = 0x00;
Loop++;
ReadChars = Index + 1;
for(Index = 0; Index < 4; Index++)
printf("%c", ReadString[Index]);
BytesWritten = write(dev_tty2, ReadString, ReadChars);
printf("\n Chars written to port = %d\n", ReadChars);
sleep(2);
BytesRead = pread(dev_tty2, WriteString, 255, 5);
printf("\n No of chars read from port= %d\n", BytesRead);
for(Index = 0; Index < 254; Index++)
{
printf("%c", WriteString[Index]);
}
/* tcflush(dev_tty2, TCOFLUSH);*/
/* tcflush(dev_tty2, TCIFLUSH);*/
sleep(2);
/*getchar();*/
}while ( Loop < 2);
return 0;
}
------------
---output---
# ./uartl
Loop 0
1111
Chars written to port = 5
No of chars read from port= 5
1111
Loop 1
2222
Chars written to port = 5
No of chars read from port= 5
1111 ----> 2222 is expected here..
#
------------------------
a simple problem but has been troubling me since long..
trying to test serial port in Loopback mode.. normally simple transmit works
here is the https://www.captain.at/howto-simple-serial-port-test-example.php
and myversion of the code..
help would be appreciated.. ( i wonder if loopback is supported atall in linux!)
------code--
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <asm-ppc/delay.h>
#include<asm-ppc/termios.h>
uint8 WriteString[255];
uint8 ReadString[30];
unsigned char EndChar[] = {0x0d};
main()
{
int dev_tty2;
uint8 BytesWritten = 0;
uint8 ReadChars = 0;
uint8 BytesRead = 0;
uint8 Index;
uint8 Loop;
dev_tty2 = open("/dev/ttl1", O_RDWR);
if(dev_tty2 < 0)
{
printf("Cannot open the COM2 Port\n");
return -1;
}
Loop = 0;
do
{
printf("Loop %d\n", Loop);
for(Index = 0; Index < 4; Index++)
ReadString[Index] = '1' + Loop;
ReadString[Index] = 0x0D;
ReadString[Index + 1] = 0x00;
Loop++;
ReadChars = Index + 1;
for(Index = 0; Index < 4; Index++)
printf("%c", ReadString[Index]);
BytesWritten = write(dev_tty2, ReadString, ReadChars);
printf("\n Chars written to port = %d\n", ReadChars);
sleep(2);
BytesRead = pread(dev_tty2, WriteString, 255, 5);
printf("\n No of chars read from port= %d\n", BytesRead);
for(Index = 0; Index < 254; Index++)
{
printf("%c", WriteString[Index]);
}
/* tcflush(dev_tty2, TCOFLUSH);*/
/* tcflush(dev_tty2, TCIFLUSH);*/
sleep(2);
/*getchar();*/
}while ( Loop < 2);
return 0;
}
------------
---output---
# ./uartl
Loop 0
1111
Chars written to port = 5
No of chars read from port= 5
1111
Loop 1
2222
Chars written to port = 5
No of chars read from port= 5
1111 ----> 2222 is expected here..
#
------------------------