main()
method
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 | 33 | * The {@code toString} method for class {@code Object} 34 | * returns a string consisting of the name of the class of which the 35 | * object is an instance, the at-sign character `{@code @}', and 36 | * the unsigned hexadecimal representation of the hash code of the 37 | * object. In other words, this method returns a string equal to the 38 | * value of: 39 | *
40 | *43 | * 44 | * @return a string representation of the object. 45 | */ 46 | @Override 47 | public String toString() { 48 | return Key; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/HslCommunicationDemo/PLC/Panasonic/FormPanasonicMcNet.java: -------------------------------------------------------------------------------- 1 | package HslCommunicationDemo.PLC.Panasonic; 2 | 3 | import HslCommunication.BasicFramework.SoftBasic; 4 | import HslCommunication.Core.Types.OperateResult; 5 | import HslCommunication.Core.Types.OperateResultExOne; 6 | import HslCommunication.Profinet.Panasonic.PanasonicMcNet; 7 | import HslCommunication.Profinet.Siemens.SiemensS7Net; 8 | import HslCommunicationDemo.Demo.AddressExampleControl; 9 | import HslCommunicationDemo.Demo.DeviceAddressExample; 10 | import HslCommunicationDemo.DemoUtils; 11 | import HslCommunicationDemo.UserControlReadWriteDevice; 12 | import HslCommunicationDemo.UserControlReadWriteHead; 13 | import HslCommunicationDemo.UserControlReadWriteOp; 14 | 15 | import javax.swing.*; 16 | import java.awt.*; 17 | import java.awt.event.MouseAdapter; 18 | import java.awt.event.MouseEvent; 19 | 20 | public class FormPanasonicMcNet extends JPanel { 21 | 22 | public FormPanasonicMcNet(JTabbedPane tabbedPane){ 23 | setLayout(null); 24 | add( new UserControlReadWriteHead("Qna-3E Binary", tabbedPane, this)); 25 | AddConnectSegment(this); 26 | plc = new PanasonicMcNet(); 27 | 28 | userControlReadWriteDevice = DemoUtils.CreateDevicePanel(this); 29 | userControlReadWriteDevice.setEnabled(false); 30 | 31 | addressExampleControl = new AddressExampleControl(PanasonicHelper.GetMCAddressExamples()); 32 | userControlReadWriteDevice.AddSpecialFunctionTab(addressExampleControl, false, DeviceAddressExample.GetTitle()); 33 | } 34 | 35 | private AddressExampleControl addressExampleControl; 36 | private PanasonicMcNet plc = null; 37 | private String defaultAddress = "D100"; 38 | private UserControlReadWriteDevice userControlReadWriteDevice = null; 39 | 40 | public void AddConnectSegment(JPanel panel){ 41 | JPanel panelConnect = DemoUtils.CreateConnectPanel(panel); 42 | 43 | JTextField textField1 = DemoUtils.CreateIpAddressTextBox(panelConnect); 44 | JTextField textField2 = DemoUtils.CreateIpPortTextBox(panelConnect, "6000"); 45 | 46 | JButton button2 = new JButton("Disconnect"); 47 | button2.setFocusPainted(false); 48 | button2.setBounds(584,11,121, 28); 49 | panelConnect.add(button2); 50 | 51 | JButton button1 = new JButton("Connect"); 52 | button1.setFocusPainted(false); 53 | button1.setBounds(477,11,91, 28); 54 | panelConnect.add(button1); 55 | 56 | button2.setEnabled(false); 57 | button1.setEnabled(true); 58 | button1.addMouseListener(new MouseAdapter() { 59 | @Override 60 | public void mouseClicked(MouseEvent e) { 61 | if (!button1.isEnabled())return; 62 | super.mouseClicked(e); 63 | try { 64 | plc.setIpAddress(textField1.getText()); 65 | plc.setPort(Integer.parseInt(textField2.getText())); 66 | 67 | OperateResult connect = plc.ConnectServer(); 68 | if(connect.IsSuccess){ 69 | JOptionPane.showMessageDialog( 70 | null, 71 | "Connect Success", 72 | "Result", 73 | JOptionPane.PLAIN_MESSAGE); 74 | button2.setEnabled(true); 75 | button1.setEnabled(false); 76 | userControlReadWriteDevice.SetReadWriteNet(plc, defaultAddress, 10); 77 | } 78 | else { 79 | JOptionPane.showMessageDialog( 80 | null, 81 | "Connect Failed:" + connect.ToMessageShowString(), 82 | "Result", 83 | JOptionPane.WARNING_MESSAGE); 84 | } 85 | } 86 | catch (Exception ex){ 87 | JOptionPane.showMessageDialog( 88 | null, 89 | "Connect Failed\r\nReason:"+ex.getMessage(), 90 | "Result", 91 | JOptionPane.ERROR_MESSAGE); 92 | } 93 | } 94 | }); 95 | button2.addMouseListener(new MouseAdapter() { 96 | @Override 97 | public void mouseClicked(MouseEvent e) { 98 | super.mouseClicked(e); 99 | if (button2.isEnabled() == false) return; 100 | if(plc !=null){ 101 | plc.ConnectClose(); 102 | button1.setEnabled(true); 103 | button2.setEnabled(false); 104 | userControlReadWriteDevice.setEnabled(false); 105 | } 106 | } 107 | }); 108 | 109 | 110 | panel.add(panelConnect); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/HslCommunicationDemo/PLC/Panasonic/PanasonicHelper.java: -------------------------------------------------------------------------------- 1 | package HslCommunicationDemo.PLC.Panasonic; 2 | 3 | import HslCommunicationDemo.Demo.DeviceAddressExample; 4 | 5 | public class PanasonicHelper { 6 | public static DeviceAddressExample[] GetMCAddressExamples( ) 7 | { 8 | return new DeviceAddressExample[] 9 | { 10 | new DeviceAddressExample( "X0", "外部输入继电器", true, false, "X33 等同于 X3.3" ), 11 | new DeviceAddressExample( "Y0", "外部输出继电器", true, false, "Y33 等同于 Y3.3" ), 12 | new DeviceAddressExample( "R2.1", "内部继电器", true, false, "R21 等同于 R2.1" ), 13 | new DeviceAddressExample( "TN0", "定时器(当前值)", true, false, "读写字" ), 14 | new DeviceAddressExample( "TS0", "定时器(触点)", true, false, "读写bool" ), 15 | new DeviceAddressExample( "CN0", "计数器(当前值)", true, false, "读写字" ), 16 | new DeviceAddressExample( "CS0", "计数器(触点)", true, false, "读写bool" ), 17 | new DeviceAddressExample( "L2.1", "链接继电器", true, false, "L21 等同于 L2.1" ), 18 | new DeviceAddressExample( "D0", "数据寄存器 DT", false, true, "" ), 19 | new DeviceAddressExample( "LD0", "链接寄存器 LD", false, true, "" ), 20 | new DeviceAddressExample( "SD0", "特殊数据寄存器", false, true, "" ), 21 | }; 22 | } 23 | 24 | public static DeviceAddressExample[] GetMewtocolAddressExamples( ) 25 | { 26 | return new DeviceAddressExample[] 27 | { 28 | new DeviceAddressExample( "X0", "外部输入继电器", true, false, "X33 等同于 X3.3" ), 29 | new DeviceAddressExample( "Y0", "外部输出继电器", true, false, "Y33 等同于 Y3.3" ), 30 | new DeviceAddressExample( "R2.1", "内部继电器", true, false, "R21 等同于 R2.1" ), 31 | new DeviceAddressExample( "SR2.1", "特殊内部继电器", true, false, "SR21 等同于 SR2.1" ), 32 | new DeviceAddressExample( "T0", "定时器", true, false, "" ), 33 | new DeviceAddressExample( "C0", "计数器", true, false, "" ), 34 | new DeviceAddressExample( "L2.1", "链接继电器", true, false, "L21 等同于 L2.1" ), 35 | new DeviceAddressExample( "D0", "数据寄存器 DT", false, true, "" ), 36 | new DeviceAddressExample( "LD0", "链接寄存器 LD", false, true, "" ), 37 | new DeviceAddressExample( "F0", "文件寄存器 FL", false, true, "" ), 38 | new DeviceAddressExample( "S0", "目标值 SV", false, true, "" ), 39 | new DeviceAddressExample( "K0", "经过值 EV", false, true, "" ), 40 | new DeviceAddressExample( "IX", "索引寄存器 IX", false, true, "" ), 41 | new DeviceAddressExample( "IY", "索引寄存器 IY", false, true, "" ), 42 | new DeviceAddressExample( "s=2;R2.1", "内部继电器", true, false, "支持额外指定其他的站号信息" ), 43 | }; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/HslCommunicationDemo/PLC/Siemens/SiemensHelper.java: -------------------------------------------------------------------------------- 1 | package HslCommunicationDemo.PLC.Siemens; 2 | 3 | import HslCommunicationDemo.Demo.DeviceAddressExample; 4 | 5 | public class SiemensHelper { 6 | 7 | public static DeviceAddressExample[] GetSiemensS7Address( ) 8 | { 9 | return new DeviceAddressExample[] 10 | { 11 | new DeviceAddressExample( "I0", "输入寄存器", true, true, "位地址示例:I1.6" ), 12 | new DeviceAddressExample( "Q0", "输出寄存器", true, true, "位地址示例:Q1.6" ), 13 | new DeviceAddressExample( "M0", "内部寄存器", true, true, "位地址示例:M1.6 , 也可以输入 MW100,MD100" ), 14 | new DeviceAddressExample( "DB1.0", "数据寄存器", true, true, "位地址示例:DB1.0.1, 也可以输入 DB1.DBD100" ), 15 | new DeviceAddressExample( "V0", "数据寄存器", true, true, "等同于DB1.0" ), 16 | 17 | new DeviceAddressExample( "SM0", "系统寄存器", true, true, "System flags of 200 family, 位地址示例:SM1.6" ), 18 | new DeviceAddressExample( "P0", "外设寄存器", true, true, "Direct peripheral access, 也可以输入:PIW0, PQW0" ), 19 | 20 | new DeviceAddressExample( "T0", "定时器寄存器", true, true, "smart200测试通过" ), 21 | new DeviceAddressExample( "C0", "计数器寄存器", true, true, "smart200测试通过" ), 22 | new DeviceAddressExample( "AI0", "智能输入寄存器", false, true, "仅支持字单位" ), 23 | new DeviceAddressExample( "AQ0", "智能输出寄存器", false, true, "仅支持字单位" ), 24 | }; 25 | } 26 | 27 | public static DeviceAddressExample[] GetSiemensPPIAddress( ) 28 | { 29 | return new DeviceAddressExample[] 30 | { 31 | new DeviceAddressExample( "I0", "输入寄存器", true, true, "位地址示例:I1.6" ), 32 | new DeviceAddressExample( "Q0", "输出寄存器", true, true, "位地址示例:Q1.6" ), 33 | new DeviceAddressExample( "M0", "内部寄存器", true, true, "位地址示例:M1.6" ), 34 | new DeviceAddressExample( "DB1.0", "数据寄存器", true, true, "位地址示例:DB1.0.1" ), 35 | new DeviceAddressExample( "V0", "数据寄存器", true, true, "等同于DB1.0" ), 36 | 37 | new DeviceAddressExample( "T0", "定时器寄存器", true, true, "smart200测试通过" ), 38 | new DeviceAddressExample( "C0", "计数器寄存器", true, true, "smart200测试通过" ), 39 | new DeviceAddressExample( "AI0", "智能输入寄存器", false, true, "仅支持字单位" ), 40 | new DeviceAddressExample( "AQ0", "智能输出寄存器", false, true, "仅支持字单位" ), 41 | new DeviceAddressExample( "SYS0", "系统内部地址", true, true, "位地址示例:SYS1.6" ), 42 | new DeviceAddressExample( "S0", "内部寄存器", true, true, "位地址示例:S1.6" ), 43 | new DeviceAddressExample( "SM0", "特殊内部寄存器", true, true, "位地址示例:SM1.6" ), 44 | new DeviceAddressExample( "s=1;M0", "内部寄存器", true, true, "支持额外指定站号信息" ), 45 | }; 46 | } 47 | 48 | public static DeviceAddressExample[] GetSiemensFWAddress( ) 49 | { 50 | return new DeviceAddressExample[] 51 | { 52 | new DeviceAddressExample( "I0", "输入寄存器", true, true, "仅支持字单位" ), 53 | new DeviceAddressExample( "Q0", "输出寄存器", true, true, "仅支持字单位" ), 54 | new DeviceAddressExample( "M0", "内部寄存器", true, true, "仅支持字单位" ), 55 | new DeviceAddressExample( "DB1.0", "数据寄存器", true, true, "仅支持字单位" ), 56 | 57 | new DeviceAddressExample( "T0", "定时器寄存器", true, true, "仅支持字单位" ), 58 | new DeviceAddressExample( "C0", "计数器寄存器", true, true, "仅支持字单位" ), 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/HslCommunicationDemo/PLC/Toyota/ToyoPucHelper.java: -------------------------------------------------------------------------------- 1 | package HslCommunicationDemo.PLC.Toyota; 2 | 3 | import HslCommunicationDemo.Demo.DeviceAddressExample; 4 | 5 | public class ToyoPucHelper { 6 | public static DeviceAddressExample[] GetToyotaAddress( ) 7 | { 8 | return new DeviceAddressExample[] 9 | { 10 | new DeviceAddressExample( "K0", "保持继电器", true, true, "地址使用16进制,范围 K0 ~ K2FF" ), 11 | new DeviceAddressExample( "V0", "特殊继电器", true, true, "地址使用16进制,范围 V0 ~ VFF" ), 12 | new DeviceAddressExample( "T0", "定时器", true, true, "地址使用16进制,范围 T0 ~ T1FF" ), 13 | new DeviceAddressExample( "C0", "计数器", true, true, "地址使用16进制,范围 C0 ~ C1FF" ), 14 | new DeviceAddressExample( "L0", "链接继电器", true, true, "地址使用16进制,范围 L0 ~ L7FF" ), 15 | new DeviceAddressExample( "X0", "输入继电器", true, true, "地址使用16进制,范围 X0 ~ X7FF" ), 16 | new DeviceAddressExample( "Y0", "输出继电器", true, true, "地址使用16进制,范围 Y0 ~ Y7FF" ), 17 | new DeviceAddressExample( "M0", "内部继电器", true, true, "地址使用16进制,范围 M0 ~ M7FF" ), 18 | new DeviceAddressExample( "S0", "特殊寄存器", false, true, "地址使用16进制,范围 S0 ~ S3FF" ), 19 | new DeviceAddressExample( "N0", "定时器计数器当前值", false, true, "地址使用16进制,范围 N0 ~ N1FF" ), 20 | new DeviceAddressExample( "R0", "链接寄存器", false, true, "地址使用16进制,范围 R0 ~ R7FF" ), 21 | new DeviceAddressExample( "D0", "数据寄存器", false, true, "地址使用16进制,范围 D0 ~ D2FFF" ), 22 | new DeviceAddressExample( "B0", "文件寄存器", false, true, "地址使用16进制,范围 B0 ~ B1FFF" ), 23 | new DeviceAddressExample( "EK0", "扩展保持继电器", true, true, "地址使用16进制,范围 EK0 ~ EKFFF" ), 24 | new DeviceAddressExample( "EV0", "扩展特殊继电器", true, true, "地址使用16进制,范围 EV0 ~ EVFFF" ), 25 | new DeviceAddressExample( "ET0", "扩展定时器", true, true, "地址使用16进制,范围 ET0 ~ ET7FF" ), 26 | new DeviceAddressExample( "EC0", "扩展计数器", true, true, "地址使用16进制,范围 EC0 ~ EC7FF" ), 27 | new DeviceAddressExample( "EL0", "扩展链接继电器", true, true, "地址使用16进制,范围 EL0 ~ EL1FFF" ), 28 | new DeviceAddressExample( "EX0", "扩展输入继电器", true, true, "地址使用16进制,范围 EX0 ~ EX7FF" ), 29 | new DeviceAddressExample( "EY0", "扩展输出继电器", true, true, "地址使用16进制,范围 EY0 ~ EY7FF" ), 30 | new DeviceAddressExample( "EM0", "扩展内部继电器", true, true, "地址使用16进制,范围 EM0 ~ EM1FFF" ), 31 | new DeviceAddressExample( "ES0", "扩展特殊寄存器", false, true, "地址使用16进制,范围 ES0 ~ ES7FF" ), 32 | new DeviceAddressExample( "ENO", "扩展当前值寄存器", false, true, "地址使用16进制,范围 EN0 ~ EN7FF" ), 33 | new DeviceAddressExample( "H0", "扩展设置定寄存器", false, true, "地址使用16进制,范围 H0 ~ H7FF" ), 34 | new DeviceAddressExample( "U0", "扩展数据寄存器", false, true, "地址使用16进制,范围 U0 ~ U7FFF" ), 35 | new DeviceAddressExample( "GX0", "扩展输入继电器", false, true, "地址使用16进制,范围 GX0 ~ GXFFFF" ), 36 | new DeviceAddressExample( "GY0", "扩展输出继电器", false, true, "地址使用16进制,范围 GY0 ~ GYFFFF" ), 37 | new DeviceAddressExample( "GM0", "扩展内部继电器", false, true, "地址使用16进制,范围 GM0 ~ GMFFFF" ), 38 | new DeviceAddressExample( "EB0", "扩展文件寄存器", false, true, "范围 EB0 ~ EB7FFF, EB8000 ~ EBFFFF, EB10000 ~ EB17FFF, EM18000 ~ EB1FFFF" ), 39 | new DeviceAddressExample( "prg=1;D0", "指定程序号的数据寄存器", false, true, "上述所有非扩展地址均支持另外指定程序号参数" ), 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/HslCommunicationDemo/PLC/WeCon/FormWeConModbusRtuOverTcp.java: -------------------------------------------------------------------------------- 1 | package HslCommunicationDemo.PLC.WeCon; 2 | 3 | import HslCommunication.Core.Types.FunctionOperateExTwo; 4 | import HslCommunication.Core.Types.OperateResultExOne; 5 | import HslCommunication.ModBus.ModbusMappingAddress; 6 | import HslCommunicationDemo.Demo.DeviceAddressExample; 7 | import HslCommunicationDemo.PLC.Modbus.FormModbusRtuOverTcp; 8 | 9 | import javax.swing.*; 10 | 11 | public class FormWeConModbusRtuOverTcp extends FormModbusRtuOverTcp { 12 | public FormWeConModbusRtuOverTcp(JTabbedPane tabbedPane) { 13 | super(tabbedPane); 14 | 15 | // 注册了维控PLC的地址映射关系 16 | addressMapping = new FunctionOperateExTwo41 | * getClass().getName() + '@' + Integer.toHexString(hashCode()) 42 | *
Note: Disabling a component does not disable its children. 58 | * 59 | *
Note: Disabling a lightweight component does not prevent it from 60 | * receiving MouseEvents. 61 | * 62 | * @param enabled true if this component should be enabled, false otherwise 63 | * @beaninfo preferred: true 64 | * bound: true 65 | * attribute: visualUpdate true 66 | * description: The enabled state of the component. 67 | * @see Component#isEnabled 68 | * @see Component#isLightweight 69 | */ 70 | @Override 71 | public void setEnabled(boolean enabled) { 72 | super.setEnabled(enabled); 73 | userControlReadWriteOp.setEnabled(enabled); 74 | tabbedPane.setEnabled(enabled); 75 | batchReadControl.setEnabled(enabled); 76 | logControl.setEnabled(enabled); 77 | 78 | DemoUtils.SetPanelEnabled(userControlReadWriteOp, enabled); 79 | DemoUtils.SetPanelEnabled(batchReadControl, enabled); 80 | 81 | } 82 | 83 | /** 84 | * 设置当前的读写通信类对象 85 | * @param readWrite 通信对象 86 | * @param address 默认地址 87 | * @param strLength 长度信息 88 | */ 89 | public void SetReadWriteNet(IReadWriteNet readWrite, String address, int strLength ) { 90 | this.userControlReadWriteOp.SetReadWriteNet(readWrite, address, strLength); 91 | this.batchReadControl.SetReadWriteNet(readWrite, address, strLength); 92 | setEnabled(true); 93 | } 94 | 95 | /** 96 | * 新增一个自定义的控件信息 97 | * @param control 自定义的控件实现 98 | * @param show 是否显示出来 99 | * @param title 标题名称 100 | */ 101 | public void AddSpecialFunctionTab( JPanel control, boolean show, String title ) 102 | { 103 | this.tabbedPane.add(title, control); 104 | if (show) this.tabbedPane.setSelectedComponent(control); 105 | } 106 | 107 | /** 108 | * 获取日志控件 109 | * @return 控件对象 110 | */ 111 | public ServerLogControl getLogControl(){ 112 | return this.logControl; 113 | } 114 | 115 | private ServerLogControl logControl; 116 | private BatchReadControl batchReadControl; 117 | private UserControlReadWriteOp userControlReadWriteOp; 118 | private JTabbedPane tabbedPane; 119 | 120 | } 121 | --------------------------------------------------------------------------------