Java Communications API PocketPC/WinCE Driver: Documentation

Programming API

The package is designed to fit transparently into any Java™ Communications program.

The API for the Java™ Communications API is available here.

Installation

  1. Download the correct package for your computer type.
  2. Unpack the files.
  3. Copy the commapi.dll file to /windows
  4. Copy the javax.comm.properties file to <java.home>/lib
  5. Copy the CESerial.jar and comm.jar file to the target machine.
  6. Add the paths to both jar files to your classpath.

Quick Getting started guide

The following code will open up COM1 and get its input and output streams. After this just treat the streams as any other io stream.

Note that closing the stream does not close the serial port. You must close the serial port before you quit your application, otherwise you will need to reboot you CE machine.

    CommPortIdentifier cpi = null;
    for (Enumeration e = CommPortIdentifier.getPortIdentifiers() ; e.hasMoreElements() ;) {
      CommPortIdentifier tmp = (CommPortIdentifier)e.nextElement();
      if (tmp.getName().equals("COM1:")) {
        cpi = tmp;
        break;
      }
    }
    if (cpi == null) {
      // Unable to find COM1
      return;
    }
    else {
      // found COM1
    }

    try {
      port = cpi.open("My app name", 1000);
      cos = port.getOutputStream();
      cis = port.getInputStream();
      // we have now succesfully opened COM1
      // you should configure the port to the correct baud rate, datawidth etc...
    }
    catch (Throwable e) {
       //Failed opening port
       System.err.println(e.toString());
       return;
    }
	// Do app specific code here.