Erro in USB Serial --- Wrong data received on windows xp

Hi,

I am trying to pass float data from 1.0 to 200.0 in increment of 1.0
(for testing, actual data will be real float numbers)
through usb gadget serial drive of beagle board to windows xp host

speed is 115200 and 8N1 is the protocol

I find that data 1.0 to 137.0 is received on the Windows perfectly but
after that data suddenly becomes wrong and extra character is added in
the receiving side and the actual data again starts coming but now the
order of characters received is lost and wrong float data is
interpreted.....

I will explain how :

for 137 on receiver side I get : (00 00 09 43) as float in hex in
reverse order

for 138 i suddenly get : (00 00 0D 0A) in place of (00 00 0A 43)

and then 139 I get : (43 00 00 0B) --- in place of (00 00 0B 43)

and then 140 I get : (43 00 00 0C) ... in place of (00 00 0C 43) ...
so the track is lost due to corrupt data being added during 138 i.e.
0D

Please help if some one has received this problem earlier

This is the code :

///////////////////////////////////////////// main program
begins /////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void main()
{

//clrscr();
int N = 4000000;
char *ptr;
float *x;

int i,bytes_written;
float j=1.0;
double cpu_time_used;
clock_t start,end;

size_t len = 0;

x = (float*) malloc(sizeof(float)*N);

*x = 1.0;

for (i=0;i<=(N/4 - 1);i++)
{
  *(x+i)=j;
  j = j+1.0;
}

len = (N/5000);

ptr=(char*)x;

x = (float*)ptr;

serial_port_open();

// Assign a handler to close the serial port on Ctrl+C.

signal (SIGINT, (void*)sigint_handler);
start = clock();

//for(i=0; i<=2; i++)
//{

bytes_written = write(serial_port, ptr, len);

if (bytes_written < len)
  printf("Write failed %d\n", i);

//ptr = ptr + 400;

//usleep(10000);

//}

end = clock();

cpu_time_used = ((double) (end - start));
printf("cpu time used = %lf",cpu_time_used);
printf("successful transfer operation");
return 0;

free (x);
}

//////////////////////////////////////////////// main program
ends /////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Resets the terminal and closes the serial port.

void serial_port_close()
{
  tcsetattr(serial_port,TCSANOW,&options_original);
  close(serial_port);
}

// Opens a USB virtual serial port at ttyUSB0.
//
// returns - the port's file descriptor or -1 on error.

int serial_port_open(void)
{
  struct termios options;

  serial_port = open(PORT_NAME, O_RDWR | O_NONBLOCK);

  if (serial_port != -1)
  {
    printf("Serial Port open\n");
    tcgetattr(serial_port,&options_original);
          bzero(&options, sizeof(options));
    tcgetattr(serial_port, &options);
    cfsetispeed(&options, B115200);
    cfsetospeed(&options, B115200);
    options.c_cflag |= (CLOCAL | CREAD);
    options.c_lflag |= ICANON;
    tcsetattr(serial_port, TCSANOW, &options);
  }
  else
    printf("Unable to open /dev/ttyGS0\n");
  return (serial_port);
}

// Attempts to read up to 10 bytes from the serial port.
// If data was read, calls a routine to examine the received data
// and take action.
// *read_buffer - the buffer that will contain the data read.
// returns - 0 if data was received, -1 if no data received.

int serial_port_read(char *read_buffer)
{
  if ( read(serial_port, read_buffer, MAX_COMMAND_LENGTH) > 0)
  {
    return 0;
  }
  else
    return -1;
}

// Writes data to the port.
// Parameter: write_buffer - the data to write to the port.
// *write_buffer - the buffer that contains the data to write.

void serial_port_write(char *write_buffer)
{
  int bytes_written;
  size_t len = 0;

  len = strlen(write_buffer);
  bytes_written = write(serial_port, write_buffer, len);
  if (bytes_written < len)
    printf("Write failed \n");
}

// Executes when the user presses Ctrl+C.
// Closes the port, resets the terminal, and exits the program.

void sigint_handler(int sig)
{
  serial_port_close();
  exit (sig);
}

mohit hada wrote:

Hi,

I am trying to pass float data from 1.0 to 200.0 in increment of 1.0
(for testing, actual data will be real float numbers)
through usb gadget serial drive of beagle board to windows xp host

speed is 115200 and 8N1 is the protocol

I find that data 1.0 to 137.0 is received on the Windows perfectly but
after that data suddenly becomes wrong and extra character is added in
the receiving side and the actual data again starts coming but now the
order of characters received is lost and wrong float data is
interpreted.....

I will explain how :

for 137 on receiver side I get : (00 00 09 43) as float in hex in
reverse order

for 138 i suddenly get : (00 00 0D 0A) in place of (00 00 0A 43)

I guess thats DOS/windows and its stupid "text" mode where is converts
0x0A to 0x0D 0x0A...

I guess thats DOS/windows and its stupid “text” mode where is converts
0x0A to 0x0D 0x0A…


You received this message because you are subscribed to the Google Groups “Beagle Board” group.
To post to this group, send email to beagleboard@googlegroups.com.
To unsubscribe from this group, send email to beagleboard+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

But we are reading characters converting them in float using java program or through a software called Real Term… both give the same result…

we don’t read through hyperterminal…

mohit hada wrote:

    I guess thats DOS/windows and its stupid "text" mode where is converts
    0x0A to 0x0D 0x0A...

    --
    You received this message because you are subscribed to the Google Groups "Beagle Board" group.
    To post to this group, send email to beagleboard@googlegroups.com <mailto:beagleboard@googlegroups.com>.
    To unsubscribe from this group, send email to beagleboard+unsubscribe@googlegroups.com
    <mailto:beagleboard%2Bunsubscribe@googlegroups.com>.
    For more options, visit this group at http://groups.google.com/group/beagleboard?hl=en.

But we are reading characters converting them in float using java program or through a software called Real Term....
both give the same result...

and you are sure your java program opens the stream in "binary" mode?

Dude,
I have a simple doubt, i have read that the signals that come out of BeagleBoard are TTL signals , they have to be lifted up to rs-232 level, may be using a max-232 level converter.
I may not be right,
Guy, I have a similar omap350 board,
I want to write an simple shell script to send data from uart3 of the omap3530 and read it on my computer.
But, i am afraid the logic levels are not same, its 1.8v on the Board side, Please tell me what should i do ?

Thanks and regards,
bumble

*PREVIOUS MESSAGE HAS LOTS OF TYPOS… PLEASE READ THIS

Dude,I have a simple doubt, i have read that the signals that come out of BeagleBoard are TTL signals , they have to be lifted up to rs-232 level, may be using a max-232 level converter.
I may not be right,
Guys, I have a similar omap3530 board,
I want to write an simple shell script to send data from uart3 of the omap3530 and read it on my computer.
But, i am afraid the logic levels are not same, its 1.8v on the Board side, Please tell me what should i do ?

Thanks and regards,
bumble

Hi, vladimir,

it happens only on selective numbers i.e. if I give float 138.0 continuously, it will show errors in all received 138…

similarly other selective numbers… it continues…

regards

Mohit

bumble omap wrote:

Dude,
I have a simple doubt, i have read that the signals that come out of BeagleBoard are TTL signals , they have to be
lifted up to rs-232 level, may be using a max-232 level converter.
I may not be right,
Guy, I have a similar omap350 board,
I want to write an simple shell script to send data from uart3 of the omap3530 and read it on my computer.
But, i am afraid the logic levels are not same, its 1.8v on the Board side, Please tell me what should i do ?

Thanks and regards,
bumble

Dude!

learn to ask questions properly on mailing lists. This one has the subject:
"Error in USB Serial --- Wrong data received on windows xp"

mohit hada wrote:

Hi, vladimir,

it happens only on selective numbers i.e. if I give float 138.0 continuously, it will show errors in all received 138.....

in: 00 00 09 43 00 00 0A 43 00 00 0B 43 00 00 0C 00 00 0C 43
out: 00 00 09 43 00 00 0D 0A 43 00 00 0B 43 00 00 0C 00 00 0C 43

do you see where 0x0A became 0x0D 0x0A?

this mailing list is about the Beagleboard,
not Windows XP, not java and not Real Term

yeah i see ever 0x0A preceeded by 0x0D…

mohit hada wrote:

Hi, vladimir,

it happens only on selective numbers i.e. if I give float 138.0 continuously, it will show errors in all received 138…

in: 00 00 09 43 00 00 0A 43 00 00 0B 43 00 00 0C 00 00 0C 43
out: 00 00 09 43 00 00 0D 0A 43 00 00 0B 43 00 00 0C 00 00 0C 43

do you see where 0x0A became 0x0D 0x0A?

this mailing list is about the Beagleboard,
not Windows XP, not java and not Real Term

Dear vladimir, i am not sure whether I am having problem on BB side or PC side, so I have explain the entire scenario to see where the fault is…

I think Java is taking in text mode…

sorry Vladimir and everyone else.

i was a bit informal…

Please help me out…

Thanks.
bumble…

Actually i mean for the same subject…
i thought ,May be mohit has faced the problem because of the logic level intricacies.

Sorry, if i was out of context…
And i will post it separately,

Thanks…
bumble…