opc ua - How do I write a value to an OPC tag in kepware using PowerShell - Stack Overflow

How do I writeupdate the value of tag2 in Kepware using PowerShell. This is my code example and I am g

How do I write/update the value of tag2 in Kepware using PowerShell. This is my code example and I am getting the error

Invoke-RestMethod : The remote server returned an error: (400) Bad Request. At line:21 char:13

  • $response = Invoke-RestMethod -Uri $kepwareServerUrl -Method Put -Bod ...

  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    enter code here

        $kepwareServerUrl = http://localhost:57412/config/v1
     /project/channels/Channel1/devices/Device1/tags/Tag2'
      $newValue = 10
    
      $payload = @{
      "v" = $newValue
      } | ConvertTo-Json
    
    
      $username = "Administrator"
     $password = ""
     $encodedCredentials = 
    
    
    
    [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes
    ("${username}:${password}"))
    
    
    Write-Host "Payload: $payload"
    Write-Host "URL: $kepwareServerUrl"
    
    
    try 
    {
       $response = Invoke-RestMethod `
      -Uri $kepwareServerUrl -Method Put `
      -Body $payload  `
      -ContentType "application/json" `
      -Headers @{Authorization=("Basic 
       $encodedCredentials")}
       Write-Host "Tag value updated successfully."
      } 
      catch 
      {
        Write-Host "Failed to update the tag value. Error: $_"
      }
    
    
      if ($response -eq $null) {
       Write-Host "Failed to update the tag value."
      }  
      else 
      {
         Write-Host "Tag value updated successfully."
      }
    

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744784394a4593534.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信