Jazea / Onvif.Core

A lightweight ONVIF Discovery and Client library.
MIT License
68 stars 26 forks source link

How to use async focus move? #22

Open stoex opened 1 month ago

stoex commented 1 month ago

Hey there,

I'm checking the focus support of my camera like this:

var moveOptions = await _camera.Imaging.GetMoveOptionsAsync(_videoSourceToken);
if(moveOptions.Absolute != null)    // Camera has to support absolute focus
    HasFocus = true;

Although the camera supports the imaging client and the focus adaption, this code doesn't change the focus of the camera:

var move = new FocusMove { Relative = new RelativeFocus { Distance = dY, Speed = 1f } };
await _camera.FocusAsync(move);

This code doesn't work also:

var move = new FocusMove { Absolute = new AbsoluteFocus { Position = (float)abs / 100, Speed = 1f } };
Task task = _camera.Imaging.MoveAsync(_videoSourceToken, move);
await task;
HarryJeacock commented 1 month ago

Hey, How did you connect to a camera ? i get an error on camera.create but i have no clue what's causing it so was wondering if you could provide your code for connecting the camera? for me it just hangs tring to get a device time

stoex commented 1 month ago

Hey, How did you connect to a camera ? i get an error on camera.create but i have no clue what's causing it so was wondering if you could provide your code for connecting the camera? for me it just hangs tring to get a device time

// Create onvif camera object
var account = new Account(_ip, _apiUser, _apiPassword);
_camera = Camera.Create(account, ex => { });    // Null if onvif isn't supported