This code first write 0x80 to COM port () then it reads 0x32 
from COM port and then sends 6 more bytes and to terminate the 
packet it receives  0x70 form COM port.
This code can be very helpful to communicate with embedded devices which communicate with PC through COM port.
-Watch video
https://youtu.be/sX0XAROhuiQ
// library import import java.io.*;import java.util.*;import javax.comm.*;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.Statement;public class Fms implements Runnable{static Enumeration portList;static CommPortIdentifier portId;static SerialPort serialPort;static OutputStream outputStream;static InputStream inputStream;static Thread readThread,dataBase;static int crf;static int cwf;static byte cxc[] = new byte[4];static int cxm = 128;//0x80static byte[] creadBuffer;//1byte readstatic int creadBuff[];write rt=new write();static read rd;public void run() {};public static void main(String[] args) {int a=10;write wr = new write();read rd = new read(1);int b = 0;int speed=0,tcount=0,jcount=0,status=0;while(b!=10){for(int j =0 ; j<=1;j++){try{wr.cwritemain(a);rd.cmainx(a);readThread.sleep(1000);}catch(Exception e){}if(j==0){status =creadBuff[1];jcount =creadBuff[5];System.out.println("results : "+status +"\t"+jcount);}if(j==1){speed =creadBuff[1]*256+creadBuff[2];//to convert received data in decimaltcount =creadBuff[6];System.out.println("results : "+speed +"\t"+tcount);}}}}static class write{public void cwritemain(int m)
 
No comments:
Post a Comment