Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you already got the whole communication over a serial port thing worked out, and that the second line IS a valid data set, I would wrap your serial stream with a <code>Scanner</code>, and structure it as such:</p> <pre><code>String[] arrayAndValue; int arrayToken; double arrayValue; Scanner serScanner = new Scanner(myInputStream); serScanner.useDelimiter("[\\p{JavaWhiteSpace}+||\*dd]"); While(serScanner.hasNext()) { scannedItem = serScanner.nextString; arrayAndValue=scannedItem.split(","); arrayToken =Integer.parseInt(arrayAndValue[0]); arrayValue =Double.parseDouble(arrayAndValue[1]; //insert a switch statement here, //based on the different values arrayToken could have } </code></pre> <p>What I did there was to use the <code>Scanner</code> class to parse <code>myInputStream</code> into pairs of array tags and values, <code>arrayToken</code> and <code>arrayValue</code> respectively as a <code>String</code>, and then split that String using the <code>,</code> OR a pattern of a <code>*</code> followed by two digits. </p> <p>That will result in a String array of length 3, with the first containing the <code>arrayToken</code>, the second the <code>arrayValue</code>, and the third being an empty string (created because of the trailing comma).</p> <p>Then you use the <code>Integer.parseInt</code> and <code>Double.parseDouble</code> calls to translate them, and then add them to the appropriate array in your <code>switch</code> statement later. I would recommend you input the items into <code>ArrayLists</code> instead of <code>Arrays</code> if you do not know the exact number of each type you will be receiving though. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload