喷气织机监控系统源代码-全部.doc

上传人:wux****ua 文档编号:9105631 上传时间:2020-04-03 格式:DOC 页数:61 大小:256.50KB
返回 下载 相关 举报
喷气织机监控系统源代码-全部.doc_第1页
第1页 / 共61页
喷气织机监控系统源代码-全部.doc_第2页
第2页 / 共61页
喷气织机监控系统源代码-全部.doc_第3页
第3页 / 共61页
点击查看更多>>
资源描述
喷气织机监控系统源代码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 16 & 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 (int i = 0; i 9; i+)if (ai != bi)return false;return true;4.org.genius.controlsystem.dao4.1IDetailDao.javapackage org.genius.controlsystem.dao;import java.util.List;import org.genius.controlsystem.vo.Detail;/* * 详细信息DAO借口 * * * */public interface IDetailDao/* * 向数据库添加一条记录,记录中包含一圈中特定时刻的信息 * * param detail * return * throws Exception */public boolean doCreate(Detail detail) throws Exception;/* * * 根据测试编号和圈数执行查询操作,返回该圈特定时刻信息 * * param t_id * param roundnum * return * throws Exception */public List finddata(String testdate, int t_id, int roundnum)throws Exception;4.2ITestDao.javapackage org.genius.controlsystem.dao;import java.util.List;import org.genius.controlsystem.vo.Test;/* * 测试DAO接口 * * * */public interface ITestDao/* * 表示数据库的增加、更新操作 * * param test * return * throws Exception */public boolean doCreate(Test test) throws Exception;public boolean doUpdate(Test test) throws Exception;/* * 按测试日期进行数据库的查询操作,返回一组测试对象 * * param test_date * return * throws Exception */public List findByTestDate(String testdate) throws Exception;/* * 根据测试日期和测试编号进行数据库的查询操作,返回一个测试对象 * * param test_date * param test_id * return * throws Exception */public Test findByTestDate_Id(String testdate, int testid) throws Exception;/* * 查找所有测试对象 * * return * throws Exception */public List findAll() throws Exception;5.org.genius.controlsystem.dao.impl5.1DetailDaoimpl.javapackage org.genius.controlsystem.dao.impl;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import org.genius.controlsystem.dao.IDetailDao;import org.genius.controlsystem.jdbc.JDBCExecutor;import org.genius.controlsystem.vo.Detail;import org.genius.controlsystem.vo.Test;/* * 详细信息实现类 * * * */public class DetailDaoimpl implements IDetailDaopublic DetailDaoimpl()/ TODO Auto-generated constructor stubOverridepublic boolean doCreate(Detail detail) throws Exception/ TODO Auto-generated method stubString sql = INSERT INTO Detail(id,testdate,testid,roundnum,speed,time,angle,lev1,lev2,event) VALUES (detailseq.nextval,?,?,?,?,?,?,?,?,?) ;JDBCExecutor.getJDBCExecutor().addBatch(sql, detail);return false;Overridepublic List finddata(String testdate, int tid, int roundnum)throws Exception/ TODO Auto-generated method stubList all = new ArrayList();String sql = SELECT lev1,lev2,time FROM Detail where testid = + tid+ and roundnum= + roundnum + and testdate= + + testdate+ ;ResultSet rs = JDBCExecutor.getJDBCExecutor().executeQuery(sql);while (rs.next()Detail detail = new Detail();detail.setLev1(rs.getInt(1);detail.setLev2(rs.getInt(2);detail.setTime(rs.getInt(3);all.add(detail);return all;5.2TestDaoimpl.javapackage org.genius.controlsystem.dao.impl;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import org.genius.controlsystem.dao.ITestDao;import org.genius.controlsystem.jdbc.JDBCExecutor;import org.genius.controlsystem.vo.Test;public class TestDaoimpl implements ITestDaopublic TestDaoimpl()/ TODO Auto-generated constructor stubOverridepublic boolean doCreate(Test test) throws Exception/ TODO Auto-generated method stubString sql = INSERT INTO Test(id,testdate,testid,starttime,endtime,totalround)values(testseq.nextval,?,?,?,?,?);JDBCExecutor.getJDBCExecutor().executeUpdate(sql, test);return false;Overridepublic boolean doUpdate(Test test) throws Exception/ TODO Auto-generated method stubString sql = UPDATE Test SET endtime= + test.getEndtime()+ ,totalround= + test.getTotalround() + where id=+ test.getId();JDBCExecutor.getJDBCExecutor().executeUpdate(sql);return false;Overridepublic List findByTestDate(String testdate) throws Exception/ TODO Auto-generated method stubList all = new ArrayList();String sql = SELECT testid FROM Test where testdate = + testdate+ ;ResultSet rs = JDBCExecutor.getJDBCExecutor().executeQuery(sql);while (rs.next()Test test = new Test();test.setTest_id(rs.getInt(1);all.add(test);return all;Overridepublic Test findByTestDate_Id(String testdate, int testid) throws Exception/ TODO Auto-generated method stubTest test = new Test();String sql = SELECT id,starttime,endtime,totalround FROM Test where testdate =+ testdate + and testid= + testid;ResultSet rs = JDBCExecutor.getJDBCExecuto
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!