Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RS232 - RS485 coding problem

843829Sep 25 2003 — edited Sep 25 2003
hi....
i cannot find out where i got this wrong. if the program is logically right...then probably the command format is wrong...thanks for any suggetion...

import java.io.*;
import java.util.*;
import javax.comm.*;

public class ICPTest
{

static CommPortIdentifier portId;
static String command = "#000+07.000013E";
static SerialPort serialPort;
static OutputStream outputStream;
//static boolean outputBufferEmptyFlag = false;

public static void main(String[] args)
{
try
{
portId = CommPortIdentifier.getPortIdentifier("COM1");
} catch (NoSuchPortException ne) {System.out.println(ne);}

try
{
serialPort = (SerialPort) portId.open("ICPTest", 20000);
} catch (PortInUseException pe) {System.out.println(pe);}

try
{
outputStream = serialPort.getOutputStream();
} catch (IOException ie) {System.out.println(ie);}

try
{
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException ue) {System.out.println(ue);}

try
{
serialPort.notifyOnOutputEmpty(true);
} catch (Exception e)
{
System.out.println("Error setting event notification");
System.out.println(e.toString());
System.exit(-1);
}

System.out.println(
"Writing \""+command+"\" to "
+serialPort.getName());
serialPort.setDTR(true);
serialPort.setRTS(true);
try
{
outputStream.write(command.getBytes());
} catch (IOException e) {System.out.println(e);}

try
{
Thread.sleep(20000);
} catch (Exception e) {System.out.println(e);}
serialPort.setRTS(false);
serialPort.close();
System.out.println("End of transmition.");
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2003
Added on Sep 25 2003
2 comments
175 views