how to store OnComm values in a single string variable
-
Hi In my project I have serial port communication.. which will receive three values with an interval of one sec, i want to store it in one single array, i don't know how to do it... the values are A0109000000000000i000(1 sec delay) B0109000000000000i000(1 sec delay) C0109000000000000i000 string res= new string[]; the value of res shld be res=A0109000000000000i000B0109000000000000i000C0109000000000000i000 how to do this Pls help me
-
Hi In my project I have serial port communication.. which will receive three values with an interval of one sec, i want to store it in one single array, i don't know how to do it... the values are A0109000000000000i000(1 sec delay) B0109000000000000i000(1 sec delay) C0109000000000000i000 string res= new string[]; the value of res shld be res=A0109000000000000i000B0109000000000000i000C0109000000000000i000 how to do this Pls help me
hi guy, if you only want to appent the string than you should use a System.Text.StringBuilder strBuilder.Appent(string); to get the hole string use strBuilder.ToString()... otherwise declare a generic array of type string, use the System.Collection.Generic.List lst.Add(string); after all values added copy the generic array to the string array string res = new string[lst.count]; lst.CopyTo(res); lst.Clear() hope i could help! greetz
-
Hi In my project I have serial port communication.. which will receive three values with an interval of one sec, i want to store it in one single array, i don't know how to do it... the values are A0109000000000000i000(1 sec delay) B0109000000000000i000(1 sec delay) C0109000000000000i000 string res= new string[]; the value of res shld be res=A0109000000000000i000B0109000000000000i000C0109000000000000i000 how to do this Pls help me
Mads115 wrote:
string res= new string[];
that does not compile. You declare a single value and instantiate an array.
Mads115 wrote:
res=A0109000000000000i000B0109000000000000i000C0109000000000000i000
whereas this suggests a single string, not an array. There are several ways to get your data, all assuming you use SerialPort class: 1. with DataReceived event: read the available data and add it to a List<string> when three elements are available, remove them from the list and join them together, possibly using
string.Join
2. with DataReceived event: if you're sure about the delays, then include a Thread.Sleep(2500) and read all available data, it will hold the three values (as the next two came in during the sleep). 3. without DataReceived event: issue a blocking read for the right amount of data. I would go for (1) as that is the cleanest approach. :)Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
-
Hi In my project I have serial port communication.. which will receive three values with an interval of one sec, i want to store it in one single array, i don't know how to do it... the values are A0109000000000000i000(1 sec delay) B0109000000000000i000(1 sec delay) C0109000000000000i000 string res= new string[]; the value of res shld be res=A0109000000000000i000B0109000000000000i000C0109000000000000i000 how to do this Pls help me
-
Hi In my project I have serial port communication.. which will receive three values with an interval of one sec, i want to store it in one single array, i don't know how to do it... the values are A0109000000000000i000(1 sec delay) B0109000000000000i000(1 sec delay) C0109000000000000i000 string res= new string[]; the value of res shld be res=A0109000000000000i000B0109000000000000i000C0109000000000000i000 how to do this Pls help me
I don't see why you'd want all three values in one string. A string array or a List would be a straightforward technique. Or you may want to define a class or structure to hold the values. It depends on what you plan to do with the values afterward.