1 Reply Latest reply: Nov 2, 2008 10:22 PM by 843851 RSS

    Serial communication between two pc using RS232(rxtxcomm)

    843851
      Hi,

      I am new to serial communication part. i want to communicate two pc via serial port using RS232. shall anybody give any idea for serial port communication process..
        • 1. Re: Serial communication between two pc using RS232(rxtxcomm)
          843851
          Hi I have a code snippet for RS232 communication. I guess this might help you.
          For serial port communication you have to import javax.comm.CommDriver,avax.comm.CommPortIdentifier,javax.comm.SerialPort,javax.comm.SerialPort,javax.comm.SerialPortEventListener,javax.comm.SerialPortEvent and then use the following snipet

          Enumeration enu = CommPortIdentifier.getPortIdentifiers();
          CommPortIdentifier portid = null;
          while (enu.hasMoreElements())
          {
               portid = (CommPortIdentifier) enu.nextElement();
               System.out.println("port ID:" + portid.getName() + " portType:" + portid.getPortType());
                              
               if(portid.getName().trim().equalsIgnoreCase(serialPortName.trim()))
          {
          System.out.println("opening serial port " + serialPortName);
               //serialPort = (SerialPort) commDriver.getCommPort(serialPortName, CommPortIdentifier.PORT_SERIAL);
               serialPort = (SerialPort)portid.open("MyApp", 2000);
               break;
               }
          }