DELL
2024-08-30 9792926a4a3054f1b2f72e6fc8c810103bb81c16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
package main;
import java.awt.EventQueue;
 
import javax.swing.JFrame;
 
import java.awt.Panel;
import java.awt.BorderLayout;
 
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JButton;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.Timer;
 
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;
 
import javax.swing.JTextField;
import javax.swing.UIManager;
 
import java.awt.Color;
import java.nio.ByteBuffer;
import java.util.Date;
 
import javax.swing.JTabbedPane;
 
import java.awt.Font;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
 
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
 
import sp_comm.CommSerialPort;
 
import com.Com;
import com.LimitedDocument;
import com.dev.btsm.bts_page_base;
import com.dev.bybb.bybb_page_base;
import com.dev.fbs9600_curr.module_curr_page;
import com.dev.fbs9600_groupvol.FCF651_groupvol_page;
import com.dev.fbs9600_groupvol.module_vol_page;
import com.dev.fbs9600_mon.SPCommMon;
import com.dev.fbs9600_mon.module_mon_page;
import com.dev.fbs9600_zdhj.zdhj_page_base;
import com.dev.nrf_lora_tester.loratester_page_base;
import com.dev.ntm.ntm_page_base;
 
import javax.swing.BoxLayout;
 
import java.awt.Dimension;
import java.awt.FlowLayout;
 
import javax.swing.JLabel;
import javax.swing.ImageIcon;
 
import java.awt.GridLayout;
 
import javax.swing.SwingConstants;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
public class main_window {
    public static final int  CommDevType_MON = 0;
    public static final int  CommDevType_CURR = 1;
    public static final int  CommDevType_GROUPVOL = 2;
    public static final int  CommDevType_FCF651VOL = 3;
    public static final int  CommDevType_ZDHJ = 4;
    public static final int  CommDevType_FBS9100 = 5;
    public static final int  CommDevType_NTM = 6;
    public static final int  CommDevType_LoraTest = 7;
    public static final int  CommDevType_BYBB = 8;
    
    public static final float  BattResLowLimit = (float) 0.95;
    public static final float  BattResHighLimit = (float) 1.05;
    
    public static int LANG_TYPE_CN = 0;
    public static int LANG_TYPE_EN = 1;
    
    //public String mTitle = "MSP&SAM&SWM&Curr_V1.523_220424G";
    public String mTitle = "»ã¼¯Ä£¿éµ÷ÊÔ¹¤¾ß_V1.525_ZJ";
    
    public static int LANG_TYPE    = LANG_TYPE_CN;
    public static final boolean APP_FBS9600_MON_EN = true;
    public static final boolean APP_FBS9600_CURR_EN    = false;
    public static final boolean APP_FBS9600_GVOL_EN    = false;
    public static final boolean APP_FCF_GVOL_EN    = false;
    public static final boolean APP_FBS9600_ZDHJ_EN = true;
    public static final boolean APP_BTSM_EN = false;
    public static final boolean APP_NTM_EN = false;
    public static final boolean APP_NTM_LORA_EN = false;
    public static final boolean APP_BYBB_EN = false;
    
    public int CommDevType = CommDevType_ZDHJ;        //ĬÈÏÏÔʾtabÑ¡Ï
    
    public boolean isDebugMode = true;                //ÊÇ·ñΪµ÷ÊÔģʽtrue:µ÷ÊÔģʽ     false:´ò°üģʽ[»áÒþ²Ø×ó²àÑ¡Ï]
    
    public boolean MonVol_Is_Adj = false;
    public boolean MonRes_Is_Test = false;
    public boolean MonBianHao_Is_Test = false;
    public String mLastTestID = "";
    
    private JFrame frmSerialport;
    private JButton btn_connet;
    private JButton btn_break;
    private JComboBox<String> cb_commport;
    private JTextField tf_target_addr;
    private JTextField tf_txcnt;
    private JTextField tf_rxcnt;
    
    private Timer mMainFormTimer = null;
    static private ByteBuffer DataBuffer = ByteBuffer.allocate(256); 
    private JTabbedPane main_TabbedPane;
    private JButton btn_renew_commport;
    private JComboBox<String> cb_comm_bitrate;
    
    private JComboBox<?> cb_dev_type;
    private JButton btnNewButton;
    private JButton btnNewButton_1;
    private JLabel label;
    private JTabbedPane tab_comm_type;
    private JPanel panel_3;
    private JTextField tf_ip_addr;
    private JTextField tf_ip_port;
    
    private module_mon_page panel_mon_base;
    private module_curr_page panel_Curr_Module;
    private module_vol_page panel_groupVol_Module;
    private FCF651_groupvol_page panel_fcf651Vol_Module;
    private zdhj_page_base panel_ZDHJ_base;
    private bts_page_base panel_FBS9100_base;
    private ntm_page_base panel_NTM_base;
    private loratester_page_base panel_LoraTest_base;
    private bybb_page_base panel_bybb_base;
    /*********************************************************************************************/
    static Logger m_Log = null;
    @SuppressWarnings("rawtypes")
    private JComboBox cb_tcp_udp;
    static {
        System.setProperty("log4j.configurationFile", "log4j2_batt_dev.xml");
    //    System.setProperty("contextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
    }
    /*********************************************************************************************/
    
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        m_Log = LogManager.getLogger(main_window.class);
        
        //int dat = -30;
        //System.out.println(String.format("dat=%4X", dat));
        
        byte[] bf = new byte[8];
        for(int n=0; n<bf.length; n++) {
            bf[n] = (byte) n;
        }
        //short crc1 = Crc16.CalModBusCRC16(bf, bf.length);
        //short crc2 = Crc16.CalCRC16(bf, bf.length);
        //System.out.println("crc1:" + (crc1&0xFFFF) + ", " + "crc2:" + crc2);
        /*
        CRC32 crc32 = new CRC32();
        crc32.reset();
        crc32.update(bf);
        System.out.println(ComFn.bytesToHexString(bf, bf.length));
        System.out.println("byte[] crc32.getValue():" + crc32.getValue());
        
        crc32.reset();
        ByteBuffer bb = ByteBuffer.allocate(bf.length);
        bb.put(bf);
        bb.flip();
        crc32.update(bb);
        System.out.println("ByteBuffer crc32.getValue():" + crc32.getValue());
        */
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    main_window window = new main_window();
                    window.frmSerialport.setVisible(true);
                } catch (Exception e) {
                    m_Log.error(e.toString(), e);
                }
            }
        });
    }
 
    /**
     * Create the application.
     */
    public main_window() {
        /*
        String skin_type = "SubstanceBusinessLookAndFeel";
        int type_id = 8;
        switch(type_id) {
        case 1:skin_type = "SubstanceBusinessLookAndFeel"; break;
        case 2:skin_type = "SubstanceOfficeSilver2007LookAndFeel"; break;
        case 3:skin_type = "SubstanceOfficeBlue2007LookAndFeel"; break;
        case 4:skin_type = "SubstanceSaharaLookAndFeel"; break;
        case 5:skin_type = "SubstanceBusinessBlackSteelLookAndFeel"; break;
        case 6:skin_type = "SubstanceChallengerDeepLookAndFeel"; break;
        case 7:skin_type = "SubstanceCremeCoffeeLookAndFeel"; break;
        case 8:skin_type = "SubstanceCremeLookAndFeel"; break;
        case 9:skin_type = "SubstanceDustCoffeeLookAndFeel"; break;
        case 10:skin_type = "SubstanceEmeraldDuskLookAndFeel"; break;
        case 11:skin_type = "SubstanceMagmaLookAndFeel"; break;
        case 12:skin_type = "SubstanceMistAquaLookAndFeel"; break;
        case 13:skin_type = "SubstanceMistSilverLookAndFeel"; break;
        case 14:skin_type = "SubstanceModerateLookAndFeel"; break;
        case 15:skin_type = "SubstanceNebulaBrickWallLookAndFeel"; break;
        case 16:skin_type = "SubstanceNebulaLookAndFeel"; break;
        case 17:skin_type = "SubstanceRavenGraphiteGlassLookAndFeel"; break;
        case 18:skin_type = "SubstanceRavenGraphiteLookAndFeel"; break;
        case 19:skin_type = "SubstanceRavenLookAndFeel"; break;
        case 20:skin_type = "SubstanceSaharaLookAndFeel"; break;
        case 21:skin_type = "SubstanceTwilightLookAndFeel"; break;
        }
        try {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            UIManager.setLookAndFeel("org.jvnet.substance.skin." + skin_type);
        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedLookAndFeelException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        */
        initialize();
    }
 
    /**
     * Initialize the contents of the frame.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    private void initialize() {
        frmSerialport = new JFrame();
        frmSerialport.setFont(new Font("ËÎÌå", Font.PLAIN, 12));
        //frmSerialport.setResizable(false);
        frmSerialport.setTitle(mTitle);
        if(LANG_TYPE_EN == LANG_TYPE) {
            frmSerialport.setTitle(this.mTitle + "_EN");
        }
        frmSerialport.setIconImage(Toolkit.getDefaultToolkit().getImage(main_window.class.getResource("/main/12164006.png")));
        frmSerialport.setBounds(100, 100, 1030, 640);
        frmSerialport.setMinimumSize(new Dimension(1030, 640) );
        frmSerialport.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frmSerialport.setLocationRelativeTo(null);
        
        Panel panel = new Panel();
        frmSerialport.getContentPane().add(panel, BorderLayout.NORTH);
        String comm_title = "ͨÐŵØÖ· / ²¨ÌØÂÊ";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Comm Addr / Bit Rate";
        }
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        
        JPanel panel_80 = new JPanel();
        panel_80.setLayout(new GridLayout(0, 1));
        
        tab_comm_type = new JTabbedPane(JTabbedPane.TOP);
        panel_80.add(tab_comm_type);
        
        panel.add(panel_80);
        
        JPanel panel_8 = new JPanel();
        tab_comm_type.addTab("RS485\u901A\u4FE1", null, panel_8, null);
        panel_8.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u4E32\u53E3\u53F7 / \u6CE2\u7279\u7387", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel_8.setLayout(new FlowLayout(FlowLayout.CENTER, 2, 0));
        btn_renew_commport = new JButton("\u5237\u65B0");
        panel_8.add(btn_renew_commport);
        btn_renew_commport.setIcon(new ImageIcon(main_window.class.getResource("/png_16x16/arrow_refresh.png")));
        btn_renew_commport.setFont(new Font("ËÎÌå", Font.PLAIN, 12));
        btn_renew_commport.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                CommSerialPort.searchCommPort(cb_commport);
                if(cb_commport.getItemCount() > 0) {
                    cb_commport.setSelectedIndex(0);
                }
            }
        });
        
        cb_commport = new JComboBox<String>();
        panel_8.add(cb_commport);
        //cb_commport.setModel(new DefaultComboBoxModel<String>(new String[] {"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11", "COM12"}));
        CommSerialPort.searchCommPort(cb_commport);
        
        cb_comm_bitrate = new JComboBox();
        cb_comm_bitrate.setModel(new DefaultComboBoxModel(new String[] {"2400", "4800", "9600", "19200", "38400", "57600", "115200"}));
        cb_comm_bitrate.setSelectedIndex(2);
        panel_8.add(cb_comm_bitrate);
        
        cb_dev_type = new JComboBox();
        cb_dev_type.setModel(new DefaultComboBoxModel(new String[] {"SAM", "MSP", "MSP_RF", "SWM(\u534E\u82AF\u5A01\u7279)"}));
        panel_8.add(cb_dev_type);
        
        label = new JLabel("");
        panel_8.add(label);
        
        panel_3 = new JPanel();
        FlowLayout flowLayout = (FlowLayout) panel_3.getLayout();
        flowLayout.setVgap(0);
        panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "IP\u5730\u5740  /  \u7AEF\u53E3", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        tab_comm_type.addTab("\u4EE5\u592A\u7F51\u901A\u4FE1", null, panel_3, null);
        
        cb_tcp_udp = new JComboBox();
        cb_tcp_udp.setEnabled(false);
        cb_tcp_udp.setModel(new DefaultComboBoxModel(new String[] {"TCP", "UDP"}));
        panel_3.add(cb_tcp_udp);
        
        tf_ip_addr = new JTextField();
        tf_ip_addr.setDocument(new LimitedDocument(16, "0123456789."));
        tf_ip_addr.setText("192.168.10.102");
        panel_3.add(tf_ip_addr);
        tf_ip_addr.setColumns(10);
        
        tf_ip_port = new JTextField();
        tf_ip_port.setDocument(new LimitedDocument(6, "0123456789"));
        tf_ip_port.setText("1025");
        panel_3.add(tf_ip_port);
        tf_ip_port.setColumns(10);
        
        JPanel panel_1 = new JPanel();
        comm_title = "´®¿ÚºÅ";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Comm Port";
        }
        panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u8BBE\u5907\u5730\u5740", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel.add(panel_1);
        if(cb_commport.getItemCount() > 0) {
            cb_commport.setSelectedIndex(0);
        }
        
        comm_title = "Ë¢ÐÂ";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Reflesh";
        }
        panel_1.setLayout(new GridLayout(0, 3, 0, 0));
        
        btnNewButton = new JButton("\u4E0A\u4E00\u4E2A");
        panel_1.add(btnNewButton);
        btnNewButton.setIcon(new ImageIcon(main_window.class.getResource("/png_16x16/arrow_left.png")));
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int addr = Integer.parseInt(tf_target_addr.getText());
                if(addr > 0) {
                    addr -= 1;
                } else {
                    addr = 255;
                }
                tf_target_addr.setText(String.valueOf(addr));
            }
        });
        
        tf_target_addr = new JTextField();
        tf_target_addr.setHorizontalAlignment(SwingConstants.CENTER);
        tf_target_addr.setFont(new Font("ËÎÌå", Font.PLAIN, 32));
        panel_1.add(tf_target_addr);
        tf_target_addr.addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
                if(tf_target_addr.getText().trim().length() < 1) {
                    tf_target_addr.setText("255");
                }
            }
        });
        tf_target_addr.setDocument(new LimitedDocument(3, "0123456789"));
        tf_target_addr.setText("255");
        tf_target_addr.setColumns(4);
        
        btnNewButton_1 = new JButton("\u4E0B\u4E00\u4E2A");
        panel_1.add(btnNewButton_1);
        btnNewButton_1.setIcon(new ImageIcon(main_window.class.getResource("/png_16x16/arrow_right.png")));
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int addr = Integer.parseInt(tf_target_addr.getText());
                if(++addr > 255) {
                    addr = 0;
                }
                tf_target_addr.setText(String.valueOf(addr));
            }
        });
        
        JPanel panel_2 = new JPanel();
        comm_title = "²Ù×÷";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Operation";
        }
        panel_2.setBorder(new TitledBorder(null, comm_title, TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel.add(panel_2);
        
        comm_title = "Á¬½Ó";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Connect";
        }
        btn_connet = new JButton(comm_title);
        btn_connet.setIcon(new ImageIcon(main_window.class.getResource("/png_16x16/connect.png")));
        btn_connet.setFont(new Font("ËÎÌå", Font.PLAIN, 24));
        btn_connet.setEnabled(true);
        btn_connet.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int comm_type = tab_comm_type.getSelectedIndex();
                
                //System.out.println(comm_type);
                String spname_or_ipaddr;
                int bitrate_or_ipport = Integer.parseInt((String)cb_comm_bitrate.getSelectedItem());
                
                if(SPCommMon.COMM_PORT_TYPE_Serial == comm_type) {
                    spname_or_ipaddr = cb_commport.getSelectedItem().toString();
                    if(cb_commport.getSelectedIndex() < 0) {
                        Toolkit.getDefaultToolkit().beep();
                        JOptionPane.showMessageDialog(frmSerialport, "ÕÒ²»µ½Èκδ®¿Ú!");
                        return;
                    }
                } else {
                    spname_or_ipaddr = tf_ip_addr.getText().trim();
                    bitrate_or_ipport = Integer.parseInt(tf_ip_port.getText().trim());
                }
                
                int main_DevType = main_TabbedPane.getSelectedIndex();
                boolean comm_open_res = true;
                int monomer_devType = cb_dev_type.getSelectedIndex();
                if(main_window.CommDevType_MON == main_DevType) {
                    int comm_multy_type = CommSerialPort.mutycomm_Type_Samd09;
                    if(0 == monomer_devType) {
                        comm_multy_type = CommSerialPort.mutycomm_Type_Samd09;
                    } else if(1 == monomer_devType) {
                        comm_multy_type = CommSerialPort.mutycomm_Type_Msp430;
                    } else if(2 == monomer_devType) {
                        comm_multy_type = CommSerialPort.mutycomm_Type_Samd09;
                    } else if(3 == monomer_devType) {
                        comm_multy_type = CommSerialPort.mutycomm_Type_SWM;
                    }
                    
                    comm_open_res = panel_mon_base.openCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport, 
                                                                monomer_devType, comm_multy_type, tf_target_addr, m_Log);
                } else if(main_window.CommDevType_CURR == main_DevType) {
                    comm_open_res = panel_Curr_Module.openCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport, 
                                                monomer_devType, CommSerialPort.mutycomm_Type_Samd09, tf_target_addr, m_Log);
                } else if(main_window.CommDevType_GROUPVOL == main_DevType) {
                    comm_open_res = panel_groupVol_Module.openCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport, 
                                                monomer_devType, CommSerialPort.mutycomm_Type_Samd09, tf_target_addr, m_Log);
                } else if(main_window.CommDevType_FCF651VOL == main_DevType) {
                    comm_open_res = panel_fcf651Vol_Module.openCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport, 
                                                monomer_devType, CommSerialPort.mutycomm_Type_Samd09, tf_target_addr);
                } else if(main_window.CommDevType_ZDHJ == main_DevType) {
                    int dev_addr = Integer.parseInt(tf_target_addr.getText().trim());
                    comm_open_res = panel_ZDHJ_base.openCommPort(comm_type, spname_or_ipaddr,
                                                                bitrate_or_ipport, dev_addr, m_Log);
                } else if(main_window.CommDevType_FBS9100 == main_DevType) {
                    int dev_addr = Integer.parseInt(tf_target_addr.getText().trim());
                    comm_open_res = panel_FBS9100_base.openCommPort(comm_type, spname_or_ipaddr, 
                                                                bitrate_or_ipport, dev_addr, m_Log);
                } else if(main_window.CommDevType_NTM == main_DevType) {
                    int dev_addr = Integer.parseInt(tf_target_addr.getText().trim());
                    comm_open_res = panel_NTM_base.openCommPort(comm_type, spname_or_ipaddr, 
                                                                bitrate_or_ipport, dev_addr, m_Log);
                } else if(main_window.CommDevType_LoraTest == main_DevType) {
                    comm_open_res = panel_LoraTest_base.openCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport, m_Log);
                } else if(main_window.CommDevType_BYBB == main_DevType) {
                    int dev_addr = Integer.parseInt(tf_target_addr.getText().trim());
                    comm_open_res = panel_bybb_base.openCommPort(comm_type, spname_or_ipaddr, 
                                                                bitrate_or_ipport, dev_addr, m_Log);
                } 
                
                if(true == comm_open_res) {
                    CommDevType = main_DevType;
                    
                    main_TabbedPane.setEnabled(false);
                    tf_target_addr.setEditable(false);
                    btn_renew_commport.setEnabled(false);
                    cb_commport.setEnabled(false);
                    btn_connet.setEnabled(false);
                    btn_break.setEnabled(true);
                    cb_comm_bitrate.setEnabled(false);
                    cb_dev_type.setEnabled(false);
                    
                    mMainFormTimer.start();
                } else {
                    Toolkit.getDefaultToolkit().beep();
                    JOptionPane.showMessageDialog(frmSerialport, spname_or_ipaddr + "²»´æÔÚ»ò±»ÆäËûÓ¦ÓóÌÐòÕ¼ÓÃ!");
                }
            }
        });
        panel_2.setLayout(new GridLayout(0, 2, 0, 0));
        panel_2.add(btn_connet);
        
        comm_title = "¶Ï¿ª";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Break";
        }
        btn_break = new JButton(comm_title);
        btn_break.setIcon(new ImageIcon(main_window.class.getResource("/png_16x16/disconnect.png")));
        btn_break.setFont(new Font("ËÎÌå", Font.PLAIN, 24));
        panel_2.add(btn_break);
        btn_break.setEnabled(false);
        btn_break.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                mMainFormTimer.stop();
                if(null != panel_mon_base) {
                    panel_mon_base.closeCommPort();
                }
                if(null != panel_Curr_Module) {
                    panel_Curr_Module.closeCommPort();
                }
                if(null != panel_groupVol_Module) {
                    panel_groupVol_Module.closeCommPort();
                }
                if(null != panel_fcf651Vol_Module) {
                    panel_fcf651Vol_Module.closeCommPort();
                }
                if(null != panel_ZDHJ_base) {
                    panel_ZDHJ_base.closeCommPort();
                }
                if(null != panel_FBS9100_base) {
                    panel_FBS9100_base.closeCommPort();
                    panel_FBS9100_base.setButttonState(false);
                }
                if(null != panel_NTM_base) {
                    panel_NTM_base.closeCommPort();
                }
                if(null != panel_LoraTest_base) {
                    panel_LoraTest_base.closeCommPort();
                }
                if(null != panel_bybb_base) {
                    panel_bybb_base.closeCommPort();
                }
                
                tf_target_addr.setEditable(true);
                btn_renew_commport.setEnabled(true);
                cb_commport.setEnabled(true);
                btn_connet.setEnabled(true);
                btn_break.setEnabled(false);
                cb_dev_type.setEnabled(true);
                cb_comm_bitrate.setEnabled(true);
                
                if((LANG_TYPE_EN == LANG_TYPE)/* || (1 == APP_ZDHJ_ONLY)*/) {
                    main_TabbedPane.setSelectedIndex(1);
                    main_TabbedPane.setEnabled(false);
                } else {
                    main_TabbedPane.setEnabled(true);
                }
            }
        });
        
        JPanel panel_9 = new JPanel();
        comm_title = "ͨÐżÆÊý(TX / RX)";
        if(LANG_TYPE_EN == LANG_TYPE) {
            comm_title = "Comm Count(TX / RX)";
        }
        panel_9.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u901A\u4FE1\u8BA1\u6570(TX/RX)", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel.add(panel_9);
        panel_9.setLayout(new GridLayout(0, 1, 0, 0));
        
        tf_txcnt = new JTextField();
        tf_txcnt.setFont(new Font("ËÎÌå", Font.PLAIN, 16));
        panel_9.add(tf_txcnt);
        tf_txcnt.setColumns(12);
        
        tf_rxcnt = new JTextField();
        tf_rxcnt.setFont(new Font("ËÎÌå", Font.PLAIN, 16));
        panel_9.add(tf_rxcnt);
        tf_rxcnt.setColumns(12);
        
        main_TabbedPane = new JTabbedPane(JTabbedPane.LEFT);
        main_TabbedPane.setFont(new Font("ËÎÌå", Font.PLAIN, 20));
        main_TabbedPane.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent arg0) {
                cb_dev_type.setSelectedIndex(0);
            }
        });
        frmSerialport.getContentPane().add(main_TabbedPane, BorderLayout.CENTER);
        
        //=======================================================================//
        if(APP_FBS9600_MON_EN) {
            panel_mon_base = new module_mon_page();
            String dt_title = "µ¥ÌåÄ£¿é";
            if(LANG_TYPE_EN == LANG_TYPE) {
                dt_title = "Mon Module";
            }
            main_TabbedPane.add(dt_title, panel_mon_base);
            main_TabbedPane.setIconAt(0, new ImageIcon(main_window.class.getResource("/png_16x16/application.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        //=======================================================================//
        if(APP_FBS9600_CURR_EN) {
            panel_Curr_Module = new module_curr_page();
            String Curr_Module_title = "µçÁ÷Ä£¿é";
            if(LANG_TYPE_EN == LANG_TYPE) {
                Curr_Module_title = "Curr Module";
            }
            main_TabbedPane.add(Curr_Module_title, panel_Curr_Module);
            main_TabbedPane.setIconAt(1, new ImageIcon(main_window.class.getResource("/png_16x16/application_link.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        //=======================================================================//
        if(APP_FBS9600_GVOL_EN) {
            panel_groupVol_Module = new module_vol_page();
            String vol_Module_title = "×éѹģ¿é";
            if(LANG_TYPE_EN == LANG_TYPE) {
                vol_Module_title = "GroupVol Module";
            }
            main_TabbedPane.add(vol_Module_title, panel_groupVol_Module);
            main_TabbedPane.setIconAt(2, new ImageIcon(main_window.class.getResource("/png_16x16/application_lightning.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        
        if(APP_FCF_GVOL_EN) {
            panel_fcf651Vol_Module = new FCF651_groupvol_page();
            String vol_Module_title = "FCF×éѹ";
            if(LANG_TYPE_EN == LANG_TYPE) {
                vol_Module_title = "FCF651 GroupVol";
            }
            main_TabbedPane.add(vol_Module_title, panel_fcf651Vol_Module);
            main_TabbedPane.setIconAt(3, new ImageIcon(main_window.class.getResource("/png_16x16/application_lightning.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        
        //======================================================================//
        if(APP_FBS9600_ZDHJ_EN) {
            panel_ZDHJ_base = new zdhj_page_base();
            String zdhj_title = "»ã¼¯Ä£¿é";
            if(LANG_TYPE_EN == LANG_TYPE) {
                zdhj_title = "Collect Module";
            }
            main_TabbedPane.add(zdhj_title, panel_ZDHJ_base);
            main_TabbedPane.setIconAt(4, new ImageIcon(main_window.class.getResource("/png_16x16/application_view_tile.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        //======================================================================//
        if(APP_BTSM_EN) {
            panel_FBS9100_base = new bts_page_base();
            String fbs9100_title = "BTSÖ÷¿Ø";
            if(LANG_TYPE_EN == LANG_TYPE) {
                fbs9100_title = "BTS Module";
            }
            main_TabbedPane.add(fbs9100_title, panel_FBS9100_base);
            main_TabbedPane.setIconAt(5, new ImageIcon(main_window.class.getResource("/png_16x16/application_home.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        //======================================================================//
        if(APP_NTM_EN) {
            String ntm_title = "NT·ÅµçÒÇ";
            if(LANG_TYPE_EN == LANG_TYPE) {
                ntm_title = "NT Tester";
            }
            panel_NTM_base = new ntm_page_base(m_Log);
            main_TabbedPane.add(ntm_title, panel_NTM_base);
            main_TabbedPane.setIconAt(6, new ImageIcon(main_window.class.getResource("/png_16x16/layer_treansparent.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        //======================================================================//
        if(APP_NTM_LORA_EN) {
            String loratest_title = "Lora²âÊÔ";
            if(LANG_TYPE_EN == LANG_TYPE) {
                loratest_title = "NT Tester";
            }
            panel_LoraTest_base = new loratester_page_base(m_Log);
            main_TabbedPane.add(loratest_title, panel_LoraTest_base);
            main_TabbedPane.setIconAt(7, new ImageIcon(main_window.class.getResource("/png_16x16/layer_treansparent.png")));
        } else {
            main_TabbedPane.add("", new JPanel());
        }
        //======================================================================//
        if(APP_BYBB_EN) {
            String bybb_title = "BYBB²âÊÔ";
            if(LANG_TYPE_EN == LANG_TYPE) {
                bybb_title = "bybb Tester";
            }
            panel_bybb_base = new bybb_page_base();
            main_TabbedPane.add(bybb_title, panel_bybb_base);
            main_TabbedPane.setIconAt(8, new ImageIcon(main_window.class.getResource("/png_16x16/layer_treansparent.png")));
            if(APP_BYBB_EN) {
                tf_ip_port.setText("6600");
                tab_comm_type.setSelectedIndex(1);
                //tab_comm_type.setEnabled(false);
                main_TabbedPane.setSelectedIndex(main_window.CommDevType_BYBB);
                main_TabbedPane.setEnabled(false);
            }
        } else {
            main_TabbedPane.add("back_up", new JPanel());
        }
        /**************************************************************************/
        if((LANG_TYPE_EN == LANG_TYPE)/* || (1 == APP_ZDHJ_ONLY)*/) {
            main_TabbedPane.setSelectedIndex(1);
            main_TabbedPane.setEnabled(false);
        }
        /**************************************************************************/
        
        //´ò°üģʽÅжÏÑ¡Ïî--Òþ²Ø×ó²àÑ¡¿¨¿¨
        if(CommDevType >= CommDevType_MON && CommDevType <= CommDevType_BYBB) {
            //Ñ¡ÖÐĬÈÏÑ¡Ï
            main_TabbedPane.setSelectedIndex(CommDevType);
            if(!isDebugMode) {                
                main_TabbedPane.setVisible(false);
                switch(CommDevType) {
                    case CommDevType_MON:{                     
                        frmSerialport.getContentPane().add(panel_mon_base, BorderLayout.CENTER);
                    }break;
                    case CommDevType_CURR:{
                        frmSerialport.getContentPane().add(panel_Curr_Module, BorderLayout.CENTER);
                    }break;
                    case CommDevType_GROUPVOL:{
                        frmSerialport.getContentPane().add(panel_groupVol_Module, BorderLayout.CENTER);
                    }break;
                    case CommDevType_FCF651VOL:{
                        frmSerialport.getContentPane().add(panel_fcf651Vol_Module, BorderLayout.CENTER);
                    }break;
                    case CommDevType_ZDHJ:{
                        //panel_3.setVisible(false);
                        tab_comm_type.remove(panel_3);
                        
                        frmSerialport.getContentPane().add(panel_ZDHJ_base, BorderLayout.CENTER);
                    }break;
                    case CommDevType_FBS9100:{
                        frmSerialport.getContentPane().add(panel_FBS9100_base, BorderLayout.CENTER);
                    }break;
                    case CommDevType_NTM:{
                        frmSerialport.getContentPane().add(panel_NTM_base, BorderLayout.CENTER);
                    }break;
                    case CommDevType_LoraTest:{
                        frmSerialport.getContentPane().add(panel_LoraTest_base, BorderLayout.CENTER);
                    }break;
                    case CommDevType_BYBB:{
                        frmSerialport.getContentPane().add(panel_bybb_base, BorderLayout.CENTER);
                    }break;
                }
            }
        }
        /**************************************************************************/
        mMainFormTimer = new Timer(200, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                updateData();
            }
        });
        /**************************************************************************/
    }
    
    public static void setCommData(ByteBuffer bf) {
        DataBuffer.position(0);
        DataBuffer.put(bf.array());
    }
    
    private void updateData() {
        try{
            frmSerialport.setTitle(this.mTitle + "     " + Com.get_DTF(new Date(), Com.DTF_YMDhms));
            
            if(CommDevType_MON == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_mon_base.Comm_Mon.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_mon_base.Comm_Mon.comm_rx_cnt));
                
                panel_mon_base.updateData();
            } else if(CommDevType_CURR == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_Curr_Module.Comm_Curr.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_Curr_Module.Comm_Curr.comm_rx_cnt));
                
                panel_Curr_Module.updateData();
            } else if(CommDevType_GROUPVOL == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_groupVol_Module.Comm_Vol.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_groupVol_Module.Comm_Vol.comm_rx_cnt));
                
                panel_groupVol_Module.updateData();
            } else if(CommDevType_FCF651VOL == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_fcf651Vol_Module.Comm_Vol.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_fcf651Vol_Module.Comm_Vol.comm_rx_cnt));
                
                panel_fcf651Vol_Module.updateData();
            } else if(CommDevType_ZDHJ == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_ZDHJ_base.Comm_ZDHJ.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_ZDHJ_base.Comm_ZDHJ.comm_rx_cnt));
                
                panel_ZDHJ_base.updateData();
            } else if(CommDevType_FBS9100 == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_FBS9100_base.Comm_BTS.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_FBS9100_base.Comm_BTS.comm_rx_cnt));
                
                panel_FBS9100_base.updateData();
            } if(CommDevType_NTM == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_NTM_base.Comm_NTM.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_NTM_base.Comm_NTM.comm_rx_cnt));
                
                panel_NTM_base.updateData();
            } if(CommDevType_LoraTest == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_LoraTest_base.Comm_LoraTester.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_LoraTest_base.Comm_LoraTester.comm_rx_cnt));
                
                panel_LoraTest_base.updateData();
            } if(CommDevType_BYBB == CommDevType) {
                tf_txcnt.setText(String.format("TX:%d", panel_bybb_base.Comm_BYBB.comm_tx_cnt));
                tf_rxcnt.setText(String.format("RX:%d", panel_bybb_base.Comm_BYBB.comm_rx_cnt));
                
                panel_bybb_base.updateData();
            } 
        } catch (Exception e) {
            m_Log.error(e.toString(), e);
        }
    }
}