喷气织机监控系统源代码.doc
喷气织机监控系统源代码1. org.genius.controlsystem1.1 Main.javapackage org.genius.controlsystem;import javax.swing.UIManager;import org.genius.controlsystem.ui.MainFrame;public class Main/* * 程序入口类 * * param args * throws Exception */public static void main(String args) throws Exception/ TODO Auto-generated method stubtryUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName(); catch (Exception e)MainFrame f = MainFrame.getInstance();f.initmainframe();f.setVisible(true);2.org.genius.controlsystem.Action2.1Action.javapackage org.genius.controlsystem.Action;import java.io.File;import java.io.FileInputStream;import java.sql.ResultSet;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Properties;import javax.swing.JTree;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.TreePath;import org.genius.controlsystem.dao.impl.TestDaoimpl;import org.genius.controlsystem.jdbc.JDBCExecutor;import org.genius.controlsystem.ui.MainFrame;import org.genius.controlsystem.vo.Test;import org.genuis.controlsystem.datatransport.ComDataTransport;import org.genuis.controlsystem.datatransport.DataTransport;import org.genuis.controlsystem.datatransport.NetDataTransport;/* * 按钮事件实现类 * * * */public class Actionprivate MainFrame mainFrame;private DataTransport comDataTransfer;private NetDataTransport netDataTransfer;private Test test;private byte stoprun = new byte 0x10, 0x01, 0x00, 0x07, (byte) 0x80, 0x20, (byte) 0x81, 0x00, 0x00, 0x01,(byte) 0xFF, 0x10, 0x02 ;private byte run = new byte 0x10, 0x01, 0x00, 0x07, (byte) 0x80, 0x20, (byte) 0x81, 0x00, 0x00, 0x01,(byte) 0xF5, 0x10, 0x02 ;private ResultSet rs = null;private int testseq;private int test_id;private Date now;private String starttime;private String endtime;private int totalround;private JTree tree = null;private DefaultMutableTreeNode testNode;private DefaultMutableTreeNode dateNode;private DefaultTreeModel treeModel = null;private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");private Properties pro;public Action() throws Exceptionsuper();/ TODO Auto-generated constructor stubmainFrame = MainFrame.getInstance();comDataTransfer = ComDataTransport.GetInstance();netDataTransfer = NetDataTransport.GetInstance();pro = new Properties();test = new Test();/* * 执行连接操作 * * param iscom * param isnet * return * throws Exception */public boolean connect(boolean iscom, boolean isnet) throws Exceptionif (iscom)File file = new File("src/cfg/ComInfo.properties");pro.load(new FileInputStream(file);/ 读取串口参数String Comnumber = pro.getProperty("ComNumber");int Baudrate = Integer.parseInt(pro.getProperty("BaudRate");int DATABITS = Integer.parseInt(pro.getProperty("DataBits");int STOPBITS = Integer.parseInt(pro.getProperty("StopBits");comDataTransfer.SetAdress(Comnumber, Baudrate, DATABITS, STOPBITS);/ 设定串口号,波特率,数据位,停止位mainFrame.getDownToolBar().setStatus("连接状态:串口(" + Comnumber + ")已连接");/ 在面板上显示串口连接信息return true; else if (isnet)File file = new File("src/cfg/EthernetInfo.properties");pro.load(new FileInputStream(file);/ 读取以太网参数String tempIP = pro.getProperty("IPadress");netDataTransfer.SetAdress(tempIP, 0, 0, 0);/ 设定传输IP地址mainFrame.getDownToolBar().setStatus("连接状态:以太网(" + tempIP + ")已连接");/ 在面板上显示以太网连接信息return isnet;/* * 断开操作 * * param iscom * param isnet * return * throws Exception */public boolean disconnect(boolean iscom, boolean isnet) throws Exception/ TODO Auto-generated method stubcomDataTransfer.Close();/ 关闭串口netDataTransfer.Close();/ 关闭以太网端口mainFrame.getDownToolBar().setStatus("连接状态:已断开");/ 在面板上显示连接状态return false;/* * 点击运行操作 * * return * throws Exception */public boolean start() throws Exception/ TODO Auto-generated method stubString sql = "select testseq.nextval from dual"rs = JDBCExecutor.getJDBCExecutor().executeQuery(sql);while (rs.next()testseq = rs.getInt(1);/ 得到新的一次测试的主键test_id = mainFrame.getTree().getTest_id();/ 读取当前的测试编号test_id+;/ 新的测试编号为当前测试编号加1netDataTransfer.SendData(run);/ 通过以太网发送电机运行命令now = new Date();starttime = sdf.format(now);/ 得到该次测试的开始时间test.setId(testseq);test.setTest_date(sdf.format(now);test.setTest_id(test_id);test.setStarttime(starttime);test.setEndtime(starttime);test.setTotalround(0);new TestDaoimpl().doCreate(test);/ 创建一个新的测试对象并设置内容testNode = new DefaultMutableTreeNode("第" + test_id + "次实验");testNode.setAllowsChildren(true);treeModel = mainFrame.getTree().getTreeModel();dateNode = mainFrame.getTree().getDateNode();treeModel.insertNodeInto(testNode, dateNode, dateNode.getChildCount();/ 往面板中的树添加一次测试tree.scrollPathToVisible(new TreePath(testNode.getPath();return false;/* * 电机停止操作 * * return * throws Exception */public boolean stop() throws Exception/ TODO Auto-generated method stubnetDataTransfer.SendData(stoprun);/ 通过以太网发送电机停止命令now = new Date();endtime = sdf.format(now);/ 得到该次测试的结束时间totalround = netDataTransfer.getTotalround();/ 得到该次测试的运行圈数netDataTransfer.setTotalround(0);test.setEndtime(endtime);test.setTotalround(totalround);test.setId(testseq);new TestDaoimpl().doUpdate(test);/ 更新这次测试的结束时间和总圈数return false;/* * 退出系统 */public void exit()System.exit(0);3.org.genius.controlsystem.analyse3.1Analyse.javapackage org.genius.controlsystem.analyse;import java.sql.ResultSet;import java.text.SimpleDateFormat;import java.util.Date;import javax.swing.JTree;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.TreePath;import org.genius.controlsystem.dao.impl.DetailDaoimpl;import org.genius.controlsystem.dao.impl.TestDaoimpl;import org.genius.controlsystem.jdbc.JDBCExecutor;import org.genius.controlsystem.ui.MainFrame;import org.genius.controlsystem.vo.Detail;import org.genius.controlsystem.vo.Test;/* * 数据分析实现类 * * * */public class Analyse private int quanshu;private int sudu;private int nowtime;private int angle;private int dianchifa;private int count;private int level1 = 0;private int level2 = 0;private int mycount;private int datacount = 0;private int datacountresult = 0;private Date now = new Date();private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");private int testid = 0;private int tid = 0;private String testdate = sdf.format(now);private String event = null;ResultSet rs = null;MainFrame mainframe = MainFrame.getInstance();private Detail detail = new Detail();public Analyse() throws Exception testid = mainframe.getTree().getTest_id();Test test = new TestDaoimpl().findByTestDate_Id(testdate, testid);tid = test.getId();/* * 分析所接受的Byte数组中所含信息 * * param input * throws Exception */public void tcpAnalyse(byte input) throws Exception while (true) int st2 = input2 + datacountresult & 0xFF;int st3 = input3 + datacountresult & 0xff;datacount = st2 * 256 + st3;datacountresult += datacount + 6;if (input0 + datacountresult - datacount - 6 = 0x10&& input1 + datacountresult - datacount - 6 = 0x01) if (inputdatacountresult - 2 != 0x10| inputdatacountresult - 1 != 0x02) mainframe.getInstantInfo().setEventinfo("数据错误");/ 判断包头包围是否正确return;/ 循环分析数据for (count = datacountresult - datacount - 2, mycount = 0; count < datacountresult- datacount + (datacount / 6) - 2; count+, mycount+) if (count = datacountresult - datacount - 2) for (int j = 1; j <= 2; j+) if (j = 1) quanshu = (input3 * j + 1 + datacountresult- datacount - 6 & 0xff)* 65536+ (input3 * j + 2 + datacountresult- datacount - 6 & 0xff)* 256+ (input3 * j + 3 + datacountresult- datacount - 6 & 0xff);System.out.println("现在是第" + quanshu + "圈");mainframe.getInstantInfo().setRoundinfo("第" + quanshu + "圈");/ 在面板上显示当前圈数DefaultMutableTreeNode roundNode = new DefaultMutableTreeNode("第" + quanshu + "圈");JTree tree = mainframe.getTree().getTree();DefaultMutableTreeNode testNode = mainframe.getTree().getTestNode();DefaultTreeModel treeModel = mainframe.getTree().getTreeModel();treeModel.insertNodeInto(roundNode, testNode,testNode.getChildCount();/ 往面板中的树添加该圈tree.scrollPathToVisible(new TreePath(roundNode.getPath(); else sudu = (input3 * j + 1 + datacountresult- datacount - 6 & 0xff)* 65536+ (input3 * j + 2 + datacountresult- datacount - 6 & 0xff)* 256+ (input3 * j + 3 + datacountresult- datacount - 6 & 0xff);sudu = 60 * 1000000 / sudu;System.out.println("现在的速度是" + sudu);mainframe.getInstantInfo().setSpeedinfo(sudu + "rpm"); else nowtime = (inputmycount * 6 + 4 + datacountresult- datacount - 6 & 0xff)* 65536+ (inputmycount * 6 + 5 + datacountresult- datacount - 6 & 0xff)* 256+ (inputmycount * 6 + 6 + datacountresult- datacount - 6 & 0xff);angle = (inputmycount * 6 + 7 + datacountresult- datacount - 6 & 0xff)* 256+ (inputmycount * 6 + 8 + datacountresult- datacount - 6 & 0xff);dianchifa = (inputmycount * 6 + 9 + datacountresult- datacount - 6 & 0xff);if (dianchifa > 16 && dianchifa < 31) dianchifa = dianchifa - 16;event = dianchifa + "号电磁阀关闭了" else if (dianchifa > 0 && dianchifa < 15) event = dianchifa + "号电磁阀打开了" else if (dianchifa = 32) level1 = 0;event = "1号探纬下降沿" else if (dianchifa = 33) level1 = 1;event = "1号探纬上升沿" else if (dianchifa = 34) level2 = 0;event = "2号探纬下降沿" else if (dianchifa = 35) level2 = 1;event = "2号探纬上升沿"System.out.println("1号探尾电平:" + level1);System.out.println("2号探尾电平:" + level2);System.out.println("现在的时间是:" + nowtime);mainframe.getInstantInfo().setTimeinfo(nowtime + "s");/在面板上显示时间信息System.out.println("现在的角度是:" + angle);mainframe.getInstantInfo().setAngleinfo(angle + "°");/在面板上显示角度信息System.out.println(event);mainframe.getInstantInfo().setEventinfo(event);/在面板上显示事件信息detail.setTestdate(testdate);detail.setTestid(tid);detail.setRoundnum(quanshu);detail.setSpeed(sudu);detail.setTime(nowtime / 1000);detail.setAngle(angle);detail.setLev1(level1);detail.setLev2(level2);detail.setEvent(event);new DetailDaoimpl().doCreate(detail);/ 创建该圈在特定时刻下的详细信息类,并用批处理添加 else mainframe.getInstantInfo().setEventinfo("数据错误!");return;if (input0 + datacountresult = 0x00) / 判断是否达到byte数组结尾JDBCExecutor.getJDBCExecutor().executeBatch();/ 将该圈所有信息提交至数据库System.out.println("the end");return;3.2Check.javapackage org.genius.controlsystem.analyse;import javax.swing.JDialog;import org.genius.controlsystem.ui.RadioTube;/* * 数据检测实现类 * * * */public class Checkprivate static byte Closemotor = new byte 0x10, 0x01, 0x00, 0x07, 0x00, 0x20, (byte) 0x81, 0x00, 0x00, 0x01,(byte) 0xFF, 0x10, 0x02 ;private static byte Normalstar = new byte 0x10, 0x01, 0x00, 0x03, 0x00, 0x13, 0x01, 0x10, 0x02 ;private static byte Normaltriangle = new byte 0x10, 0x01, 0x00, 0x03, 0x00, 0x13, 0x02, 0x10, 0x02 ;private static byte Slowstar = new byte 0x10, 0x01, 0x00, 0x07, 0x00, 0x20, (byte) 0x81, 0x00, 0x00, 0x01,(byte) 0xF5, 0x10, 0x02 ;private static byte Slowtriangle = new byte 0x10, 0x01, 0x00, 0x03, 0x00, 0x13, 0x04, 0x10, 0x02 ;public static byte input = new byte 0x10, 0x01, 0x00, 0x04, 0x00, 0x12, 0x00, 0x01, 0x10, 0x02 ;public static byte output = new byte 0x10, 0x01, 0x00, 0x04, 0x00, 0x12, 0x00, 0x02, 0x10, 0x02 ;public static byte high = new byte 0x10, 0x01, 0x00, 0x04, 0x00, 0x11, 0x00, 0x01, 0x10, 0x02 ;public static byte low = new byte 0x10, 0x01, 0x00, 0x04, 0x00, 0x11, 0x00, 0x02, 0x10, 0x02 ;public Check()/ TODO Auto-generated constructor stubpublic static int ReturnCheck(byte b) throws Exceptionif (b0 = 0x10 && b1 = 0x01 && b2 = 0x00 && b3 = 0x22&& b4 = 0x00 && b5 = 0x40)RadioTube radiotube = RadioTube.getInstance();int temp;for (int i = 6, j = 1; i <= 20; i+)temp = 256 * (bi & 0xff) + (bi + 1 & 0xff);i+;radiotube.jtf1j.setText("" + temp);j+;System.out.println(temp);for (int i = 22, j = 1; i <= 36; i+)temp = 256 * (bi & 0xff) + (bi + 1 & 0xff);i+;radiotube.jtf2j.setText("" + temp);j+;return 11;if (equals(b, Closemotor)return 1;/ 表示接受到的数据为关闭电机反馈确认信息else if (equals(b, Normalstar)return 2;/ 表示接受到的数据为常速星形反馈确认信息else if (equals(b, Slowstar)return 3;/ 表示接受到的数据为慢速星形反馈确认信息else if (equals(b, Slowtriangle)return 4;/ 表示接受到的数据为慢速三角反馈确认信息else if (equals(b, input)return 5;/ 表示接受到的数据为输入反馈确认信息else if (equals(b, output)return 6;/ 表示接受到的数据为输出反馈确认信息else if (equals(b, high)return 7;/ 表示接受到的数据为高电平反馈确认信息else if (equals(b, low)return 8;/ 表示接受到的数据为低电平反馈确认信息else if (b0 = 0 && b1 = 0 && b2 = 0 && b3 = 0 && b10 = 0&& b11 = 0 && b12 = 0 && b13 = 0 && b14 = 0)return 10; else if (b10 = 0 && b11 = 0 && b12 = 0 && b13 = 0&& b14 = 0)System.out.println("wrong data");return 9;return 0;/* * 判断两个数组是否相等实现类 * * param a * param b * return */public static boolean equals(byte a, byte b)for