Error, disabling serialEvent() for /dev/cu.usbserial-0001 null

Hello there,

I have backup my os catalina.
And now i have this trouble
Error, disabling serialEvent() for /dev/cu.usbserial-0001
null
I have installed an uart driver but without effect.
What could I do?
I’m just so sad :frowning_face:

import processing.serial.*;    
Serial DueSerialNativeUSBport141201; // The serial port
 
int v1 =0;
int v2 =400;
int v3,v4,v5 =400;
int x;

int  counterV1;
int  oldv1;
//Record and repeat movement

int num = 20*4;
int numberSec = 4;

float mx[] = new float[num]; // Future
float my[] = new float[num]; // Future

float rx[] = new float[num];
float ry[] = new float[num];

int beginTime,endTime,TimeMiddleElapsed,LastTimeMiddleElapsed,Timer,Timer2,LastTimeElapsed;

int actualSec,lastSec, lastLastSec;

public void settings() {
  size(600, 600, P3D);
} 

 
void setup() {
  LastTimeMiddleElapsed=1980;
  LastTimeElapsed=4000-20;
//  noStroke();
  fill(255, 0, 0, 50); 
  println("Start Drawing!");
  frameRate(45);
  v1=counterV1=height/2;
//  size(800,600);
  // Open serial port
  printArray(Serial.list());
  DueSerialNativeUSBport141201 = new Serial(this, Serial.list()[2], 1000000);
 
  // Read bytes into a buffer until you get a linefeed (ASCII 10):
  DueSerialNativeUSBport141201.bufferUntil('\n');
 
  //draw with smooth edges:
  //smooth();
  noLoop();
  background(255);
}
 
void draw() {
   
    if  (actualSec>lastSec){
  lastLastSec=lastSec;
  lastSec=actualSec; 
    }  
    actualSec = second();  // Values from 0 - 59
 // print ( lastLastSec); print ( "last" ); print ( lastSec );  print ( "actual" ); println ( actualSec ); 
  samplingMovement();
   if (oldv1<v1 && v1!= oldv1 ){
    counterV1++;
   
  }
  // Draw circles
  fill(#ff0000);
  ellipse(x, v1+height/2, 10, 10);
  fill(#00ff00);
  ellipse(x, oldv1-10, 5, 5);
 
  // Update x position
  x++; 
  // Refresh screen
  if (x > 300) {
    background(255);
    x = 0;
  }
 
}
 
// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial DueSerialNativeUSBport101) { // receive 2 datas splited with ,
 
  // read the serial buffer:
  String myString = DueSerialNativeUSBport101.readStringUntil('\n');
 
  // if you got any bytes other than the linefeed:
  myString = trim(myString);
 
  // split the string at the commas
  // and convert the sections into integers:
  int values[] = int(split(myString, ','));
 
  if (values.length > 0) {// v1 de 0 a 4000
       oldv1=v1;
    v1 = (int) map (values[0], 0, 4000, 0, 400);
    v2 = (int) map (values[0], 0, 4000, 0, 400);
    v3 = (int) map (values[0], 0, 4000, 0, 400);
    v4 = (int) map (values[0], 0, 4000, 0, 400);
    v5 = (int) map (values[0], 0, 4000, 0, 400);
 
    v2 = values[1]/10;
  //  print (oldv1);   println (v1);   println (v2);    

 //  println (counterV1);
   
}
}
void samplingMovement() {

    Timer= millis()%2000;
    Timer2 = millis()%4000;
   //  print ("             Timer  "); print (Timer);
   //  print ("             Timer2  "); println ( Timer2);
    int i = int(frameCount%(20*4));
    if(frameCount>=0 && frameCount<=20*4+0 )
    {
    if(frameCount<=1) { // record 4 secondes
     int timeElapsed= endTime-beginTime; 
     print (" timeElapsed"); println (timeElapsed);
     beginTime=millis();
     background(0);
     
      } 
 //   else    background(0);
    if(frameCount>0 && Timer<=2000 && Timer2>=2000 )    //frameCount<=20*4+0
    {
    rx[i] = x;
  //  v1= (int) map (mouseY, 0, height, 0, 400);
    ry[i] = v1;
    mx[i] = rx[i];
    my[i] = ry[i];
    fill(255, 0, 0, 50); 
    circle(rx[i], ry[i], 10); 
 //   print (frameCount); print (" ry "); print (i); print ("  "); println (ry[i]);
  
    }    
   }
    
    int middleTime = millis(); 
    int TimeMiddleElapsed = middleTime -beginTime;
    
    if ( TimeMiddleElapsed >=1970 && TimeMiddleElapsed <=2030 || (frameCount >=30*4+1 && frameCount <=30*4+1)) {
  
      LastTimeMiddleElapsed=TimeMiddleElapsed;
      print (frameCount); print ("  TimeMiddleElapsed "); println ( TimeMiddleElapsed);
      } 
     
    if(frameCount>=20*4+1 ) // begin to replay
    {
       int TimeBack = millis(); 
    int TimeBackElapsed = TimeBack -beginTime;
     print (frameCount); print ("  TimeMiddleElapsed "); println ( TimeBackElapsed);
    circle(x+300, my[i], 10); 
  //  print (frameCount); print (" ry' "); print (i); print ("  "); println (ry[i]);
    print (frameCount); print (" ry "); print (i); print ("  "); print (ry[i]);
    print (" my "); print (i); print ("  "); println (my[i]);
    } 
  
    if(frameCount>=2*20*4 && frameCount<=2*20*4+0  ) // && Timer2>=4000-20 end  of replay // && actualSec>lastSec to synchronise with a second trigger
    {
      
    endTime=millis();
    int timeElapsed= endTime-beginTime; 
    LastTimeElapsed= timeElapsed;
     print (" LastTimeElapsed"); println (LastTimeElapsed);
    Timer=0;
    Timer2=0;
    background(255);
    
       // frameCount = -1; // Resets frameCount. -1 will run setup() again!

    frameCount = 81; // Restart only recorded loop
  //  frameCount = 0; // Restart from beginning
    }
    
//    if (mousePressed==true && Timer<=20) {
     if (mousePressed==true && frameCount>=0
     ) {
    frameCount = 1; // Restart main loop better than frameCount = 0
     } 
   
     
     
}

It doesn’t take much to disable serialEvent() in my experience. Try checking to make certain that myString is not null to start with. The times that I put a println just after the read line I was surprised at how many null strings there were. Try something like this:

String myString = DueSerialNativeUSBport101.readStringUntil('\n');
println(myString); // check the inString
if (myString != null) {
  myString = trim(myString);
  int values[] = int(split(myString, ','));
  if (values.length > 0) {// v1 de 0 a 4000
    oldv1=v1;
    v1 = (int) map (values[0], 0, 4000, 0, 400);
    v2 = (int) map (values[0], 0, 4000, 0, 400);
    v3 = (int) map (values[0], 0, 4000, 0, 400);
    v4 = (int) map (values[0], 0, 4000, 0, 400);
    v5 = (int) map (values[0], 0, 4000, 0, 400);

    v2 = values[1]/10;
  }
}

You define your serial port like this: Serial DueSerialNativeUSBport141201;
and call it like this: DueSerialNativeUSBport101

Those may not be the same.

2 Likes

Thank u very much!
I was tired yesterday night!

But I have an other problem.
I want to receive 6 int separted with ,
I receive this kind of datas

-1,1,0,0,0,1
-1,1,0,0,0,1
-1,1,0,0,0,1

And in my serialEvent if i want to find 6 different values it doesn’t work.
it says Error, disabling serialEvent() for /dev/cu.usbserial-0001
But in serialevent if i change with only values[0], serial port doesn’t bug but i have the same datas.
I don’t understand!

import processing.serial.*;    
Serial encodeurPort; // The serial port
int v0, v1, v2, v3, v4, v5;

int x;

int  counterV1;
int  oldv1;
//Record and repeat movement

int num = 20*4;
int numberSec = 4;

int encodeur[]=new int [num];

float mx[] = new float[num]; // Future
float my[] = new float[num]; // Future

float rx[] = new float[num];
float ry[] = new float[num];

int beginTime,endTime,TimeMiddleElapsed,LastTimeMiddleElapsed,Timer,Timer2,LastTimeElapsed;

int actualSec,lastSec, lastLastSec;

public void settings() {
  size(600, 600, P3D);
} 

 
void setup() {
  LastTimeMiddleElapsed=1980;
  LastTimeElapsed=4000-20;
//  noStroke();
  fill(255, 0, 0, 50); 
  println("Start Drawing!");
  frameRate(45);
  v1=counterV1=height/2;
//  size(800,600);
  // Open serial port
  printArray(Serial.list());
  encodeurPort = new Serial(this, Serial.list()[2], 1000000);
 
  // Read bytes into a buffer until you get a linefeed (ASCII 10):
  encodeurPort.bufferUntil('\n');
 
  //draw with smooth edges:
  //smooth();
 // noLoop();
  background(255);
}
 
void draw() {
 //  noLoop();
  
 
}
 
// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial encodeurPort) { // receive 2 datas splited with ,
 
  // read the serial buffer:
  String myString = encodeurPort.readStringUntil('\n');
 
  // if you got any bytes other than the linefeed:
  myString = trim(myString);
 
  // split the string at the commas
  // and convert the sections into integers:
  int values[] = int(split(myString, ','));
 
  if (values.length > 0) {// v1 de 0 a 4000
  // It works
  /*
    v0 = (int) map (values[0], 0, 4000, 0, 400);
    v1 = (int) map (values[0], 0, 4000, 0, 400);
    v2 = (int) map (values[0], 0, 4000, 0, 400);
    v3 = (int) map (values[0], 0, 4000, 0, 400);
    v4 = (int) map (values[0], 0, 4000, 0, 400);
    v5 = (int) map (values[0], 0, 4000, 0, 400);
   */ 
    // It doesn't 
    v0 = (int) map (values[0], 0, 4000, 0, 400);
    v1 = (int) map (values[1], 0, 4000, 0, 400);
    v2 = (int) map (values[2], 0, 4000, 0, 400);
    v3 = (int) map (values[3], 0, 4000, 0, 400);
    v4 = (int) map (values[4], 0, 4000, 0, 400);
    v5 = (int) map (values[5], 0, 4000, 0, 400);
   
   //  for (int i = 0; i < 6; i=+1 ){
   // encodeur[i]= (int) map (values[0], 0, 4000, 0, 400);
        //   printArray(encodeur);  
  //  }

    println (" v0 " + v0 + " v1 " + v1 + " v2 " + v2 + " v3 " + v3 + " v4 " + v4 +  " v5 " + v5);

   
}
}

The second problem may be related to how you are sending the data, which you have not shown us. For example it may be that you have to use two delimiters instead of one; you are currently using just commas to separate the data, but it has no way to know when it hits the end of the six integer string. It might make more sense to organize your data on the sending side by doing something like this:
&v0,v1,v2,v3,v4,v5&v0,v1,v2,v3,v4,v5& etc. You can use any delimiter you want for the six integer strings, the ampersand is just to make it understandable in e-mail. On the receiving end you would then use split twice; once for the six integer string and then again to split out the individual elements. I would suggest that you write a demo which isolates the problem. Practice sending known strings containing six elements and see if you can recover the elements on the receiving end. When you are able to do that correctly then use that same technique in your project.

Hi svan,
Trying to understand i did this below.
I send datas like that
,0§2,0,0,0,0,0§2,0,0,0,0,0§2,0,
But it doesn’t work.

import processing.serial.*;    
Serial encodeurPort; // The serial port
int f0, f1, f2, f3, f4, f5;
int v0, v1, v2, v3, v4, v5;

int x;

int  counterV1;
int  oldv1;
//Record and repeat movement

int num = 20*4;
int numberSec = 4;

int encodeur[]= new int [6]; // Future
int values[]= new int [6]; // Future


float mx[] = new float[num]; // Future
float my[] = new float[num]; // Future

float rx[] = new float[num];
float ry[] = new float[num];

int beginTime,endTime,TimeMiddleElapsed,LastTimeMiddleElapsed,Timer,Timer2,LastTimeElapsed;

int actualSec,lastSec, lastLastSec;

public void settings() {
  size(600, 600, P3D);
} 

 
void setup() {

//  size(800,600);
  // Open serial port
  printArray(Serial.list());
  encodeurPort = new Serial(this, Serial.list()[2], 1000000);
 
  // Read bytes into a buffer until you get a linefeed (ASCII 10):
  encodeurPort.bufferUntil('\n');

  background(255);
}
 
void draw() {
  

 
}
 
// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial encodeurPort) { // receive 6 datas splited with ,
 
  // read the serial buffer:
  String myString = encodeurPort.readStringUntil('\n');
 
 
 // if you got any bytes other than the linefeed:
  myString = trim(myString);
  
  
  // split the string at §
  // and convert the sections into 6 integers split with comma,:
  int valuesWithLimit[] = int(split(myString, '§'));
 
   if (valuesWithLimit.length > 0) {// v1 de 0 a 4000
   f1 = valuesWithLimit[0] ;
  
 }
 
 
  // split the string at the commas
  // and convert the sections into integers:
  int values[] = int(split(f1, ','));
 
  if (values.length > 0) {// v1 de 0 a 4000
     
    v0 = (int) map (values[0], 0, 4000, 0, 400);
    v1 = (int) map (values[1], 0, 4000, 0, 400);
    v2 = (int) map (values[2], 0, 4000, 0, 400);
    v3 = (int) map (values[3], 0, 4000, 0, 400);
    v4 = (int) map (values[4], 0, 4000, 0, 400);
    v5 = (int) map (values[5], 0, 4000, 0, 400);
 
     println (" v0 " + v0 + " v1 " + v1 + " v2 " + v2 + " v3 " + v3 + " v4 " + v4 +  " v5 " + v5);

   
}
}

Can you post the arduino code which sends the data; you’re only showing us the receiving end. The sending code and receiving code methods have to match.

Another option is to just forget about serial for a second and try to create a string of six elements containing known numbers (not all zeroes) and see if you can separate it into a six element array.

Please study the following demo and see if it applies to your situation:

void twoArrayMethod() {
  String dataStr = "8,67,5,309,427,999*5,6,34,45,23,88*76,12,44,99,32,9*";  // note trailing * which creates an empty array
  String[] numGroup = split(dataStr, '*');
  printArray(numGroup);
  println("array length = ", numGroup.length);
  // length-1 to avoid array overrun error; last index is empty
  for (int i =0; i < numGroup.length-1; i++) {
    int[] num = int(split(numGroup[i], ","));
    // This reports all the elements
    println (" v0 " + num[0] + " v1 " + num[1] + " v2 " + num[2] + " v3 " + num[3] + " v4 " + num[4] +  " v5 " + num[5]);
  }
}

void oneArrayMethod() {
  String oneDimNums = "8,67,5,309,427,999,4,33,66,32,88,99,12";
  int[] num = int(split(oneDimNums, ','));
  printArray(num);
  // This only reports first six elements of much larger array
  println (" v0 " + num[0] + " v1 " + num[1] + " v2 " + num[2] + " v3 " + num[3] + " v4 " + num[4] +  " v5 " + num[5]);
}

void setup() {
  surface.setVisible(false);
  println(" ***** ============ single array method ================ **** ");
  oneArrayMethod();
  println(" ***** ============ two array method ================ **** ");
  twoArrayMethod();
}

1 Like

Hi,
Thank a lot!
I will see your answer tomorrow with all my attention.

I send data from Arduino like that

   Serial1.print(getCount(0)); Serial1.print(",");Serial1.print(getCount(1)); Serial1.print(",");
   Serial1.print(getCount(2)); Serial1.print(",");Serial1.print(getCount(3)); Serial1.print(",");
   Serial1.print(getCount(4)); Serial1.print(",");Serial1.print(getCount(5));
   Serial1.println();