You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by GitBox <gi...@apache.org> on 2023/01/06 08:08:06 UTC

[GitHub] [plc4x] chzhm159 commented on issue #714: [Feature Request]: 建议(Suggestion)参考 NI OPC Server (National Instruments OPC Server) 与 Labview 的交互方式(Shared Variables)

chzhm159 commented on issue #714:
URL: https://github.com/apache/plc4x/issues/714#issuecomment-1373326534

   使用 Java 举例,PLC 使用 KEYENCE KV-7500,读取一个32位有符号整数.
   
   Using Java as an example, PLC uses KEYENCE KV-7500 to read a 32-bit signed integer.
   
   First step:
     configuration variables(Device information and register information)
   ```
   {
     "devices": [                      
       {
         "deviceID": "L1:D1",          // device unique identifier(设备全局唯一编号)
         "deviceName": "station-1",
         "deviceModel": "kv-7500",     
         "protocolType": "upperlink",  
         "host": "192.168.100.1",      
         "port": 8501,
         "connectTimeout": 3000,       
         "retryInterval": 3000,        
         "tags": [
           {
             "tagName": "output",
             "key": "L1:D1:output",    // Globally unique key for each tag(Tag全局唯一编号)
             "registerType": "FM",     // register area (plc寄存器区域名称)
             "registerIndex": 100,     // register index (寄存器区编号)
             "offset":0,
             "unit": "int32",          // register data type (寄存器数据类型)
             "count": 3,
             "readInterval": 10,       // Read cycle, in milliseconds (读取周期,单位毫秒)
             "timeout": 60000,                 
             "operate": "r",           // read or write or (read and write) (读/写/(读写))
           }
         ]
       }
     ]
   }
   ```
   Framework:
     框架的工作就是解析配置,建立与plc的链接,同时具备失败重连的特性,同时根据每个Tag的配置自动
     读取对于的数据缓存起来.将链接管理与协议解析对编程人员完全屏蔽,仅需要了解plc基本的寄存器
     区域,名称,数据类型等通用概念即可
     The job of the framework is to parse the configuration, link the device, and automatically collect the data of the PLC and save it to the cache
   
   Second step:
     业务代码就可以非常简单,完全不关心plc的链接与通信协议
     My business code can be written like this:
   ```
   public class Demo{
   
     public void onConnectSuccessfully(){
       // connection succeeded (链接成功)
     }
     
     public void onConnectFailed(){
      // connection failed (链接失败)
     }
   
     public void onDisconnected(){
      // lost connection (连接中断开)
     }
   
     public void onClosed(){
      // connection closed (连接关闭)
     }
     /**
     * Called according to functional needs (根据功能需要来调用)
     */  
     public void onOutput(){
       // Get instance by unique identifier for each variable
       Tag otherTag = TagMangager.getTag("L1:D1:output");
   
       // ==== read value ===    
       
       // Read mode 1. Read the original value, which can default to Byte
       Byte[] raw = tag.getRawData();
       int raw = DataUtils.convert2Int(raw);
       
       // Read mode 2. Directly obtain the value of a specific type
       int raw = tag.getInt();
   
       // >>>>> Business logic....save data to database, calculate, judge, etc.
   
       // ==== [Optional] write value ===
       tag.write(Byte[] data);
   
       // ==== [Optional] Read and write values to other variables ===
       Tag otherTag = TagMangager.getTag("key");
       otherTag.getXXX();
       otherTag.write(Data);
     }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org