3 Replies - 786 Views - Last Post: 29 September 2010 - 03:59 AM Rate Topic: -----

#1 rapo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 27-November 08

Sending numbers through serial port

Posted 29 September 2010 - 02:40 AM

I have a little problem with the serial port. I want to send from a uC through serial port some numbers. The number of numbers is variable. I'm sending from the uC everytime a number with 3 digits, so I know how long are the numbers and I know how many numbers I need to receive. I have this code:

private void port_DataReceive(object sender, SerialDataReceivedEventArgs e)
        {
            string data;

            data = ComPort.ReadExisting();

            if (numbers < numbers_selected+1)
            {// numbers - the number of numbers received from the serial port
             //numbers_selected - number of numbers that I need to received
                if (digits <= 3)
                {//the numbers are comming in digits,only one digit at a time, so digits - number of digits from the current number the I receive from the serial port
                    digits_number = string.Concat(data);
                    digits++;
                 //digits_number - is the final number, that i will add to the arraylist
                }
                else
                {
                    MyArrayList.Add(digits_number);
                    digits = 0;
                    numbers++;
                }
            }
}



So, I have an ArrayList(MyArrayList) that save 6 positions, first the number of numbers that need treceived from the serial port and is taken from a comand button, and the 5 numbers(that is the maximum number of numbers that I can take from the serial port). But now, the port is working @ 9600 and I don't know exaclty if this algorithm is enough fast...
That's my algorithm but I don't think that is the right one, but if someone has another idea,I can change mine.

Is This A Good Question/Topic? 0
  • +

Replies To: Sending numbers through serial port

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,839
  • Joined: 02-June 10

Re: Sending numbers through serial port

Posted 29 September 2010 - 03:14 AM

Is it just me, or did I miss the *question* in your question?
Are you getting an error... unexpected results... ?
Was This Post Helpful? 0
  • +
  • -

#3 rapo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 27-November 08

Re: Sending numbers through serial port

Posted 29 September 2010 - 03:45 AM

The problem is that, for example if I want to send two numbers, the string data containt bought numbers sometime, and only one number sometime but the process for sending is the same. The question is, someone has a better idea how to do this?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,839
  • Joined: 02-June 10

Re: Sending numbers through serial port

Posted 29 September 2010 - 03:59 AM

View Postrapo, on 29 September 2010 - 02:45 AM, said:

The problem is that, for example if I want to send two numbers, the string data containt bought numbers sometime, and only one number sometime but the process for sending is the same. The question is, someone has a better idea how to do this?


Computers do not just choose to send 1 number one time and 2 numbers another time. So the first thing I need to ask is: "Have you confirmed that the sending computer is actually sending 2 numbers *and* you received only 1? Not assumed that both were sent, but in some way *confirmed* it.

Secondly, have you done the DIC tutorial on Serial port communication? Your code sure doesn't look anywhere near close to it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1