Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to store OnComm values in a single string variable

how to store OnComm values in a single string variable

Scheduled Pinned Locked Moved C#
data-structureshelptutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mads115
    wrote on last edited by
    #1

    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

    F L D P 4 Replies Last reply
    0
    • M Mads115

      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

      F Offline
      F Offline
      freakyit
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Mads115

        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

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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!


        1 Reply Last reply
        0
        • M Mads115

          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

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Mads115 wrote:

          In my project I have serial port communication.

          Mads115 wrote:

          string res= new string[];

          :omg: You are going to have a tough time.

          It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

          1 Reply Last reply
          0
          • M Mads115

            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

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups