Serial port and J2ME

How can I establish a serial port connection using J2ME?And how can I read strings of this serial port?Thanks,CesarMessage was edited by: Cesar82
[187 byte] By [Cesar82a] at [2007-11-27 6:58:26]
# 1
http://www.j2medev.com/api/wma/javax/microedition/io/CommConnection.html http://forum.java.sun.com/thread.jspa?messageID=3620972&tstart=0 http://archives.java.sun.com/cgi-bin/wa?A2=ind0404&L=j2me-cdc-interest&F=&S=&P=1604
PeppeMEa at 2007-7-12 18:49:04 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Hi

I am new with Java. I would like to programm RS232 port from Java and from Mobile Phone.

First I would like to use the serial port of PC.

I have downloaded the javax.comm , and I have installed it.

Unfortunatly it does not work.

The error is:

JavaX.comm: Can not find javax.comm.properties!

Could someone help me?

Thanks

Zsolt

Attached I send my code

import java.io.*;

import java.util.*;

import javax.comm.*;

public class SimpleRead implements Runnable, SerialPortEventListener {

static CommPortIdentifier portId;

static Enumeration portList;

InputStream inputStream;

SerialPort serialPort;

Thread readThread;

public static void main(String[] args) {

boolean portFound = false;

//String defaultPort = "/dev/term/a";

String defaultPort = "COM1";

if (args.length > 0) {

defaultPort = args[0];

}

portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {

portId = (CommPortIdentifier) portList.nextElement();

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

if (portId.getName().equals(defaultPort)) {

System.out.println("Found port: "+defaultPort);

portFound = true;

SimpleRead reader = new SimpleRead();

}

}

}

if (!portFound) {

System.out.println("port " + defaultPort + " not found.");

}

}

public SimpleRead() {

try {

serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);

} catch (PortInUseException e) {}

try {

inputStream = serialPort.getInputStream();

} catch (IOException e) {}

try {

serialPort.addEventListener(this);

} catch (TooManyListenersException e) {}

serialPort.notifyOnDataAvailable(true);

try {

serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,

SerialPort.STOPBITS_1,

SerialPort.PARITY_NONE);

} catch (UnsupportedCommOperationException e) {}

readThread = new Thread(this);

readThread.start();

}

public void run() {

try {

Thread.sleep(20000);

} catch (InterruptedException e) {}

}

public void serialEvent(SerialPortEvent event) {

switch (event.getEventType()) {

case SerialPortEvent.BI:

case SerialPortEvent.OE:

case SerialPortEvent.FE:

case SerialPortEvent.PE:

case SerialPortEvent.CD:

case SerialPortEvent.CTS:

case SerialPortEvent.DSR:

case SerialPortEvent.RI:

case SerialPortEvent.OUTPUT_BUFFER_EMPTY:

break;

case SerialPortEvent.DATA_AVAILABLE:

byte[] readBuffer = new byte[20];

try {

while (inputStream.available() > 0) {

int numBytes = inputStream.read(readBuffer);

}

System.out.print(new String(readBuffer));

} catch (IOException e) {}

break;

}

}

}

Kuzina at 2007-7-12 18:49:04 > top of Java-index,Java Mobility Forums,Java ME Technologies...