我被分配了一个任务来与行显示或客户显示其型号 VFD220E 其波特率 9600 N 8 1 和 20 个字符 2 行显示进行通信。我有手册,但是当我尝试发送命令时。它没有捡起它,它只是像字符串一样打印。任何帮助将提前非常感谢。下面是我的代码。
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("COM1");
if (portIdentifier.isCurrentlyOwned())
{
System.out.println("Port in use!");
}
else {
System.out.println(portIdentifier.getName());
SerialPort serialPort = (SerialPort) portIdentifier.open("ListPortClass", 300);
int b = serialPort.getBaudRate();
System.out.println(Integer.toString(b));
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
OutputStream mOutputToPort = serialPort.getOutputStream();
InputStream mInputFromPort = serialPort.getInputStream();
String ESC=" 1B 51 41 ";//hex codes
String CR="0D";//hex codes
String mValue = ESC+" Testing Phase"+CR;//to display on top line.
String clear ="0C";
System.out.println("beginning to Write . \r\n");
mOutputToPort.write(clear.getBytes());
mOutputToPort.write( mValue.getBytes());
mOutputToPort.flush();
System.out.println("Command Written to Port. \r\n");
mOutputToPort.flush();
System.out.println("Waiting for Reply \r\n");
//Thread.sleep(500);
byte mBytesIn [] = new byte[20];
mInputFromPort.read(mBytesIn);
mInputFromPort.read(mBytesIn);
String value = new String(mBytesIn);
System.out.println("Response from Serial Device: "+value);
mOutputToPort.close();
mInputFromPort.close();
serialPort.close();