Go Down

Topic: Adding a particular character into array (Read 533 times) previous topic - next topic

arroiyyaan

Apr 11, 2017, 11:52 am Last Edit: Apr 11, 2017, 12:02 pm by arroiyyaan
Hello

I need to add a '#' into each data of array. but i've no idea how to do so as i did many ways to accomplish that
first time i read the 48 bytes adc value from 24 analog sensor (2 bytes for each) and store the value in a variable. Then I need to display each of them into textbox in the desktop app i made with VB.

here adc reading code which goes well if i send all of the data without any addition character

Code: [Select]

while (Serial1.available())
    {
        for (indexReply=0; indexReply<24; indexReply++)
        {
            thisByteReply = Serial1.read();
            value[indexReply] = thisByteReply;
           
            if (indexReply>=23)
            {
               Serial.write(value, indexReply); //directly send all of 'value' with 24 in length
            }
   
   
}
     }



then i have to send all of the values through serial with character '#' added exactly between each of the 24 data. lets say all of the sensor give full adc 10bit value which is 1023, so the data i want to send will be like this :

Code: [Select]

1023#1023#1023#1023#1023#10231023#1023#1023#1023....#1023


so that the desktop app i made can parse and display each of them in textbox correctly.
I have some trial and nothing of them runs well,
such this :

Code: [Select]


String sign = "#";
String objectSent = sign + value[indexReply=0] + sign + . . .+ value[indexReply=23]; //consider the variable written 24 times
Serial.print(objectSent);




kindly please assist me some help i really appreciate

PaulS

Quote
I need to add a '#' into each data of array.
What does that mean? Arrays have elements.

Which array do you want to store the '#'s in?

Why do you think you need to do this? You are sending binary data. You KNOW that there are 2 bytes per value. You do NOT need separators between the bytes.


arroiyyaan

i need that separation sign so that my GUI can parse each of them. each of them need to be displayed in certain textbox in GUI while the GUI recognize each of them by "#".
what i supposed to do, i did some conversion but the results display random value

arroiyyaan

all of the value stored in value[indexReply] with indexReply starts from 0-23.
this variable that i need to separate with that sign while sending to PC

UKHeliBob

Is the VB program expecting binary data or ASCII data ?

Why use Strings ?

Code: [Select]

for (int x = 0; x < NUMBER_OF_ARRAY_ELEMENTS; x++)
{
  Serial.print(value[x]);
  Serial.print("#");
}
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

arroiyyaan

i've tried that before by using this code :

Code: [Select]

void storeDisplay()
{
    while (Serial1.available())
    {
        for (indexReply=0; indexReply<24; indexReply++)
        {
            thisByteReply = Serial1.read();
            thisByteIndexReply[indexReply] = thisByteReply;     
        }
   
        for (int i=0; i<23; i++)
{
    Serial.print(thisByteIndexReply[i]);
    Serial.print("#");
}
 
    indexReply = 0;
    }

}


and i got this results :

Code: [Select]

49#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#13#49#10#


here is the declaration of variable on VB that will be parsed :

 Delegate Sub Receivedata(ByVal [text] As String)

with 'text' as the variable for received data from arduino

UKHeliBob

Code: [Select]
49#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#10#13#49#10#13#49#10#13 and so on
49 is the ASCII code for '1'
10 is the ASCII code for linefeed
13 is the ASCII code for carriage return

I don't know enough about VB to know what it expects to receive
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up