wu
2025-04-07 62e4c1883dfd13289970f8f20f0a56d86aff23ff
Merge branch 'master' of http://159.223.171.199:10439/r/Haier_MES_II

# Conflicts:
# gmms/WebContent/login/run.jsp
8个文件已修改
10个文件已添加
1699 ■■■■■ 已修改文件
.idea/workspace.xml 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gmms.sql 补丁 | 查看 | 原始文档 | blame | 历史
nglib/.idea/encodings.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/.idea/uiDesigner.xml 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/nglib.iml 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/builder/HttpHandlerDemo.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/builder/MachineManager.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/builder/Manager.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/builder/S7control.java 487 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/builder/S7objectMachine.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/builder/ThreadHttpServer.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/InitUtil.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/ModbusService.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/MysqlService.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/PlcBitInfo.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/PlcBitObject.java 127 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/PlcParameterInfo.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
nglib/src/ng/devices/PlcParameterObject.java 252 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/workspace.xml
New file
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="AutoImportSettings">
    <option name="autoReloadType" value="SELECTIVE" />
  </component>
  <component name="ChangeListManager">
    <list default="true" id="8fb06979-163e-47f4-9dfa-cdbddc7489f0" name="更改" comment="" />
    <option name="SHOW_DIALOG" value="false" />
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
    <option name="LAST_RESOLUTION" value="IGNORE" />
  </component>
  <component name="Git.Settings">
    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
  </component>
  <component name="ProjectColorInfo">{
  &quot;associatedIndex&quot;: 2
}</component>
  <component name="ProjectId" id="2uHpKN6b8NaF21shwcxgtYDcJ0z" />
  <component name="ProjectViewState">
    <option name="hideEmptyMiddlePackages" value="true" />
    <option name="showLibraryContents" value="true" />
  </component>
  <component name="PropertiesComponent">{
  &quot;keyToString&quot;: {
    &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
    &quot;git-widget-placeholder&quot;: &quot;master&quot;,
    &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
    &quot;last_opened_file_path&quot;: &quot;D:/workfile/Haier_MES_II&quot;,
    &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
    &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
    &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
    &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
    &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
    &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
  }
}</component>
  <component name="SharedIndexes">
    <attachedChunks>
      <set>
        <option value="bundled-jdk-9f38398b9061-18abd8497189-intellij.indexing.shared.core-IU-241.14494.240" />
        <option value="bundled-js-predefined-1d06a55b98c1-74d2a5396914-JavaScript-IU-241.14494.240" />
      </set>
    </attachedChunks>
  </component>
  <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
  <component name="TaskManager">
    <task active="true" id="Default" summary="默认任务">
      <changelist id="8fb06979-163e-47f4-9dfa-cdbddc7489f0" name="更改" comment="" />
      <created>1741915288398</created>
      <option name="number" value="Default" />
      <option name="presentableId" value="Default" />
      <updated>1741915288398</updated>
      <workItem from="1741915289710" duration="1265000" />
      <workItem from="1742172726815" duration="696000" />
    </task>
    <servers />
  </component>
  <component name="TypeScriptGeneratedFilesManager">
    <option name="version" value="3" />
  </component>
  <component name="Vcs.Log.Tabs.Properties">
    <option name="TAB_STATES">
      <map>
        <entry key="MAIN">
          <value>
            <State />
          </value>
        </entry>
      </map>
    </option>
  </component>
  <component name="VcsManagerConfiguration">
    <MESSAGE value="分批提交" />
    <option name="LAST_COMMIT_MESSAGE" value="" />
  </component>
</project>
gmms.sql
Binary files differ
nglib/.idea/encodings.xml
@@ -1,11 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Encoding">
    <file url="file://$PROJECT_DIR$/bin/S7/S7control.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/builder/HttpHandlerDemo.java" charset="GBK" />
    <file url="file://$PROJECT_DIR$/src/builder/MachineManager.java" charset="GBK" />
    <file url="file://$PROJECT_DIR$/src/builder/Manager.java" charset="GBK" />
    <file url="file://$PROJECT_DIR$/src/builder/S7control.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/builder/S7objectMachine.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/builder/ThreadHttpServer.java" charset="GBK" />
    <file url="file://$PROJECT_DIR$/src/ng/db/DBSession.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/ng/devices/InitUtil.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/ng/devices/PlcBitInfo.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/ng/devices/PlcBitObject.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/ng/devices/PlcParameterInfo.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/ng/devices/PlcParameterObject.java" charset="UTF-8" />
    <file url="file://$PROJECT_DIR$/src/toTcp/TCPClient.java" charset="GBK" />
    <file url="PROJECT" charset="GBK" />
  </component>
nglib/.idea/uiDesigner.xml
New file
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Palette2">
    <group name="Swing">
      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
      </item>
      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
        <initial-values>
          <property name="text" value="Button" />
        </initial-values>
      </item>
      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="RadioButton" />
        </initial-values>
      </item>
      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="CheckBox" />
        </initial-values>
      </item>
      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
        <initial-values>
          <property name="text" value="Label" />
        </initial-values>
      </item>
      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
          <preferred-size width="150" height="-1" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
          <preferred-size width="150" height="50" />
        </default-constraints>
      </item>
      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
          <preferred-size width="200" height="200" />
        </default-constraints>
      </item>
      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
      </item>
      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
      </item>
      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
          <preferred-size width="-1" height="20" />
        </default-constraints>
      </item>
      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
      </item>
      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
      </item>
    </group>
  </component>
</project>
nglib/nglib.iml
@@ -16,16 +16,16 @@
    </content>
    <orderEntry type="jdk" jdkName="JavaSE-1.8" jdkType="JavaSDK" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../json-20230618.jar!/" />
          <root url="jar://$MODULE_DIR$/../json.jar!/" />
        </CLASSES>
        <JAVADOC />
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../mysql-connector-java-8.0.20.jar!/" />
@@ -34,7 +34,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../jacob-1.18.jar!/" />
@@ -43,7 +43,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../fastjson-1.2.2.jar!/" />
@@ -52,7 +52,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://E:/HuaweiMoveData/Users/SNG-010/Desktop/海尔二期/iot-communication-1.4.2.jar!/" />
@@ -61,7 +61,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://E:/HuaweiMoveData/Users/SNG-010/Desktop/海尔二期/jul-to-slf4j-1.7.28.jar!/" />
@@ -70,7 +70,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://E:/HuaweiMoveData/Users/SNG-010/Desktop/海尔二期/logback-classic-1.2.3.jar!/" />
@@ -79,7 +79,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://E:/HuaweiMoveData/Users/SNG-010/Desktop/海尔二期/logback-core-1.2.3.jar!/" />
@@ -88,7 +88,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://E:/HuaweiMoveData/Users/SNG-010/Desktop/海尔二期/nglib.jar!/" />
@@ -97,7 +97,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://E:/HuaweiMoveData/Users/SNG-010/Desktop/海尔二期/slf4j-api-1.7.28.jar!/" />
@@ -106,7 +106,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../druid-1.1.12.jar!/" />
@@ -115,7 +115,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../commons-net-3.9.0.jar!/" />
@@ -124,7 +124,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../artemis-http-client-1.1.10.jar!/" />
@@ -133,7 +133,7 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
    <orderEntry type="module-library">
      <library>
        <CLASSES>
          <root url="jar://$MODULE_DIR$/../iot-communication-1.4.2.jar!/" />
@@ -142,5 +142,18 @@
        <SOURCES />
      </library>
    </orderEntry>
    <orderEntry type="module-library" exported="">
      <library>
        <CLASSES>
          <root url="file://$MODULE_DIR$/lib" />
        </CLASSES>
        <JAVADOC />
        <SOURCES>
          <root url="file://$MODULE_DIR$/lib" />
        </SOURCES>
        <jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" />
        <jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" type="SOURCES" />
      </library>
    </orderEntry>
  </component>
</module>
nglib/src/builder/HttpHandlerDemo.java
@@ -77,7 +77,6 @@
            String result=null;
            try{
                sn=DBHelper.getDBHelper("mes").createSession(false);
                Connection con= sn.getConnection();
                CallableStatement sql=con.prepareCall("{call Face_recognition(?,?,?,?)}");
nglib/src/builder/MachineManager.java
@@ -29,12 +29,16 @@
        public String ProcName;
        public String Name;
        public byte FunctionType;
        public String remarks;
    
    }
    List<item> items=new ArrayList<item>();
    
    public void RunAll(){
       for(item it:items){
           System.out.println(it);
           Run(it.Name);
         
       }
@@ -49,7 +53,8 @@
        if(itm!=null){
            if(itm.serv==null){
                itm.serv=new MysqlService(itm.helper,itm.ID);
                itm.serv.Run(itm.ID,itm.IP,itm.Port, (byte)1,itm.ReadOffset, itm.ReadSize,1000,itm.FunctionType);
                itm.serv.Run(itm.ID,itm.IP,itm.Port, (byte)1,itm.ReadOffset, itm.ReadSize,1000,itm.FunctionType,itm.remarks);
                System.out.println(String.format("设备启动-{%s}(%s)(%s)",itm.Name,itm.IP,itm.FunctionType));
            }
        }
@@ -75,7 +80,7 @@
    
    
    
    public void createDevice(DBHelper helper,int DeviceID,String Name,String Ip,int Port,int ReadOffset,int ReadSize,String ProcName,byte FunctionType){
    public void createDevice(DBHelper helper,int DeviceID,String Name,String Ip,int Port,int ReadOffset,int ReadSize,String ProcName,byte FunctionType,String remarks){
        synchronized(items){
            
            item itm=new item();
@@ -88,6 +93,7 @@
            itm.ReadOffset=ReadOffset;        //读取偏移
            itm.ReadSize=ReadSize;//发送偏移
            itm.FunctionType=FunctionType;
            itm.remarks=remarks;
            /*if(DeviceID==6 || DeviceID==19 || DeviceID==29 || DeviceID==30){
                itm.ReadOffset=12000;
            }*/
nglib/src/builder/Manager.java
@@ -1,6 +1,5 @@
package builder;
import S7.S7control;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import ng.db.DBHelper;
import ng.db.DBSession;
@@ -12,7 +11,8 @@
import java.net.Socket;
import java.sql.ResultSet;
public class Manager {
public class Manager extends Thread {
    //设备管理器
    static MachineManager mmgr;
    //优化排版管理器
@@ -82,35 +82,31 @@
            //读取设备列表
            DBHelper db=DBHelper.getDBHelper("mes");
            sn=DBHelper.getDBHelper("mes").createSession(false);
            sn.createSql("select id,machine_name,ip_address,port,flag,read_size,read_offset,function_type,flag from machine where id=78");
            sn.createSql("select id,machine_name,ip_address,port,flag,read_size,read_offset,function_type,remarks from machine where flag=1");
            ResultSet set= sn.query().getCurrentResult();
            System.out.println("S7链接");
            S7control s7=new S7control(EPlcType.S1500, "192.168.30.14", 102, 0, 0);
            System.out.println("S7:"+s7.readByte("DB34.0",  2));
//            //创建所有设备通讯
//            while(set.next()){
//               int id=(int)set.getLong(1);
//               String name=set.getString(2);
//               String ip=set.getString(3);
//               int port=set.getInt(4);
//               int flag=set.getInt(5);
//               int readSize=set.getInt(6);
//               int readOffset=set.getInt(7);
//               byte functionType=set.getByte(8);
//               int flags=set.getInt(9);
//               if(flags==1){
//                   mmgr.createDevice(db,id,name,ip,port,readOffset,readSize,null,functionType);
//               }
//
//            }
            //创建所有设备通讯
            while(set.next()){
               int id=(int)set.getLong(1);
               String name=set.getString(2);
               String ip=set.getString(3);
               int port=set.getInt(4);
               int flag=set.getInt(5);
               int readSize=set.getInt(6);
               int readOffset=set.getInt(7);
               byte functionType=set.getByte(8);
               String remarks=set.getString(9);
               if(flag==1){
                   mmgr.createDevice(db,id,name,ip,port,readOffset,readSize,null,functionType,remarks);
               }
            }
        }
        catch(Exception e){
            
        }
        finally{
            if(sn!=null){
                sn.close();
            }
        }
@@ -211,9 +207,9 @@
            System.out.println("错误");
        }
    }
    public static void main(String[] args){
        //Manager.appStart(new String[]{"jdbc:mysql://10.153.19.150/gmms?serverTimezone=GMT%2B8","root","beibo.123/" });
        Manager.appStart(new String[]{"jdbc:mysql://localhost/gmms?serverTimezone=GMT%2B8","root","beibo.123/" });
        while(true){
            try {
                Thread.sleep(100);
nglib/src/builder/S7control.java
New file
@@ -0,0 +1,487 @@
package builder;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.github.xingshuangs.iot.protocol.s7.service.MultiAddressWrite;
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
import java.util.ArrayList;
import java.util.List;
public class S7control {
    S7PLC s7PLC; // PLC通讯类实例
    public S7control(EPlcType plcType, String ip, int port, int rack, int slot) {
        if (s7PLC == null) {
            s7PLC = new S7PLC(plcType, ip, port, 0, 0);
        }
    }
    /**
     * 关闭西门子s7通讯连接
     */
    public void closeS7client() {
        if (s7PLC != null) {
            s7PLC.close();
        }
    }
    /**
     * 重启西门子s7通讯连接
     */
    public boolean reStartS7client() {
        if (s7PLC != null) {
            try {
                s7PLC.hotRestart();
                return true;
            } catch (Exception ex) {
                return false;
            }
        }
        return false;
    }
    /**
     * s7通讯连接状态
     */
    public boolean checkConnected() {
        return s7PLC.checkConnected();
    }
    /**
     * 按指定的地址 写入一个word
     *
     * @param address 地址
     * @param data    word的值
     */
    public boolean writeWord(String address, int data) {
        if (s7PLC == null) {
            return false;
        }
        boolean result = false;
        int tryCount = 2;
        do {
            try {
                s7PLC.writeUInt16(address, data);
                result = true;
            } catch (Exception ex) {
                System.out.println("向plc写命令过程中发生异常,原因为:" + ex.getMessage());
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 从某地址连续 写入多个word
     *
     * @param address 地址
     * @param datas   word的值
     */
    public boolean writeWord(String address, List<Integer> datas) {
        if (s7PLC == null) {
            return false;
        }
        boolean result = false;
        int tryCount = 2;
        // s7PLC.write(address, data);
        List<String> addresslist = getAddressList(address, datas.size(), 16);
        MultiAddressWrite addressWrite = new MultiAddressWrite();
        for (int i = 0; i < datas.size(); i++) {
            addressWrite.addUInt16(addresslist.get(i), datas.get(i));
        }
        do {
            try {
                s7PLC.writeMultiData(addressWrite);
                result = true;
            } catch (Exception ex) {
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 按指定的地址 写入多个word
     *
     * @param address 地址
     * @param datas   word的值
     */
    /**
     * 按指定的地址 写入一个Bit
     *
     * @param address 地址
     * @param data    Bit的值
     */
    public boolean writeBit(String address, Boolean data) {
        if (s7PLC == null) {
            return false;
        }
        boolean result = false;
        int tryCount = 2;
        do {
            try {
                s7PLC.writeBoolean(address, data);
                result = true;
            } catch (Exception ex) {
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 按指定的地址 写入多个bit
     *
     * @param address 地址
     * @param datas   bit的值
     */
    public boolean writeBit(List<String> address, List<Boolean> datas) {
        if (s7PLC == null) {
            return false;
        }
        MultiAddressWrite addressWrite = new MultiAddressWrite();
        for (int i = 0; i < address.size(); i++) {
            addressWrite.addBoolean(address.get(i), datas.get(i));
        }
        boolean result = false;
        int tryCount = 2;
        do {
            try {
                s7PLC.writeMultiData(addressWrite);
                result = true;
            } catch (Exception ex) {
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 从某地址连续 写入多个bit
     *
     * @param address 地址
     * @param datas   word的值
     */
    public boolean writeBit(String address, List<Boolean> datas) {
        if (s7PLC == null) {
            return false;
        }
        // s7PLC.write(address, data);
        List<String> addresslist = getAddressList(address, datas.size(), 1);
        MultiAddressWrite addressWrite = new MultiAddressWrite();
        for (int i = 0; i < datas.size(); i++) {
            addressWrite.addBoolean(addresslist.get(i), datas.get(i));
        }
        boolean result = false;
        int tryCount = 2;
        do {
            try {
                s7PLC.writeMultiData(addressWrite);
                result = true;
            } catch (Exception ex) {
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 按指定的地址 写入多个byte
     *
     * @param address 地址
     * @param datas   byte的值
     */
    public boolean writeByte(String address, byte[] datas) {
        if (s7PLC == null) {
            return false;
        }
        boolean result = false;
        int tryCount = 2;
        do {
            try {
                s7PLC.writeByte(address, datas);
                result = true;
            } catch (Exception ex) {
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 按指定的地址 读取word结果集
     *
     * @param address 地址
     * @return 结果
     */
    public List<Integer> readWord(List<String> address) {
        if (s7PLC == null) {
            return null;
        }
        List<Integer> result = null;
        try {
            result = s7PLC.readUInt16(address);
        } catch (Exception e) {
            s7PLC.hotRestart();
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        } finally {
            return result;
        }
    }
    /**
     * 按指定的地址 读取word结果集
     *
     * @param address 地址
     * @param count   连续读多少个word
     * @return 结果
     */
    public List<Integer> readWord(String address, int count) {
        if (s7PLC == null) {
            return null;
        }
        List<Integer> result = null;
        List<String> addresslist = getAddressList(address, count, 16);
        try {
            result = s7PLC.readUInt16(addresslist);
        } catch (Exception e) {
            s7PLC.hotRestart();
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        } finally {
            return result;
        }
    }
    /**
     * 按指定的地址 读取byte结果集
     *
     * @param address 地址
     * @param count   连续读多少个byte
     * @return 结果
     */
    public byte[] readByte(String address, int count) {
        if (s7PLC == null) {
            return null;
        }
        // List<String> addresslist = GetAddressList(address, count, 16);
        byte[] bytes = null;
        try {
            bytes = s7PLC.readByte(address, count);
        } catch (Exception e) {
            // 处理异常
            s7PLC.hotRestart();
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        } finally {
            return bytes;
        }
    }
    /**
     * 按指定的地址 按bit位 0 flase 1 true 读取结果
     *
     * @param addresslist 地址集
     * @return Boolean结果
     */
    public List<Boolean> readBits(List<String> addresslist) {
        if (s7PLC == null) {
            return null;
        }
        List<Boolean> values = new ArrayList<>();
        try {
            values = s7PLC.readBoolean(addresslist);
        } catch (Exception e) {
            // 处理异常
            s7PLC.hotRestart();
        } finally {
            return values;
        }
    }
   /* //读取不连续地址bit
    public List<Boolean> readBits(List<String> addressList) {
        if (s7PLC == null || addressList.isEmpty()) {
            return null;
        }
        List<Boolean> values = new ArrayList<>();
        for (String address : addressList) {
            try {
                boolean value = s7PLC.readBoolean(address);
                values.add(value);
            } catch (Exception e) {
                // 处理异常
                System.out.println("读取 " + address + " 失败:" + e.getMessage());
            }
        }
        return values;
    }*/
    //读取字符串
    public String readString(String address) {
        if (s7PLC == null) {
            return null;
        }
        String result = null;
        try {
            result = s7PLC.readString(address);
        } catch (Exception e) {
            s7PLC.hotRestart();
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        } finally {
            return result;
        }
    }
    //读取时间
    public Long readtime(String address) {
        if (s7PLC == null) {
            return null;
        }
        Long result = null;
        try {
            result = s7PLC.readTime(address);
        } catch (Exception e) {
            s7PLC.hotRestart();
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        } finally {
            return result;
        }
    }
    public boolean writetime(String address, long datas) {
        if (s7PLC == null) {
            return false;
        }
        boolean result = false;
        int tryCount = 2;
        do {
            try {
                s7PLC.writeTime(address, datas); // 将数据写入单个地址
                result = true;
            } catch (Exception ex) {
                reStartS7client();
            } finally {
                tryCount -= 1;
            }
        }
        while (!result && tryCount > 0);
        return result;
    }
    /**
     * 从指定的地址开始 连续按bit位读取
     *
     * @param address 地址
     * @param count   长度
     * @return Boolean结果
     */
    public List<Boolean> readBits(String address, int count) {
        if (s7PLC == null) {
            return null;
        }
        List<Boolean> values = new ArrayList<>();
        List<String> addresslist = getAddressList(address, count, 1);
        try {
            values = s7PLC.readBoolean(addresslist);
        } catch (Exception e) {
            s7PLC.hotRestart();
            System.out.println("读取 " + address + " 失败:" + e.getMessage());
        } finally {
            return values;
        }
    }
    ;
    private List<String> getAddressList(String address, int count, int addedbit) {
        List<String> addresslist = new ArrayList<String>();
        String[] stringdatas = address.trim().split("\\.");
        if (stringdatas.length < 2 || !address.startsWith("DB")) {
            return null;
        }
        int dbwindex = 0;
        int bitindex = 0;
        if (stringdatas.length == 2) {
            dbwindex = Integer.parseInt(stringdatas[1]);
        } else if (stringdatas.length == 3) {
            dbwindex = Integer.parseInt(stringdatas[1]);
            bitindex = Integer.parseInt(stringdatas[2]);
        } else {
            return null;
        }
        addresslist.add(address);
        for (int i = 0; i < count - 1; i++) {
            int bitcurrent = bitindex + addedbit;
            if (bitcurrent > 7) {
                dbwindex += bitcurrent / 8;
                bitindex = 0;
            } else {
                bitindex = bitcurrent;
            }
            String endstr = stringdatas.length == 3 ? "." + bitindex : "";
            addresslist.add(stringdatas[0] + "." + dbwindex + endstr);
        }
        return addresslist;
    }
    public void writeString(String addr,String data) {
        s7PLC.writeString(addr,data);
    }
    public void writeUInt16(String addr,int data) {
        s7PLC.writeUInt16(addr,data);
    }
    public void writeUInt32(String addr,int data) {
        s7PLC.writeUInt32(addr,data);
    }
    public void writeStringy(String addr,String value) {
        byte[] bytes = value.getBytes();
        s7PLC.writeByte(addr,bytes);
    }
    public String readStrings(String addr) {
        return s7PLC.readString(addr);
    }
}
nglib/src/builder/S7objectMachine.java
New file
@@ -0,0 +1,79 @@
package builder;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import ng.devices.InitUtil;
import ng.devices.PlcParameterInfo;
import ng.devices.PlcParameterObject;
import java.util.LinkedHashMap;
/**
 * @Author : yanzhixin
 * @Date: 2024/4/9 15:13
 * @Description:
 */
public class S7objectMachine extends Thread {
    public S7control plccontrol; // PLC通讯类实例
    private EPlcType plcType = EPlcType.S1200; // 西门子PLC类型
    private String ip = ""; // plc ip地址
    private int port = 102; // plc 端口号
    private String plcFileName=""; // json名称
    public PlcParameterObject PlcMesObject;
    public S7objectMachine(String ip, int port, String plcFileName, EPlcType plcType) {
        initialize(ip,port,plcFileName,plcType);
        if (plccontrol == null) {
            plccontrol = new S7control(this.plcType, this.ip, this.port, 0, 0);
            //String plcFileUrl = System.getProperty("user.dir") + "D:/HangZhouMes/JsonFile/"+this.plcFileName+".json";
            String plcFileUrl = "D:/mes/JsonFile/"+this.plcFileName+".json";
            PlcMesObject = InitUtil.initword(plcFileUrl);
        }
    }
    public void initialize(String ip,int port,String plcFileName,EPlcType plcType){
        this.ip = ip;
        this.port = port;
        this.plcFileName = plcFileName;
        this.plcType=  plcType;
    }
    /**
     * 打印参数值
     */
    public void consoleLogInfo(){
        String logInfo=this.plcFileName+" ";
        LinkedHashMap<String, PlcParameterInfo> thisPlcParameterInfo=PlcMesObject.getPlcParameterMap();
        for (String key:thisPlcParameterInfo.keySet()) {
            logInfo+=key+":"+thisPlcParameterInfo.get(key).getValue()+",";
        }
    }
    @Override
    public void run() {
        while (this != null) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                byte[] resultValues=new byte[PlcMesObject.getPlcAddressLength()];
                int maxRead=1092;
                int size=PlcMesObject.getPlcAddressLength()%maxRead==0?
                        (PlcMesObject.getPlcAddressLength()/maxRead):
                        (PlcMesObject.getPlcAddressLength()/maxRead+1);
                for (int i = 0; i <size ; i++) {
                    int begin=i*maxRead;
                    int length=(i==size-1?PlcMesObject.getPlcAddressLength()-begin:maxRead);
                    String beginAddress=PlcMesObject.getPlcAddressBegin().substring(0, PlcMesObject.getPlcAddressBegin().indexOf("."))+"."+begin;
                    byte[] getplcvlues = plccontrol.readByte(beginAddress, length);
                    System.arraycopy(getplcvlues,0,resultValues,begin,length);
                }
                if (resultValues != null) {
                    PlcMesObject.setPlcParameterList(resultValues);
                }
            } catch (Exception e) {
                //log.info("异常:ip:{},port:{}",this.ip,this.port);
            }
        }
    }
}
nglib/src/builder/ThreadHttpServer.java
@@ -5,8 +5,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import S7.S7control;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.sun.net.httpserver.*;
public class ThreadHttpServer  {
@@ -16,9 +14,6 @@
    private static final String Httpcontext="/demo";
    private static final int nThreads=8;
    public static void mains() {
        System.out.println("S7链接");
        S7control s7=new S7control(EPlcType.S1500, "192.168.30.14", 102, 0, 0);
        System.out.println("S7:"+s7.readByte("DB34.0",  2));
        HttpServer httpServer;
        try {
            httpServer=HttpServer.create(new InetSocketAddress(port),0);
nglib/src/ng/devices/InitUtil.java
New file
@@ -0,0 +1,91 @@
package ng.devices;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class InitUtil {
    //初始化word
    public static PlcParameterObject initword(String jsonFilePath) {
        try {
            FileReader fileReader = new FileReader(jsonFilePath);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            StringBuilder content = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                content.append(line);
            }
            bufferedReader.close();
            fileReader.close();
            JSONObject jsonfileobj = new JSONObject(content.toString());
            JSONArray jsonArray = jsonfileobj.getJSONArray("parameteInfor");
            PlcParameterObject plcParameterObject = new PlcParameterObject();
            plcParameterObject.setPlcAddressBegin(jsonfileobj.getStr("plcAddressBegin"));//设置起始位地址
            plcParameterObject.setPlcAddressLength(Integer.valueOf(jsonfileobj.getStr("plcAddressLenght")));//设置地址长度
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject parameterObj = jsonArray.getJSONObject(i);
                PlcParameterInfo plcParameterInfo = new PlcParameterInfo(jsonfileobj.getStr("plcAddressBegin")); //参数实例
                String codeid = parameterObj.getStr("codeId");
                plcParameterInfo.setCodeId(codeid);
                plcParameterInfo.setAddressIndex(Integer.valueOf(parameterObj.getStr("addressIndex")));
                //plcParameterInfo.setRatio(Integer.valueOf(parameterObj.getStr("ratio")));
                plcParameterInfo.setAddressLength(Integer.valueOf(parameterObj.getStr("addressLenght")));
                plcParameterInfo.setUnit(parameterObj.getStr("unit"));
                plcParameterObject.addPlcParameter(plcParameterInfo);
            }
            return plcParameterObject;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    //初始化bit
    public static PlcBitObject initbit(String jsonFilePath) {
        PlcBitObject plcBitObject = new PlcBitObject();
        try {
            FileReader fileReader = new FileReader(jsonFilePath);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            StringBuilder content = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                content.append(line);
            }
            bufferedReader.close();
            fileReader.close();
            JSONObject jsonfileobj = new JSONObject(content.toString());
            JSONArray jsonArray = jsonfileobj.getJSONArray("parameteInfor");
            plcBitObject.setPlcAddressBegin(jsonfileobj.getStr("plcAddressBegin"));//设置起始位地址
            plcBitObject.setPlcAddressLength(Integer.valueOf(jsonfileobj.getStr("plcAddressLenght")));//设置地址长度
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject parameterObj = jsonArray.getJSONObject(i);
                PlcBitInfo plcBitInfo = new PlcBitInfo(jsonfileobj.getStr("plcAddressBegin")); //参数实例
                String codeid = parameterObj.getStr("codeId");
                plcBitInfo.setCodeId(codeid);
                plcBitInfo.setAddressIndex(Integer.valueOf(parameterObj.getStr("addressIndex")));
                plcBitObject.addPlcBit(plcBitInfo);
            }
            System.out.println("");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return plcBitObject;
    }
}
nglib/src/ng/devices/ModbusService.java
@@ -1,13 +1,19 @@
package ng.devices;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import builder.S7control;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import ng.db.DBHelper;
import ng.db.DBSession;
import ng.db.DBSession.StdCallResult;
public abstract class ModbusService implements Runnable  {
    //modbus客户端
    protected ModbusClient client;
@@ -26,6 +32,7 @@
    protected  String ip;
    //设备端口
    protected int port;
    protected String remarks;
    //线程
    java.lang.Thread thread;
    //缓冲区(服务允许发送超过协议要求的数据,所以缓冲区更大)
@@ -41,7 +48,7 @@
    }
    //运行
    public void Run(int MachineID,String ip,int port,byte state,int ReadOffset,int ReadSize,int timeout,byte FunctionType){
    public void Run(int MachineID,String ip,int port,byte state,int ReadOffset,int ReadSize,int timeout,byte FunctionType,String remarks){
        //设置参数
        this.machineID=MachineID;
        this.ip=ip;
@@ -49,12 +56,20 @@
        this.readOffset=ReadOffset;
        this.readSize=ReadSize;
        this.functionType= FunctionType;
        this.client=new ModbusClient();
        //启动线程
        this.client.setConnectionParam(MachineID,ip,port,(byte)state,timeout);
        this.remarks= remarks;
        thread=new java.lang.Thread(this);
        thread.start();
        //启动线程
        if(this.port==102){
            thread=new java.lang.Thread(this);
            thread.start();
        }else{
            this.client=new ModbusClient();
            this.client.setConnectionParam(MachineID,ip,port,(byte)state,timeout);
            thread=new java.lang.Thread(this);
            thread.start();
        }
    }
    
    
@@ -89,6 +104,92 @@
        }
        return msg;
    }
    //一次s7读取行为
    String onceS7(){
        try {
            DBSession sn=null;
            String result=null;
            String flag=null;
            String messsage="000000000000000000";
            EPlcType ePlcType=null;
            if(this.machineID==78){
                ePlcType=EPlcType.S1500;
            }else{
                ePlcType=EPlcType.S1200;
            }
            S7control s7=new S7control(ePlcType, ip, port, 0, 0);
            //List<Integer> word=s7.readWord("DB34.122",  1);
            List<Integer> listWord=s7.readWord(this.remarks,(this.readSize/2));
            if(listWord==null){
                System.out.println("notread");
                return "";
            }
            for(int i=0;i<listWord.size();i++){
                //System.out.println("i  "+listWord.size()+"   "+messsage);
                messsage+=HexUtil.intTo2ByteHex(listWord.get(i));
            }
            //System.out.println(messsage);
            //System.out.println(ip+"  "+s7.readWord("DB34.122",  1));
            //数据库
            DBHelper db=DBHelper.getDBHelper("mes");
            try{
                //创建连接
                sn=db.createSession(false);
                Connection con= sn.getConnection();
                //调用那个存储过程
                CallableStatement sql=con.prepareCall("{call Total_method(?,?,?,?)}");
                sql.registerOutParameter(3, java.sql.Types.VARCHAR);
                sql.registerOutParameter(4, java.sql.Types.VARCHAR);
                sql.setString(1, messsage);
                sql.setLong(2, machineID);
                sql.execute();
                //读取返回参数
                result= sql.getString(3);
                flag= sql.getString(4);
                if (result!=null&&result.length()>0){
                    String []results=result.split(",");
                    //得到存储过程返回的值,数组第一个为地址,第二个为值
                    int resultsLength=results.length;
                    int resultsSize=resultsLength/2;
                    for(int i=1;i<resultsSize+1;i++){
                        int addressIndex=(i-1)*2;
                        int valueIndex=i*2-1;
                        s7.writeWord(results[addressIndex],Integer.valueOf(results[valueIndex]));//参数组写入
                    }
//                    if(results.length==2){
//                        s7.writeWord(results[0],Integer.valueOf(results[1]) );
//                    }
//                    if(results.length==4){
//                        s7.writeWord(results[0],Integer.valueOf(results[1]));//配方
//                        s7.writeWord(results[2],Integer.valueOf(results[3]));//速度
//                    }
                    List<Integer> listWord2=s7.readWord(this.remarks,(this.readSize/2));
                    System.out.println(listWord2.size());
                }
            }
            catch(Exception e){
                e.printStackTrace();
            }
            finally{
                sn.close();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally{
        }
        return "";
    }
    public void SendPLC(int Address, int count, byte[] buffer, int offset) {
        this.client.write(Address, count, buffer, offset);
@@ -110,10 +211,15 @@
    void proc(){
        running=true;
        while(running){
            if(client.IsEnable()){
            if(this.port==102||client.IsEnable()){
                try {
                    java.lang.Thread.sleep(UpadateInterval);
                    String back=once();
                    if(this.port==102){
                        String back=onceS7();
                    }else{
                        String back=once();
                    }
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                }
@@ -141,6 +247,7 @@
    @Override
    public void run() {
        // TODO Auto-generated method stub
        proc();
    }
    public class ModbusDataPackage{
nglib/src/ng/devices/MysqlService.java
@@ -4,6 +4,8 @@
import java.sql.Connection;
import builder.Manager;
import builder.S7control;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import ng.db.DBHelper;
import ng.db.DBSession;
import ng.devices.ModbusService.ModbusDataPackage;
@@ -110,21 +112,22 @@
        DBSession sn=null;
        String result=null;
        String flag=null;
        try{
        //创建连接
            sn=this.db.createSession(false);
            Connection con= sn.getConnection();
            //掉哦那个存储过程
             CallableStatement sql=con.prepareCall("{call Total_method(?,?,?,?)}");
             sql.registerOutParameter(3, java.sql.Types.VARCHAR);
               sql.registerOutParameter(4, java.sql.Types.VARCHAR);
               sql.setString(1, s);
               sql.setLong(2, id);
               sql.execute();
               //读取返回参数
               result= sql.getString(3);
              flag= sql.getString(4);
            //调用那个存储过程
            CallableStatement sql=con.prepareCall("{call Total_method(?,?,?,?)}");
            sql.registerOutParameter(3, java.sql.Types.VARCHAR);
            sql.registerOutParameter(4, java.sql.Types.VARCHAR);
            sql.setString(1, s);
            sql.setLong(2, id);
            sql.execute();
            //读取返回参数
            result= sql.getString(3);
            flag= sql.getString(4);
        }
        catch(Exception e){
            e.printStackTrace();
@@ -146,6 +149,7 @@
                //更新最后一次发送
           this.lastSend=result;
           //返回要发送的报文
                System.out.println(result);
           return this.fillPack(arg1,result);
            }
            }
nglib/src/ng/devices/PlcBitInfo.java
New file
@@ -0,0 +1,85 @@
package ng.devices;
public class PlcBitInfo {
    public PlcBitInfo(String startAddress) {
        this.startAddress = startAddress;
    }
    private String startAddress;
    // 参数标识
    private String codeId;
    // 参数名称
    private String name;
    // 读取 参数值
    private Boolean value;
    // 参数地址
    private int addressIndex;
    public String getCodeId() {
        return this.codeId;
    }
    public void setCodeId(String codeId) {
        this.codeId = codeId;
    }
    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Boolean getValue() {
        return this.value;
    }
    public void setValue(Boolean value) {
        this.value = value;
    }
    public int getAddressIndex() {
        return this.addressIndex;
    }
    /**
     * 获取地址
     *
     * @param index 索引地址
     */
    public String getAddress(int index) {
        String[] stringdatas = this.startAddress.trim().split("\\.");
        if (stringdatas.length < 2) {
            return null;
        }
        int dbwindex = 0;
        int bitindex = 0;
        if (stringdatas.length == 3) {
            dbwindex = Integer.parseInt(stringdatas[1]);
            bitindex = Integer.parseInt(stringdatas[2]);
        } else
        {
            return null;
        }
        dbwindex += index / 8;
        bitindex += index % 8;
        return stringdatas[0] + "." + dbwindex + "." + bitindex;
    }
    /**
     * 获取地址
     *
     */
    public String getAddress() {
      return   getAddress(this.addressIndex);
    }
    public void setAddressIndex(int addressindex) {
        this.addressIndex = addressindex;
    }
}
nglib/src/ng/devices/PlcBitObject.java
New file
@@ -0,0 +1,127 @@
package ng.devices;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
public class PlcBitObject {
    // 该模块数据类型,数据起始位置
    private String plcAddressBegin;
    // 数据地址长度:第一参数到最后一个参数的长度
    private int plcAddressLength;
    //private ArrayList<PlcBitInfo> plcBitList;
    private LinkedHashMap<String,PlcBitInfo> plcBitMap;
    /**
     * @return 数据区开始地址
     */
    public String getPlcAddressBegin() {
        return plcAddressBegin;
    }
    /**
     * @param plcAddressBegin 设置数据区开始地址
     */
    public void setPlcAddressBegin(String plcAddressBegin) {
        this.plcAddressBegin = plcAddressBegin;
    }
    /**
     * @return 数据区 读取所有数据所需的长度(以byte类型为基准)
     */
    public int getPlcAddressLength() {
        return plcAddressLength;
    }
    /**
     * @return 设置:数据区 读取所有数据所需的长度(以byte类型为基准)
     */
    public void setPlcAddressLength(int plcAddressLength) {
        this.plcAddressLength = plcAddressLength;
    }
    /**
     * @return 获取参数实例集合
     */
    public LinkedHashMap<String,PlcBitInfo> getBitMap() {
        return plcBitMap;
    }
    /**
     * 根据参数标识 获取某个参数实例
     *
     * @param codeid 参数标识
     * @return 获取某个参数实例
     */
    public PlcBitInfo getPlcBit(String codeid) {
        if (plcBitMap != null) {
            /*for (PlcBitInfo plcbitInfo : plcBitList) {
                if (plcbitInfo.getCodeId().equals(codeid))
                    return plcbitInfo;
            }*/
            return plcBitMap.get(codeid);
        } else
        {
            return null;
        }
    }
    /**
     * 根据参数标识 获取某个参数实例
     *
     * @param codeids 参数标识
     * @return 获取某个参数实例
     */
    public List<Boolean> getPlcBitValues(List<String> codeids) {
        List<Boolean> arrayList = new ArrayList<>();
        if (plcBitMap != null) {
            for (String codeId : codeids) { // 按照传入参数的顺序遍历
                    arrayList.add(plcBitMap.get(codeId).getValue());
            }
        }
        return arrayList;
    }
    public List<String> getAddressListByCodeId(List<String> codeIdList) {
        List<String> addressList = new ArrayList<>();
        for (String codeId : codeIdList) {
            addressList.add(plcBitMap.get(codeId).getAddress());
        }
        return addressList;
    }
    /**
     * 添加参数实例
     *
     * @param param 参数实例
     */
    public void addPlcBit(PlcBitInfo param) {
        if (plcBitMap != null) {
            plcBitMap.put(param.getCodeId(), param);
        }
        else {
            plcBitMap = new LinkedHashMap<String,PlcBitInfo>();
            plcBitMap.put(param.getCodeId(),param);
        }
    }
    /**
     * 根据PLC返回的数据 给参数实例赋值
     *
     * @param plcValueArray PLC读取回来的byte类型数据集合
     */
    public void setPlcBitList(List<Boolean> plcValueArray) {
        if (plcBitMap != null) {
            Collection<PlcBitInfo> values=plcBitMap.values();
            for (PlcBitInfo plcbitInfo : values) {
                plcbitInfo.setValue(plcValueArray.get(plcbitInfo.getAddressIndex()));
            }
        }
    }
}
nglib/src/ng/devices/PlcParameterInfo.java
New file
@@ -0,0 +1,115 @@
package ng.devices;
public class PlcParameterInfo {
    public PlcParameterInfo(String startAddress) {
        this.startAddress = startAddress;
    }
    private String startAddress;
    // 参数标识
    private String codeId;
    // 参数名称
    private String name;
    // 读取 参数值
    private String value;
    // // 写入 参数值
    // private String writeValue;
    // 参数单位
    private String unit;
    // 参数值转换系数
    private int ratio;
    // 参数地址
    private int addressIndex;
    // 参数地址位长度
    private int addressLength;
    public String getCodeId() {
        return this.codeId;
    }
    public void setCodeId(String codeId) {
        this.codeId = codeId;
    }
    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getValue() {
        return this.value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    // public String getWriteValue() {
    //     return this.writeValue;
    // }
    // public void setWriteValue(String writeValue) {
    //     this.writeValue = writeValue;
    // }
    public String getUnit() {
        return this.unit;
    }
    public void setUnit(String unit) {
        this.unit = unit;
    }
    public int getAddressIndex() {
        return this.addressIndex;
    }
    public void setAddressIndex(int addressindex) {
        this.addressIndex = addressindex;
    }
    public int getAddressLength() {
        return this.addressLength;
    }
    public void setAddressLength(int addresslength) {
        this.addressLength = addresslength;
    }
    public int getRatio() {
        return this.ratio;
    }
    public void setRatio(int ratio) {
        this.ratio = ratio;
    }
    /**
     * 获取地址
     *
     * @param index 索引地址
     */
    public String getAddress(int index) {
        String[] stringdatas = this.startAddress.trim().split("\\.");
        int addressLength = this.addressLength;
        if (addressLength < 2) {
            return null;
        }
        int wordindex = Integer.parseInt(stringdatas[1]) + index;
        return stringdatas[0] + "." + wordindex;
    }
    public String getAddress() {
        return getAddress(this.addressIndex);
    }
}
nglib/src/ng/devices/PlcParameterObject.java
New file
@@ -0,0 +1,252 @@
package ng.devices;
import com.github.s7connector.impl.serializer.converter.StringConverter;
import com.github.xingshuangs.iot.utils.IntegerUtil;
import com.github.xingshuangs.iot.utils.ShortUtil;
import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
public class PlcParameterObject {
    // 该模块数据类型,数据起始位置
    private String plcAddressBegin;
    // 数据地址长度:第一参数到最后一个参数的长度
    private int plcAddressLength;
    private LinkedHashMap<String,PlcParameterInfo> plcParameterMap;
    /**
     * @return 数据区开始地址
     */
    public String getPlcAddressBegin() {
        return plcAddressBegin;
    }
    /**
     * @param plcAddressBegin 设置数据区开始地址
     */
    public void setPlcAddressBegin(String plcAddressBegin) {
        this.plcAddressBegin = plcAddressBegin;
    }
    /**
     * @return 数据区 读取所有数据所需的长度(以byte类型为基准)
     */
    public int getPlcAddressLength() {
        return plcAddressLength;
    }
    /**
     * @return 设置:数据区 读取所有数据所需的长度(以byte类型为基准)
     */
    public void setPlcAddressLength(int plcAddressLength) {
        this.plcAddressLength = plcAddressLength;
    }
    /**
     * @return 获取参数实例集合
     */
    public LinkedHashMap<String,PlcParameterInfo> getPlcParameterMap() {
        return plcParameterMap;
    }
    /**
     * 根据参数标识 获取某个参数实例
     *
     * @param codeid 参数标识
     * @return 获取某个参数实例
     */
    public PlcParameterInfo getPlcParameter(String codeid) {
        if (plcParameterMap != null) {
            return plcParameterMap.get(codeid);
        } else {
            return null;
        }
        /*if (plcParameterList != null) {
            for (PlcParameterInfo plcParameterInfo : plcParameterList) {
                if (plcParameterInfo.getCodeId().equals(codeid))
                    return plcParameterInfo;
            }
            return null;
        } else
            return null;*/
    }
    /**
     * 根据参数标识 获取某个参数实例
     *
     * @param codeids 参数标识
     * @return 获取某个参数实例
     */
    public List<String> getPlcParameterValues(List<String> codeids) {
        List<String> arrayList = new ArrayList<>();
        if (plcParameterMap != null) {
            /*Map<String, PlcParameterInfo> resultMap = new LinkedHashMap<>(); // 使用 LinkedHashMap 保留插入顺序
            for (PlcParameterInfo plcParameterInfo : plcParameterList) {
                if (codeids.contains(plcParameterInfo.getCodeId())) {
                    resultMap.put(plcParameterInfo.getCodeId(), plcParameterInfo);
                }
            }*/
            for (String codeId : codeids) { // 按照传入参数的顺序遍历
                PlcParameterInfo plcParameterInfo = plcParameterMap.get(codeId);
                if (plcParameterInfo != null) {
                    arrayList.add(plcParameterInfo.getValue());
                } else {
                    arrayList.add(null); // 如果找不到对应的值,添加 null
                }
            }
        }
        return arrayList;
    }
    /**
     * 根据参数标识 获取传入参数的plc地址
     *
     * @param codeIdList 参数标识
     * @return 传入参数的plc地址
     */
    public List<String> getAddressListByCodeId(List<String> codeIdList) {
        List<String> addressList = new ArrayList<>();
        if (plcParameterMap!=null)
        {
            for (String codeId : codeIdList) {
                    String address = plcParameterMap.get(codeId).getAddress();
                    if (address != null) {
                        addressList.add(address);
                    }
        }
        }
        return addressList;
    }
    /**
     * 添加参数实例
     *
     * @param param 参数实例
     */
    public void addPlcParameter(PlcParameterInfo param) {
        if (plcParameterMap != null) {
            plcParameterMap.put(param.getCodeId(), param);
        }
        else {
            plcParameterMap =new  LinkedHashMap<String,PlcParameterInfo>();
            plcParameterMap.put(param.getCodeId(), param);
        }
        /*if (plcParameterList != null)
            plcParameterList.add(param);
        else {
            plcParameterList = new ArrayList<PlcParameterInfo>();
            plcParameterList.add(param);
        }*/
    }
    /**
     * 根据PLC返回的数据 给参数实例赋值
     *
     * @param plcValueArray PLC读取回来的byte类型数据集合
     */
    public void setPlcParameterList(byte[] plcValueArray) {
        if (plcParameterMap != null) {
            Collection<PlcParameterInfo> values=  plcParameterMap.values();
            for (PlcParameterInfo plcParameterInfo :values) {
                byte[] valueList = new byte[plcParameterInfo.getAddressLength()];
//                System.out.println(plcParameterInfo.getAddressLength());
                for (int i = 0; i < plcParameterInfo.getAddressLength(); i++) {
                    Array.setByte(valueList, i, plcValueArray[plcParameterInfo.getAddressIndex() + i]);
                }
                if (plcParameterInfo.getAddressLength() == 2) {
                    plcParameterInfo.setValue(String.valueOf(ShortUtil.toUInt16(valueList)));
                } else if (plcParameterInfo.getAddressLength() == 4) {
                    plcParameterInfo.setValue(String.valueOf(IntegerUtil.toUInt32(valueList)));
                }else if(plcParameterInfo.getAddressLength()==256){
                    StringConverter converter = new StringConverter();
                    String s="";
                    String extract1 = converter.extract(s.getClass(),valueList, 0, 0);
                    plcParameterInfo.setValue(extract1);
                }else {
                    plcParameterInfo.setValue((byteToHexString(valueList)));
                }
            }
        }
    }
    /**
     * 把写入值转化为byte[]
     * @param param 参数实例
     * @param data 写入值的字符类型
     */
    public byte[] setValueToBytes(PlcParameterInfo param, String data) {
        if (param.getAddressLength() == 2) {
            return ShortUtil.toByteArray(Integer.parseInt(data));
        } else if (param.getAddressLength() == 4) {
            return IntegerUtil.toByteArray(Long.parseLong(data));
        }
        else if (param.getAddressLength() >10) {
           return data.getBytes();
        } else {
            return data.getBytes();
        }
    }
    /**
     * short类型转byte[]
     *
     * @param s short类型值
     */
    public static byte[] short2byte(short s) {
        byte[] b = new byte[2];
        for (int i = 0; i < 2; i++) {
            int offset = 16 - (i + 1) * 8; //计算偏移量
            b[i] = (byte) ((s >> offset) & 0xff); //把16位分为2个8位进行分别存储
        }
        return b;
    }
    /**
     * byte[]类型转short
     *
     * @param b byte[]类型值
     */
    public static short byte2short(byte[] b) {
        short l = 0;
        for (int i = 0; i < 2; i++) {
            l <<= 8; //<<=和我们的 +=是一样的,意思就是 l = l << 8
            l |= (b[i] & 0xff); //和上面也是一样的  l = l | (b[i]&0xff)
        }
        return l;
    }
    /**
     * byte[]类型转short
     *
     * @param b byte[]类型值
     */
    public static int byte2int(byte[] b) {
        int l = 0;
        for (int i = 0; i < 4; i++) {
            l <<= 8; //<<=和我们的 +=是一样的,意思就是 l = l << 8
            l |= (b[3-i] & 0xff); //和上面也是一样的  l = l | (b[i]&0xff)
        }
        return l;
    }
    public static byte[] int2byte(int s){
        byte[] b = new byte[2];
        for(int i = 0; i < 4; i++){
            int offset = 16 - (i+1)*8; //因为byte占4个字节,所以要计算偏移量
            b[i] = (byte)((s >> offset)&0xff); //把32位分为4个8位进行分别存储
        }
        return b;
    }
    public static String byteToHexString(byte[] bytes) {
        String str = new String(bytes, StandardCharsets.UTF_8).trim();
        return str;
    }
}