Java Serial Ports Run Confguration -


i want read , write serial data on same laptop , try code. works ports chosen run configurations selecting com1 , com2 1 one. however; when want use ports again in same way, error appears nosuchportexception there anyway disconnect ports second usage?

package javaserial;  import java.util.scanner;  import gnu.io.commportidentifier;   import gnu.io.serialport;  public class rs232 {        public void connect(string portname) throws exception {           commportidentifier portidentifier = commportidentifier.getportidentifier(portname);            if (portidentifier.iscurrentlyowned()) {               system.out.println("port in use!");           } else {               // points owns port , connection timeout               serialport serialport = (serialport) portidentifier.open("rs232example", 2000);                // setup connection parameters               serialport.setserialportparams(                   38400, serialport.databits_8, serialport.stopbits_1, serialport.parity_none);              // setup serial port writer               commportsender.setwriterstream(serialport.getoutputstream());                // setup serial port reader               new commportreceiver(serialport.getinputstream()).start();          }       }        public static void main(string[] args) throws exception {                             string textname;         int startindex;         int bytelength;          scanner scan = new scanner(system.in);         system.out.println("textname");         textname = scan.nextline();         system.out.println("startindex");         startindex = scan.nextint();         system.out.println("bytelength");         bytelength = scan.nextint();          // connects port name (e.g. com1) in first argument         new rs232().connect(args[0]);          // send helo message through serial port using protocol implementation           commportsender.send(new protocolimpl().getmessage(new readfileintobytearray(textname, startindex, bytelength).getfilestring()));      }   } 


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -