iT邦幫忙

1

控制ip cam I/O

  • 分享至 

  • xImage

因ip Cam I/O 要控制很東設備 所以想寫一款根據惡影機畫面自動調整設備開關的軟體
使用ONVIF協議做控制 PYTHON做語法
以下是ONVIF協議解說:

SetRelayOutputSettings
Description:
This operation sets the settings of a relay output. The relay can work in two relay modes:
Bistable – After setting the state, the relay remains in this state.
Monostable – After setting the state, the relay returns to its idle state after the specified time.
The physical idle state of a relay output can be configured by setting the IdleState to ‘open’ or ‘closed’ (inversion of the relay behaviour).

Idle State ‘open’ means that the relay is open when the relay state is set to ‘inactive’ through the trigger command (see Section 8.5.3) and closed when the state is set to ‘active’ through the same command.

Idle State ‘closed’ means, that the relay is closed when the relay state is set to ‘inactive’ through the trigger command (see Section 8.5.3) and open when the state is set to ‘active’ through the same command.
SOAP action:
http://www.onvif.org/ver10/deviceio/wsdl/SetRelayOutputSettings
Input:
[SetRelayOutputSettings]
RelayOutput [RelayOutput]
token - required; [ReferenceToken]
Unique identifier referencing the physical entity.
Properties [RelayOutputSettings]
Mode [RelayMode]
'Bistable' or 'Monostable'
Bistable – After setting the state, the relay remains in this state.
Monostable – After setting the state, the relay returns to its idle state after the specified time.
- enum { 'Monostable', 'Bistable' }
DelayTime [duration]
Time after which the relay returns to its idle state if it is in monostable mode. If the Mode field is set to bistable mode the value of the parameter can be ignored.
IdleState [RelayIdleState]
'open' or 'closed'
'open' means that the relay is open when the relay state is set to 'inactive' through the trigger command and closed when the state is set to 'active' through the same command.
'closed' means that the relay is closed when the relay state is set to 'inactive' through the trigger command and open when the state is set to 'active' through the same command.
- enum { 'closed', 'open' }
RelayOutputToken [ReferenceToken]
Properties [RelayOutputSettings]
Mode [RelayMode]
'Bistable' or 'Monostable'
Bistable – After setting the state, the relay remains in this state.
Monostable – After setting the state, the relay returns to its idle state after the specified time.
- enum { 'Monostable', 'Bistable' }
DelayTime [duration]
Time after which the relay returns to its idle state if it is in monostable mode. If the Mode field is set to bistable mode the value of the parameter can be ignored.
IdleState [RelayIdleState]
'open' or 'closed'
'open' means that the relay is open when the relay state is set to 'inactive' through the trigger command and closed when the state is set to 'active' through the same command.
'closed' means that the relay is closed when the relay state is set to 'inactive' through the trigger command and open when the state is set to 'active' through the same command.
- enum { 'closed', 'open' }
Output:
[SetRelayOutputSettingsResponse]

但使用後卻不能執行
以下程式碼

from onvif import ONVIFCamera 
mycam = ONVIFCamera('XXX.XXX.XXX.XXX', 80, 'XXXXX', 'XXXXXX')
params = mycam.devicemgmt.create_type('SetRelayOutputSettings')
params.RelayOutputToken = 'AlarmOut_0'
# params.Properties.Mode = 'Bistable'
# params.Properties.DelayTime = 'PT1S'
# params.Properties.IdleState = 'closed'
params.Properties = {'Mode':'Bistable','DelayTime':'PT1S','IdleState':'closed'}
mycam.devicemgmt.SetRelayOutputSettings(params)
mycam.devicemgmt.SetRelayOutputState({'RelayOutputToken':'AlarmOut_0','LogicalState':'active'})

我是哪裡有誤嗎?

ccutmis iT邦高手 2 級 ‧ 2023-02-08 22:12:16 檢舉
google said i hate chatGPT...
https://blog.csdn.net/zong596568821xp/article/details/89644654
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
JamesDoge
iT邦高手 1 級 ‧ 2023-02-18 21:14:05

建議您使用 try-except 陳述式,捕捉錯誤,以瞭解程式碼執行時可能發生了什麼問題。

from onvif import ONVIFCamera

mycam = ONVIFCamera('XXX.XXX.XXX.XXX', 80, 'XXXXX', 'XXXXXX')

try:
    params = mycam.devicemgmt.create_type('SetRelayOutputSettings')
    params.RelayOutputToken = 'AlarmOut_0'
    params.Properties = {'Mode':'Bistable','DelayTime':'PT1S','IdleState':'closed'}
    mycam.devicemgmt.SetRelayOutputSettings(params)
    mycam.devicemgmt.SetRelayOutputState({'RelayOutputToken':'AlarmOut_0','LogicalState':'active'})
except Exception as e:
    print('Error:', e)

我要發表回答

立即登入回答