Sponsored Content
Top Forums Programming Wrong data with Read from a serial port. Post 302732901 by enaud on Monday 19th of November 2012 10:33:00 AM
Old 11-19-2012
i've doing:

Code:
every 2ms:


    ioctl(fd, FIONREAD, &bytes_avaiable);
    static int i=0;
    array[i]=bytes_avaiable;

    if (bytes_avaiable<=310 && i>=10 && array[i]==array[i-1] && array[i]==array[i-2]
            && array[i]==array[i-3] && array[i]!=0){
        
        iIn = read(fd, array_uart2, sizeof(array_uart2));
        aggiorna1();
    }

    i++;
    if (i==400){
        i=0;
    }



void cClassSerialLIB::aggiorna1(){
    int n_samples=0;
    int m_pos;

    unsigned char buffer[4000];
    for (int i=0;i<4000;i++)
        buffer[i]='\0';

    int counter=0;


for (int j=0;j<6000;j++){
   n_samples=array_uart2[j+7];//numero sample.
   int len_payload=array_uart2[j+3];
   m_pos=len_payload+5;
   if (array_uart2[j]=='M' && array_uart2[j+1]=='A'&& array_uart2[j+2]=='M'&& array_uart2[j+5]==128 && array_uart2[j+m_pos]=='m'/*&& Buffer_temp[j+6]==7*/){
      qDebug("\t Sequence Number %d,%d,%d,%d\t",array_uart2[9],array_uart2[10],array_uart2[11],array_uart2[12]);
      counter=0;
      for (int i=0;i<4000;i++)
           buffer[i]=array_uart2[i];


      QString str="";
      QString temp="";
      int num_byte=n_samples*3/2; //numero_byte
      for(int i=j+13; i<j+num_byte+13; i+=3){
          int b0_msb= buffer[i];//8bit
          unsigned short shift_dx_b0msb = b0_msb<<4;
          int b0_lsb= buffer[i+1] & 0xF0;//4bit
          unsigned short shift_dx_b0lsb = b0_lsb>>4;
          unsigned short first_sample=shift_dx_b0msb|shift_dx_b0lsb;
          int b1_msb= buffer[i+1] & 0x0F;//4bit
          unsigned short shift_dx_b1msb = b1_msb<<8;
          int b1_lsb= buffer[i+2];			//8bit
          unsigned short shift_dx_b1lsb = b1_lsb;//>>4;
          unsigned short second_sample=shift_dx_b1msb|shift_dx_b1lsb;
          //str="";//gius
          str = QString("%1,%2").arg(first_sample).arg(second_sample);
          temp.append(str);
          temp.append(", ");
      }//chiusura for


      qDebug()<<temp;
      for (int i=0;i<6000;i++)
                array_uart2[i]='\0';

}//chiusura if


    else{
        counter++;
       }


  }
  qDebug()<<counter;
}

 

9 More Discussions You Might Find Interesting

1. Linux

Urgent - serial port

Hi All, I am a begineer in Linux, I have 4 ports and 3 are operational port 1,port 2 and port 4 (when I plug in serial device I can see it working) but port 3 seems it is not working. I am sure the hardware is fine. when I give command dmesg | grep tty I get, serial 8250:ttyS0 at... (0 Replies)
Discussion started by: vr_82
0 Replies

2. SCO

data transfer from serial port

dear sir, pls. can you help me ? , my os is unix sco 5.0.4 and ,server dat derive (1,4gb) not working, now i want to transfer my server data in other machine (unix/other possible) by serial port/other port comminication. thanks pankaj raval (2 Replies)
Discussion started by: pankajbraval
2 Replies

3. Programming

Problem with read data from serial device

I have problem with C programming. I want to send & receive data through serial communication. I send data(command) to device to get data from device but when receive data, it can't get altogether of data. It get only some data. What should I do to get altogether of data? If all of... (7 Replies)
Discussion started by: noppon_s
7 Replies

4. Shell Programming and Scripting

Need help with serial port

Hi, I have a external board connected to my serial port. I need to execute "shutdown -r now" command when system boot up. When system boots up it requires a username ans password. Then I need to run my command. I can use rc script but that is rebooting system before it asks for username and... (0 Replies)
Discussion started by: charlie.arya
0 Replies

5. Solaris

How to enable Serial port on ILOM, when Network Port is enabled in parallel

Hi Everyone, In my environment, I have few T5220. On the iLOM Management Card, I have both Network and Serial port are cabled, I don't have any issues while I try to connect using Network Management port, but when I try to connect the serial port for the same server which is actually connected... (3 Replies)
Discussion started by: bobby320
3 Replies

6. Programming

unable to send read and write serial port

hey frns pls help me out !! i hav a code of c that i have to include in my project. i am using a device (geomeda) that has unix based OS. it also support SIM card for connecting to server . I need to send SMS to user from this device.. below code is not working .. i am unable to send sms and the... (7 Replies)
Discussion started by: yashwantkumar
7 Replies

7. Programming

Read from serial port

Hi I try to communicate with a GSM modem, from C, for sending SMS. I use standart AT-commands. Working well with terminal. There is no problem writing ti the port. But when I try to read I only get a echo, I write "ATI" and get "ATI" back, I should get somthing like "SIEMENS 35... (4 Replies)
Discussion started by: dmiller
4 Replies

8. Debian

Reading data from a serial port

Dear List - I am trying to capture data from a serial port and write it to a file. /var/www$ cat /dev/ttyS0 > scale_value.html cat: /dev/ttyS0: Device or resource busy /var/www# cat /proc/tty/driver/serial serinfo:1.0 driver revision: 0: uart:16550A port:000003F8 irq:4 tx:90... (11 Replies)
Discussion started by: Meow613
11 Replies

9. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies
RESET(3)								 1								  RESET(3)

reset - Set the internal pointer of an array to its first element

SYNOPSIS
mixed reset (array &$array) DESCRIPTION
reset(3) rewinds $array's internal pointer to the first element and returns the value of the first array element. PARAMETERS
o $array - The input array. RETURN VALUES
Returns the value of the first array element, or FALSE if the array is empty. EXAMPLES
Example #1 reset(3) example <?php $array = array('step one', 'step two', 'step three', 'step four'); // by default, the pointer is on the first element echo current($array) . "<br /> "; // "step one" // skip two steps next($array); next($array); echo current($array) . "<br /> "; // "step three" // reset pointer, start again on step one reset($array); echo current($array) . "<br /> "; // "step one" ?> SEE ALSO
current(3), each(3), end(3), next(3), prev(3). PHP Documentation Group RESET(3)
All times are GMT -4. The time now is 01:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy