We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Newbie Serial question - is this an array
Page Index Toggle Pages: 1
Newbie Serial question - is this an array (Read 415 times)
Newbie Serial question - is this an array
Sep 29th, 2005, 8:25pm
 
Hi

I have serial data coming in that consists of bursts of 14 bytes.
I have got them coming in using the code posted in the learning section (with numbers changed for the correct port on my machine).

The code currently looks like this (very little change from example)
--------------------------
// Example by Tom Igoe (then mangled by Nick)

import processing.serial.*;

Serial myPort;  // The serial port

void setup() {

 println(Serial.list());

 myPort = new Serial(this, Serial.list()[2], 9600);

}

void draw() {

 // Expand array size to the number of bytes you expect

 byte[] inBuffer = new byte[14];
 while (myPort.available() > 0) {

   inBuffer = myPort.readBytes();

   myPort.readBytes(inBuffer);

   if (inBuffer != null) {

    print(inBuffer);
//print("break");
   }

 }

}

This prints out the 14 byte signal to the console each time I trigger the device.
I was hoping that inBuffer was an array that I could then get at particular bytes by addressing them inBuffer[4] or whatever, but that gives me an out of bounds error.

When I uncomment the print('break") I expected to get the run of 14 values, with break printed at the end of each run (I can pause indefinitely between each run of 14 bytes) , but the word break seems to be sprinkled randomly amongst the values, sometimes a couple of times in a run of 14, sometimes once, but in the middle, occasionally at the end as I had hoped.

Sorry for long post - any pointers anyone?

Cheers

Nick

Page Index Toggle Pages: 1