Hi everyones!
I tried to create a class to list what is plugged on serial port.
Then if a string match with a specific port, I want to see if it is true or not.
the program listing port is below
import processing.serial.*;
Serial DueSerialNativeUSBport141201; // The serial port
int v1 =0;
int v2 =400;
public void settings() {
size(600, 600, P3D);
}
void setup() {
// print serial port
printArray(Serial.list());
DueSerialNativeUSBport141201 = new Serial(this, Serial.list()[1], 9600);
// Read bytes into a buffer until you get a linefeed (ASCII 10):
DueSerialNativeUSBport141201.bufferUntil('\n');
background(255);
}
// 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
v1 = (int) map (values[0], 0, 4000, 0, 400);
v2 = (int) map (values[1], 0, 4000, 0, 400);
}
}
I did a class like this
class portManager {
// String whatIsPlugged,whatIsPlugged1,whatIsPlugged2,whatIsPlugged3,whatIsPlugged4;
// String whatIsPlugged5,whatIsPlugged6,whatIsPlugged7,whatIsPlugged8;
String [] portToCheck;
// portManager(String whatIsPlugged, String whatIsPlugged1, String whatIsPlugged2, String whatIsPlugged3, String whatIsPlugged4, String whatIsPlugged5, String whatIsPlugged6
// , String whatIsPlugged7,String whatIsPlugged8)
portManager (String [] portToCheck)
{
// this.whatIsPlugged=whatIsPlugged;
this.portToCheck[] = new String[portToCheck];
for (int i = 0; i < this.portToCheck; i++) {
print ( " portToCheck " + i + portToCheck );
}
}
//this.portManager = { "GA", "FL", "NC", "po", "po", "po" ,"po", "po", "po" };
}
Is there a good lesson to understand class? I’m French