# Check a match with serial port. How to make a simple test? Should I use a class?

**URL:** <https://discourse.processing.org/t/check-a-match-with-serial-port-how-to-make-a-simple-test-should-i-use-a-class/41683>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [April 11, 2023, 2:30pm UTC](https://discourse.processing.org/t/check-a-match-with-serial-port-how-to-make-a-simple-test-should-i-use-a-class/41683 "2023-04-11T14:30:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)\
**Post date:** [April 11, 2023, 2:30pm UTC](https://discourse.processing.org/t/check-a-match-with-serial-port-how-to-make-a-simple-test-should-i-use-a-class/41683/1 "2023-04-11T14:30:34Z")

</div>

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

```auto
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

```auto
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 🫣
