Centrino 칩용으로 하나의 J2ME 애플리케이션을 개발했습니다. 이 칩은 하나의 EZ 파워 미터에 연결됩니다. Modbus 프로토콜을 사용하는 직렬 통신 RS-232를 통해 EZ 미터에서 데이터를 읽고 싶습니다.j2me에서 commConneciton API를 사용하는 직렬 통신
나는 지주 레지스터에 대한 Modbus 요청을 보내기위한 몇 가지 코드가 있습니다.
//declare variable here
CommConnection commConn;
InputStream inStream;
OutputStream outStream;
는 // 여기에 열려있는 COM 포트 사용 CommConnection을
String strCOM = "comm:COM1;baudrate=9600;bitsperchar=8;stopbits=1;parity=even;blocking=on;autocts=off;autorts=off";
commConn = (CommConnection)Connector.open(strCOM);
inStream = commConn.openInputStream();
outStream = commConn.openOutputStream();
// 여기 모드 버스 프로토콜 요청을 만들 수 있습니다. 나는 그것을 읽고 레지스터 주소 1000 hava 2 레지스터를 갖고 싶어.
byte[] buffer = new byte[100];
byte[] frame1 = new byte[] {(byte) 0x01, (byte) 0x03, (byte) 0x03, (byte) 0xE8, (byte) 0x00, (byte) 0x02, (byte) 0x34, (byte) 0xBA};
outStream.write(frame1,0,frame1.length);//write(frame1);
outStream.flush();
int available1 = inStream.available();
System.out.println("inStream Available : "+inStream.available());
readBytes = inStream.read(buffer,0,available1);
System.out.println("Read Integer : "+readBytes +" and Bytes size : "+buffer.length);
항상 응답이 0 바이트입니다. 나는 무엇이 잘못되었는지 모른다. 잘못된 코드를 작성하면 안내해주십시오.
미리 감사드립니다.
http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/io/CommConnection.html의 예제 섹션을 참조하십시오. –
Opps! 칩 대 미터 연결에 연결 오류가 발생했습니다. 나는 그것을 고쳤다. 위 코드가 작동하면 찾을 수 있습니다. Meter에서 데이터를 읽을 수 있습니다. 감사합니다. –