Tuesday, 15 June 2010

drop down menu - Serial COM Port Selection by DropDownList in processing -


I have to set a communication between two machines via serial port processing 2.1.2 Wrote a program in. On my laptop, it was working fine but there is more than one serial port available on my desktop, it is not about detecting my functional serial COM port.

So now I will be able to select them from Combo Button and I will choose one of them.

How can you solve this issue?

  Import Processing ; String input; serial port; Zero setup () {size (448, 299, p3d); Println (serial.list ()); Port = new serial (this, serial list) [0], 9600); Port.bufferUntil ('\ n'); } Zero draw () {background (0); } Zero serial port {input = port.readString (); If (input! = Null) {string [] value = partition (input, ""); Println (value [0]); Println (value [1]); Println (value [2]); }}  

As it is mentioned in the comment, it is possible to use the UI library dropdown Before display you have to choose a library, as is very popular with processing. You can choose to use a swing originally & amp; After that, it should be a matter of touching the serial ports list in the loopdown in order to open the serial connection on this dropdown listener / callback.

An archive of concept sketch based on Bellow Control 5. Display downdown example that comes with the library:

  import processing.serial. *; Import control p5 *; Control P5CP5; Dropdown list serial ports list; Serial serial port; Final full BAUD_RATE = 9600; Zero setup () {size (700, 400, p3d); String [] portNames = serial.list (); Cp5 = new controlP5 (this); // Create a dropdown list serial portslist = CP 5. Adoprado List ("Serial Ports"). Setpoint (10, 10) .setWidth (200); For (int i = 0; i & lt; portNames.length; i ++) serialPortsList.addItem (port name [i], i); } ControlEvent theEvent {// dropdown list type control is of the control group // ControlAvent control group will start from inside the class. // so you have to check the provider of the event with // if (theEvent.isGroup ()) // to avoid error message by controlP5. If (theEvent.isGroup ()) // Check whether the event had started with a ControlGram printlain ("From Group to Event:" + theEvent.getGroup ()). GetValue () + "to" + theEvent.getGroup ()); // Check whether a serial port is already open, if so, turn it off (serialport = zero) {serialPort.stop (); SerialPort = null; } // Selected core string PortName = Open Serial Ports.list.GetItim ((int) theEvent.getValue ()). GetName (); {SerialPort = New Serial (try this, PortName, BAUD_RATE); } Hold (exception e) {System.err.println ("error in opening serial port" + portName); E.printStackTrace (); }} And if (theEvent.isController ()) {println ("From admin to event:" + theEvent.getController (). GetValue () + "to" + theEvent.getController ()); }} Zero draw () {background (128); }  

Also, when selecting a new serial port, any existing connection will be closed and errors related to opening a serial port are handled, so the program does not crash when there are problems is.

For example, on OSX, you get Bluetooth serial ports which are not available or are not available or used:


No comments:

Post a Comment