Java 通過 OPC UA 抓取機床數據 過程 采坑


OPCUA

最近 老板讓我 做一個 類似 物聯網的 實時 展示 機床 狀態 生產數據 的一個系統

本身我是做Java 的 一開始 是在網上 找到了 PLC 的 但是有些數據PLC 里面沒有

后續找到 了 eclipse 旗下的 [milo](eclipse/milo: Eclipse Milo™ - an open source implementation of OPC UA (IEC 62541). (github.com)) 通過OPC UA 連接

踩了很多坑 在這里 寫一下 參考了許多大佬的 文章

1.一開始 搜索到 OPC

參考ioufev 大佬的 Java實現OPC通信 一文

下載了 KEPServer V6 里面詳細介紹了 OPC 與 KEPServer V6 的使用教程

為我后面 的 OPC UA 搭好了基礎

2.后續聽說 使用 OPC UA 可以

找到 了 eclipse 旗下的 [milo](eclipse/milo: Eclipse Milo™ - an open source implementation of OPC UA (IEC 62541). (github.com))

在網上找了許多資料 有很多大佬的資料 多多少少會有一些問題

最后 選擇了 使用java的milo框架訪問OPCUA服務的方法_玩火的稻草人的博客-CSDN博客

  • 第一次訪問會出現 諸如

    UaServiceFaultException: status=Bad_UserAccessDenied, message=User does not have permission to perform the requested operation.
    

    如果出現此異常 > 右擊右下角KEP狀態欄圖標> OPC UA配置 > 受信任的客戶端 > 找到剛生成的證書 打X的證書 選擇信任 保存 再右擊圖標 > 重新初始化

  • UaServiceFaultException: status=Bad_CertificateUriInvalid, message=The URI specified in the ApplicationDescription does not match the URI in the Certificate.
    

    如果出現此類錯誤 找到 OpcUAClientRunner類里面的 createClient 方法

    OpcUaClientConfig.builder()
            .setApplicationUri(" ")//這里的值
    

    和生成證書的 KeyStoreLoader 類里面的 填寫一致

    SelfSignedCertificateBuilder builder = new SelfSignedCertificateBuilder(keyPair)
                        .setCommonName("Eclipse Milo Example Client")
                        .setOrganization("SanQuanKeJi")
                        .setOrganizationalUnit("dev")
                        .setLocalityName("CryanNing")
                        .setStateName("CA")
                        .setCountryCode("US")
                        .setApplicationUri("urn:eclipse:milo:examples:client")//與這里對應
                        .addDnsName("localhost")
                        .addIpAddress("127.0.0.1");       
    
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM