Oct 14, 2003 #1 aryajur Programmer Jul 2, 2003 45 0 0 US Hello, Can anyone help me as to how can I access the serial port thru a Java application ?
Oct 14, 2003 1 #2 greeneka Programmer Aug 11, 2003 17 0 0 IE check out: http://java.sun.com/products/javacomm/ Upvote 0 Downvote
Oct 22, 2003 Thread starter #3 aryajur Programmer Jul 2, 2003 45 0 0 US I tried the api and I tried to execute the following code in one of the examples: import java.io.*; import java.util.*; import javax.comm.*; public class SimpleWrite { static Enumeration portList; static CommPortIdentifier portId; static String messageString = "Hello, world!\n"; static SerialPort serialPort; static OutputStream outputStream; public static void main(String[] args) { portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { if (portId.getName().equals("COM1") { //if (portId.getName().equals("/dev/term/a") { try { serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000); } catch (PortInUseException e) {} try { outputStream = serialPort.getOutputStream(); } catch (IOException e) {} try { serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException e) {} try { outputStream.write(messageString.getBytes()); } catch (IOException e) {} } } } } } It compiles fine but when I execute it it gives the message: Exception in thread "main" java.lang.NoClassDefFoundError: SimpleWrite What is wrong here?? Upvote 0 Downvote
I tried the api and I tried to execute the following code in one of the examples: import java.io.*; import java.util.*; import javax.comm.*; public class SimpleWrite { static Enumeration portList; static CommPortIdentifier portId; static String messageString = "Hello, world!\n"; static SerialPort serialPort; static OutputStream outputStream; public static void main(String[] args) { portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { if (portId.getName().equals("COM1") { //if (portId.getName().equals("/dev/term/a") { try { serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000); } catch (PortInUseException e) {} try { outputStream = serialPort.getOutputStream(); } catch (IOException e) {} try { serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException e) {} try { outputStream.write(messageString.getBytes()); } catch (IOException e) {} } } } } } It compiles fine but when I execute it it gives the message: Exception in thread "main" java.lang.NoClassDefFoundError: SimpleWrite What is wrong here??
Oct 22, 2003 #4 sedj Programmer Aug 6, 2002 5,610 0 0 The directory that you have your SimpleWrite.class file is not in your CLASSPATH. In the console you will run your code, do (in dos) set CLASSPATH=%CLASSPATH%;. (in unix/linux [syntax for csh a bit different mind]) export CLASSPATH=$CLASSPATH:. Upvote 0 Downvote
The directory that you have your SimpleWrite.class file is not in your CLASSPATH. In the console you will run your code, do (in dos) set CLASSPATH=%CLASSPATH%;. (in unix/linux [syntax for csh a bit different mind]) export CLASSPATH=$CLASSPATH:.