We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am getting error in recovering the Item Value set using .setvalue(0). Also please guide how to use when users change the default value.
`//Imports
import processing.serial.*;
import controlP5.*;
import java.util.*;
//Variable Declarations
ControlP5 lstPortList;
ControlP5 lstBaud;
String tport;
int tbaud;
Serial myPort; // The serial port
int whichKey = -1; // Variable to hold keystoke values
int inByte = -1; // Incoming serial data
int Indexport =0;
int Indexbaud =1;
///Setup/////
void setup() {
size(400, 400);
// create a font with the third font available to the system:
PFont myFont = createFont(PFont.list()[2], 14);
textFont(myFont);
// List all the available serial ports:
// printArray(Serial.list());
lstPortList = new ControlP5(this);
String[] portNames =Serial.list();
lstPortList.addScrollableList("Port")
.setPosition(10, 10)
.setSize(100, 100)
.setBarHeight(20)
.setItemHeight(20)
.addItems(portNames)
.setFont(createFont("Arial", 13))
.setColorForeground(color(40, 128))
.setValue(Indexport);
lstBaud = new ControlP5(this);
List BaudList = Arrays.asList("4800", "9600", "19200", "38400", "57600", "115200");
lstBaud.addScrollableList("Baud")
.setPosition(200, 10)
.setSize(100, 100)
.setBarHeight(20)
.setItemHeight(20)
.addItems(BaudList)
.setFont(createFont("Arial", 13))
.setColorForeground(color(40, 128))
.setValue(Indexbaud);
tport= port(Indexport);//lstPortList.get(ScrollableList.class, "port").getItem(Indexport).get("text");
tbaud= baud(Indexbaud); //lstBaud.get(ScrollableList.class, "port").getItem(Indexbaud).get("text");
myPort = new Serial(this, tport, tbaud );
}
void draw() {
background(0);
text("Last Received: " + inByte, 10, 130);
text("Last Sent: " + whichKey, 10, 100);
}
void serialEvent(Serial myPort) {
inByte = myPort.read();
}
void keyPressed() {
// Send the keystroke out:
myPort.write(key);
whichKey = key;
}
String port(int n) {
return lstPortList.get(ScrollableList.class, "Port").getItem(n).get("text");
}
int baud(int n) {
return lstBaud.get(ScrollableList.class, "Baud").getItem(n).get("text");
}`
Thanks
Answers
I am using CP5 and am trying since morning to list all the COM ports and Baud Speeds and allow user to select and then should connect to that COM port at that Baud.
I am trying to list all the COM ports and Baud Speeds and allow user to select and then should connect to that COM port at that Baud.
I believe this was already answered in the following post: https://forum.processing.org/two/discussion/20389/how-to-list-all-com-ports-in-combobox-or-listbox-and-allow-user-to-select-the-desired-com-port#latest
Kf
Not totally sir. But now I am through with it. I still have a minor glitch. The Port or Baud I select from the List doesn't get immediately selected but gets selected on the next selection. Here is my code