diff --git a/BallCamera.go b/BallCamera.go index 4effbbb..29d2753 100644 --- a/BallCamera.go +++ b/BallCamera.go @@ -187,6 +187,9 @@ type PTZ struct { } func (this *BallCamera) GetPTZ() (PTZ, error) { + if this == nil { + return PTZ{}, errors.New("BallCamera is nil") + } if this._type == BuKongQiu { var data PTZ @@ -273,6 +276,9 @@ func padding(n int) ([]byte, error) { } func (this *BallCamera) PtzGotoPut(Action int, P, T, Z float64) error { + if this == nil { + return errors.New("BallCamera is nil") + } if this._type == BuKongQiu { SerialStartHandle, err := Core.SerialStart(this.userId, func(lSerialHandle Core.LONG, lChannel Core.LONG, pRecvDataBuffer []byte, dwBufSize Core.DWORD, pUser unsafe.Pointer) { }) @@ -400,7 +406,9 @@ func (this *BallCamera) retrySend(handle Core.LONG, cmd []byte, maxRetries int, } func (receiver *BallCamera) StartBus(direction int, speed int) error { - + if receiver == nil { + return errors.New("BallCamera is nil") + } err := Core.PTZControlWithSpeed_Other(receiver.userId, Core.LONG(receiver.deviceInfo.ByStartChan), Core.DWORD(PTZEnum.toHikPTZEnum(direction)), Core.DWORD(0), Core.DWORD(speed)) if err != nil { return err @@ -408,6 +416,9 @@ func (receiver *BallCamera) StartBus(direction int, speed int) error { return nil } func (receiver *BallCamera) StopBus(direction int, speed int) error { + if receiver == nil { + return errors.New("BallCamera is nil") + } err := Core.PTZControlWithSpeed_Other(receiver.userId, Core.LONG(receiver.deviceInfo.ByStartChan), Core.DWORD(PTZEnum.toHikPTZEnum(direction)), Core.DWORD(1), Core.DWORD(speed)) if err != nil { return err @@ -429,9 +440,15 @@ func verify(data []byte) (byte, error) { } func (this *BallCamera) Logout() error { + if this == nil { + return errors.New("BallCamera is nil") + } return Core.Logout(this.userId) } func (this *BallCamera) Status() bool { + if this == nil { + return false + } return Core.NET_DVR_RemoteControl(this.userId) }