package com.dev.fbs9600_groupvol;
|
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Font;
|
import java.awt.GridLayout;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
|
import javax.swing.BoxLayout;
|
import javax.swing.JButton;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JTextField;
|
import javax.swing.UIManager;
|
import javax.swing.border.TitledBorder;
|
|
import com.LimitedDocument;
|
import java.awt.FlowLayout;
|
|
import javax.swing.JTabbedPane;
|
|
import main.page_debug_inf;
|
import javax.swing.JLabel;
|
|
public class FCF651_groupvol_page extends JPanel {
|
public SPCommGroupVol Comm_Vol;
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
private JTextField tf_addr;
|
private JTextField tf_version;
|
private JTextField tf_vol;
|
private JTextField tf_offset_val;
|
private JTextField tf_slope_val;
|
private JTextField tf_real_vol1;
|
private JTextField tf_vol_messure1;
|
private JTextField tf_vol_offset;
|
private JTextField tf_vol_slope;
|
private JTextField tf_vol_messure2;
|
|
private JButton btn_vol_cal2;
|
private JButton btn_vol_cal1;
|
private JButton btn_exe_cal;
|
private JPanel panel;
|
private JTabbedPane tabbedPane;
|
|
private page_debug_inf panel_debug;
|
private JTextField tf_real_vol2;
|
private JPanel panel_1;
|
private JPanel panel_2;
|
private JPanel panel_8;
|
private JButton btn_reset_cal;
|
private JPanel panel_9;
|
private JTextField tf_set_addr;
|
private JButton btn_set_addr;
|
private JLabel lblNewLabel;
|
|
/**
|
* Create the panel.
|
*/
|
public FCF651_groupvol_page() {
|
setLayout(new BorderLayout(0, 0));
|
|
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
add(tabbedPane, BorderLayout.CENTER);
|
|
panel = new JPanel();
|
tabbedPane.addTab("\u57FA\u672C\u6D4B\u8BD5", null, panel, null);
|
panel.setLayout(new BorderLayout(0, 0));
|
|
panel_8 = new JPanel();
|
panel.add(panel_8, BorderLayout.NORTH);
|
panel_8.setLayout(new GridLayout(0, 1, 0, 0));
|
|
JPanel panel_4 = new JPanel();
|
panel_8.add(panel_4);
|
panel_4.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6A21\u5757\u6570\u636E", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_4.setLayout(new GridLayout(0, 5, 0, 0));
|
|
JPanel panel_5 = new JPanel();
|
panel_5.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6A21\u5757\u5730\u5740", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_4.add(panel_5);
|
panel_5.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_addr = new JTextField();
|
tf_addr.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
tf_addr.setEditable(false);
|
panel_5.add(tf_addr);
|
tf_addr.setColumns(10);
|
|
JPanel panel_6 = new JPanel();
|
panel_6.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6A21\u5757\u7248\u672C", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_4.add(panel_6);
|
panel_6.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_version = new JTextField();
|
tf_version.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
tf_version.setEditable(false);
|
panel_6.add(tf_version);
|
tf_version.setColumns(10);
|
|
JPanel panel_11 = new JPanel();
|
panel_4.add(panel_11);
|
panel_11.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u7535\u538B\u503C(V)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_11.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_vol = new JTextField();
|
tf_vol.setEditable(false);
|
tf_vol.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_11.add(tf_vol);
|
tf_vol.setColumns(10);
|
|
JPanel panel_13 = new JPanel();
|
panel_4.add(panel_13);
|
panel_13.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u504F\u79FB\u503C(mV)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_13.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_offset_val = new JTextField();
|
tf_offset_val.setEditable(false);
|
panel_13.add(tf_offset_val);
|
tf_offset_val.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
//tf_offset_val.setDocument(new LimitedDocument(10, "0123456789"));
|
tf_offset_val.setColumns(10);
|
|
JPanel panel_22 = new JPanel();
|
panel_4.add(panel_22);
|
panel_22.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u659C\u7387\u503C", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_22.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_slope_val = new JTextField();
|
tf_slope_val.setEditable(false);
|
tf_slope_val.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
//tf_slope_val.setDocument(new LimitedDocument(6, "0123456789"));
|
panel_22.add(tf_slope_val);
|
tf_slope_val.setColumns(10);
|
|
JPanel panel_12 = new JPanel();
|
panel_8.add(panel_12);
|
panel_12.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u7535\u538B\u6821\u51C6", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_12.setLayout(new BoxLayout(panel_12, BoxLayout.X_AXIS));
|
|
panel_1 = new JPanel();
|
panel_12.add(panel_1);
|
|
JPanel panel_14 = new JPanel();
|
panel_1.add(panel_14);
|
panel_14.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u5B9E\u9645\u7535\u538BA (V)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_14.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_real_vol1 = new JTextField();
|
tf_real_vol1.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_14.add(tf_real_vol1);
|
tf_real_vol1.setDocument(new LimitedDocument(10, ".0123456789"));
|
tf_real_vol1.setColumns(10);
|
|
JPanel panel_24 = new JPanel();
|
panel_1.add(panel_24);
|
panel_24.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6D4B\u91CF\u7535\u538BA (V)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_24.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_vol_messure1 = new JTextField();
|
tf_vol_messure1.setEditable(false);
|
tf_vol_messure1.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
//tf_vol_messure1.setDocument(new LimitedDocument(5, "0123456789."));
|
panel_24.add(tf_vol_messure1);
|
tf_vol_messure1.setColumns(10);
|
|
btn_vol_cal1 = new JButton("\u53D6\u6821\u51C6\u70B9A");
|
btn_vol_cal1.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_1.add(btn_vol_cal1);
|
btn_vol_cal1.setEnabled(false);
|
btn_vol_cal1.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(null != Comm_Vol) {
|
if (tf_real_vol1.getText().length() <= 0) {
|
JOptionPane.showMessageDialog(null, "ÇëÊäÈëÐèҪУ׼µÄʵ¼Êµçѹ1Öµ!");
|
return;
|
}
|
|
tf_vol_messure1.setText(tf_vol.getText());
|
}
|
}
|
});
|
|
panel_2 = new JPanel();
|
panel_12.add(panel_2);
|
|
JPanel panel_36 = new JPanel();
|
panel_2.add(panel_36);
|
panel_36.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u5B9E\u9645\u7535\u538BB (V)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_36.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_real_vol2 = new JTextField();
|
tf_real_vol2.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
tf_real_vol2.setDocument(new LimitedDocument(10, ".0123456789"));
|
tf_real_vol2.setColumns(10);
|
panel_36.add(tf_real_vol2);
|
|
JPanel panel_77 = new JPanel();
|
panel_2.add(panel_77);
|
panel_77.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6D4B\u91CF\u7535\u538BB (V)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_77.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_vol_messure2 = new JTextField();
|
tf_vol_messure2.setEditable(false);
|
tf_vol_messure2.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_77.add(tf_vol_messure2);
|
tf_vol_messure2.setColumns(10);
|
//tf_vol_messure2.setDocument(new LimitedDocument(10, "0123456789."));
|
|
btn_vol_cal2 = new JButton("\u53D6\u6821\u51C6\u70B9B");
|
btn_vol_cal2.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_2.add(btn_vol_cal2);
|
btn_vol_cal2.setEnabled(false);
|
btn_vol_cal2.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
if(null != Comm_Vol) {
|
if (tf_real_vol1.getText().length() <= 0) {
|
JOptionPane.showMessageDialog(null, "ÇëÊäÈëÐèҪУ׼µÄʵ¼Êµçѹ1Öµ!");
|
return;
|
}
|
if (tf_real_vol2.getText().length() <= 0) {
|
JOptionPane.showMessageDialog(null, "ÇëÊäÈëÐèҪУ׼µÄʵ¼Êµçѹ2Öµ!");
|
return;
|
}
|
|
tf_vol_messure2.setText(tf_vol.getText());
|
try{
|
double y2 = Double.parseDouble(tf_real_vol2.getText().trim());
|
double y1 = Double.parseDouble(tf_real_vol1.getText().trim());
|
double x2 = Double.parseDouble(tf_vol_messure2.getText().trim());
|
double x1 = Double.parseDouble(tf_vol_messure1.getText().trim());
|
|
if(Math.abs(x2-x1) < 1) {
|
JOptionPane.showMessageDialog(null, "Á½´Î²âÁ¿µçѹֵ֮¼ä²î¾à̫С,²»ÄÜУ׼!");
|
return;
|
}
|
|
double a = (y2-y1)/(x2-x1);
|
tf_vol_slope.setText(String.valueOf((int)(a*50000 + 0.5)));
|
tf_vol_offset.setText(String.valueOf((int)((y2 - x2*a)*1000)));
|
} catch (Exception e) {
|
JOptionPane.showMessageDialog(null, "ÇëÊäÈëÓÐЧµÄʵ¼Êµçѹֵ!");
|
return;
|
}
|
}
|
}
|
});
|
|
JPanel panel_15 = new JPanel();
|
panel_8.add(panel_15);
|
panel_15.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6821\u51C6\u53C2\u6570", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_15.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
btn_reset_cal = new JButton("\u590D\u4F4D\u6821\u51C6\u53C2\u6570");
|
btn_reset_cal.setEnabled(false);
|
btn_reset_cal.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
if(null != Comm_Vol) {
|
Comm_Vol.setCommCmd(SPCommGroupVol.CMD_TYPE_WRITE_Multy,
|
SPCommGroupVol.UART_MonomerAdjOffSet_RegAddr,
|
(short) 2,
|
(short) 0, (short) 50000);
|
}
|
}
|
});
|
btn_reset_cal.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_15.add(btn_reset_cal);
|
|
JPanel panel_3 = new JPanel();
|
panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u7535\u538B\u504F\u79FB\u503C(mV)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_15.add(panel_3);
|
panel_3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_vol_offset = new JTextField();
|
tf_vol_offset.setEditable(false);
|
tf_vol_offset.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
tf_vol_offset.setColumns(10);
|
panel_3.add(tf_vol_offset);
|
|
JPanel panel_7 = new JPanel();
|
panel_7.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u7535\u538B\u659C\u7387\u503C", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
panel_15.add(panel_7);
|
panel_7.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
|
tf_vol_slope = new JTextField();
|
tf_vol_slope.setEditable(false);
|
tf_vol_slope.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
//tf_vol_slope.setDocument(new LimitedDocument(5, "0123456789."));
|
tf_vol_slope.setColumns(10);
|
panel_7.add(tf_vol_slope);
|
|
btn_exe_cal = new JButton("\u4E0B\u53D1\u6821\u51C6\u53C2\u6570");
|
btn_exe_cal.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_15.add(btn_exe_cal);
|
btn_exe_cal.setEnabled(false);
|
|
lblNewLabel = new JLabel(" ");
|
panel_15.add(lblNewLabel);
|
|
panel_9 = new JPanel();
|
panel_9.setBorder(new TitledBorder(null, "\u5730\u5740\u8BBE\u7F6E", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panel_15.add(panel_9);
|
|
tf_set_addr = new JTextField();
|
tf_set_addr.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_9.add(tf_set_addr);
|
tf_set_addr.setDocument(new LimitedDocument(3, "0123456789"));
|
tf_set_addr.setColumns(10);
|
|
btn_set_addr = new JButton("\u8BBE\u7F6E");
|
btn_set_addr.setEnabled(false);
|
btn_set_addr.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(null != Comm_Vol) {
|
String addr = tf_set_addr.getText().trim();
|
if((addr.length() < 1) || (addr.length() < 1)) {
|
JOptionPane.showMessageDialog(null, "µØÖ·¸ñʽ²»ÕýÈ·!");
|
return;
|
}
|
|
int addr_s = Integer.parseInt(addr);
|
if(addr_s > 250) {
|
JOptionPane.showMessageDialog(null, "µØÖ·²»Äܳ¬¹ý250!");
|
return;
|
}
|
|
Comm_Vol.setCommCmd(SPCommGroupVol.CMD_TYPE_WRITE_Multy,
|
SPCommGroupVol.UART_MonomerSetAddr_RegAddr,
|
(short) 1,
|
(short) addr_s, (short) 0);
|
}
|
}
|
});
|
btn_set_addr.setFont(new Font("ËÎÌå", Font.PLAIN, 18));
|
panel_9.add(btn_set_addr);
|
btn_exe_cal.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(null != Comm_Vol) {
|
String offset = tf_vol_offset.getText().trim();
|
String slope = tf_vol_slope.getText().trim();
|
|
if((offset.length() < 1) || (slope.length() < 1)) {
|
JOptionPane.showMessageDialog(null, "У׼²ÎÊý²»ÕýÈ·!");
|
return;
|
}
|
|
try {
|
int offset_s = Integer.parseInt(offset);
|
int slpoe_s = Integer.parseInt(slope);
|
if(Math.abs(offset_s) > 3000) {
|
JOptionPane.showMessageDialog(null, "Æ«ÒÆÁ¿ÊýÖµ³¬¹ý3000,²»ÄÜУ׼!");
|
return;
|
}
|
if(Math.abs(slpoe_s-50000) > 10000) {
|
JOptionPane.showMessageDialog(null, "бÂÊÊýֵƫ²î³¬¹ý50000µÄ20%,²»ÄÜУ׼!");
|
return;
|
}
|
|
Comm_Vol.setCommCmd(SPCommGroupVol.CMD_TYPE_WRITE_Multy,
|
SPCommGroupVol.UART_MonomerAdjOffSet_RegAddr,
|
(short) 2,
|
(short)offset_s, (short)slpoe_s);
|
} catch (Exception e1) {
|
JOptionPane.showMessageDialog(null, "У׼²ÎÊýÊýÖµ¸ñʽ²»ÕýÈ·!");
|
return;
|
}
|
|
tf_vol_messure1.setText("");
|
tf_vol_messure2.setText("");
|
tf_vol_offset.setText("");
|
tf_vol_slope.setText("");
|
}
|
}
|
});
|
|
panel_debug = new page_debug_inf();
|
tabbedPane.addTab("\u8C03\u8BD5\u4FE1\u606F", null, panel_debug, null);
|
}
|
|
public void setButttonState(boolean state) {
|
btn_vol_cal2.setEnabled(state);
|
btn_vol_cal1.setEnabled(state);
|
btn_exe_cal.setEnabled(state);
|
btn_reset_cal.setEnabled(state);
|
btn_set_addr.setEnabled(state);
|
}
|
|
public boolean openCommPort(int comm_type, String spname_or_ipaddr, int bitrate_or_ipport,
|
int dev_type, int multy_comm_type, JTextField tf_addr) {
|
boolean res = false;
|
Comm_Vol = new SPCommGroupVol(tf_addr, bitrate_or_ipport, dev_type, multy_comm_type, panel_debug);
|
|
if(true == Comm_Vol.OpenCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport)) {
|
Thread spcommThread = new Thread(Comm_Vol);
|
spcommThread.start();
|
|
setButttonState(true);
|
|
res = true;
|
}
|
|
return res;
|
}
|
|
public void closeCommPort() {
|
if(null != Comm_Vol) {
|
Comm_Vol.exitCommPortThread();
|
Comm_Vol = null;
|
|
setButttonState(false);
|
}
|
}
|
|
public void updateData() {
|
try{
|
if(null != Comm_Vol) {
|
tf_addr.setText(String.format("%d", Comm_Vol.dt_addr));
|
tf_version.setText(String.format("V%1.2f", ((double)Comm_Vol.dt_version)/100));
|
|
tf_vol.setText(String.format("%1.3f", ((double)Comm_Vol.dt_vol)/1000));
|
|
tf_offset_val.setText(String.format("%d", Comm_Vol.dt_volcal_offset));
|
tf_slope_val.setText(String.format("%d", Comm_Vol.dt_volcal_slope));
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
//JOptionPane.showMessageDialog(null, "updateData():" + e.getMessage());
|
}
|
}
|
}
|