• Post Reply Bookmark Topic Watch Topic
  • New Topic

RS232 - RS485 coding problem  RSS feed

 
Hsiu-Chin Chao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi....
i cannot find out where i got this wrong. i cannot send the command to the convertor(RS232-RS485), it read for nothing, so nothing changed. 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.");
}
}
[ September 25, 2003: Message edited by: Hsiu-Chin Chao ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!