当前位置:   article > 正文

C# 云台控制 Pelco_D-P协议_pelco device utility

pelco device utility

Pelco_D:

 

using System;
using System.Collections;

namespace Pelco
{
 /// <summary>
 /// dot.NET Implementation of Pelco D Protocol
 /// </summary>
    public class Pelco_D
 {
        private static readonly byte STX = 0xFF;//同步字节

  #region Pan and Tilt Commands
  #region Command1
  private const byte FocusNear = 0x01;
  private const byte IrisOpen = 0x02;
  private const byte IrisClose = 0x04;
  private const byte CameraOnOff = 0x08;
  private const byte AutoManualScan = 0x10;
  private const byte Sense = 0x80;
  #endregion

  #region Command2
  private const byte PanRight = 0x02;
  private const byte PanLeft = 0x04;
  private const byte TiltUp =  0x08;
  private const byte TiltDown = 0x10;
  private const byte ZoomTele = 0x20;
  private const byte ZoomWide = 0x40;
  private const byte FocusFar = 0x80;
  #endregion

  #region Data1
  private const byte PanSpeedMin = 0x00;
  private const byte PanSpeedMax = 0xFF;
  #endregion

  #region Data2
  private const byte TiltSpeedMin = 0x00;
  private const byte TiltSpeedMax = 0x3F;
  #endregion
  #endregion

  #region Enums
  public enum PresetAction {Set,Clear,Goto}
  public enum AuxAction {Set=0x09,Clear=0x0B}
  public enum Action {Start,Stop}
  public enum LensSpeed {Low=0x00,Medium=0x01,High=0x02,Turbo=0x03}
  public enum PatternAction {Start,Stop,Run}
  public enum SwitchAction {Auto=0x00,On=0x01,Off=0x02}
  public enum Switch {On=0x01,Off=0x02}
  public enum Focus {Near = FocusNear,Far = FocusFar}
  public enum Zoom {Wide = ZoomWide,Tele = ZoomTele}
  public enum Tilt {Up = TiltUp,Down = TiltDown}
  public enum Pan {Left = PanLeft,Right = PanRight}
  public enum Scan {Auto, Manual}
  public enum Iris {Open = IrisOpen,Close = IrisClose}
  #endregion

  #region Extended Command Set
  public byte[] Preset(uint deviceAddress, byte preset, PresetAction action)
  {
   byte m_action;
   switch (action)
   {
    case PresetAction.Set:
     m_action = 0x03;
     break;
    case PresetAction.Clear:
     m_action = 0x05;
     break;
    case PresetAction.Goto:
     m_action = 0x07;
     break;
    default:
     m_action = 0x03;
     break;
   }
   return Message.GetMessage(deviceAddress,0x00,m_action,0x00,preset);
  }

  public byte[] Flip(uint deviceAddress)
  {
   return Message.GetMessage(deviceAddress,0x00,0x07,0x00,0x21);
  }

  public byte[] ZeroPanPosition(uint deviceAddress)
  {
   return Message.GetMessage(deviceAddress,0x00,0x07,0x00,0x22);
  }

  public byte[] SetAuxiliary(uint deviceAddress,byte auxiliaryID, AuxAction action)
  {
   if(auxiliaryID<0x00)
    auxiliaryID = 0x00;
   else if(auxiliaryID>0x08)
    auxiliaryID = 0x08;
   return Message.GetMessage(deviceAddress,0x00,(byte)action,0x00,auxiliaryID);
  }

  public byte[] RemoteReset(uint deviceAddress)
  {
   return Message.GetMessage(deviceAddress,0x00,0x0F,0x00,0x00);
  }
  public byte[] Zone(uint deviceAddress,byte zone, Action action)
  {
   if(zone<0x01 & zone>0x08)
    throw new Exception("Zone value should be between 0x01 and 0x08 include");
   byte m_action;
   if(action == Action.Start)
    m_action = 0x11;
   else
    m_action = 0x13;

   return Message.GetMessage(deviceAddress,0x00,m_action,0x00,zone);
  }

  public byte[] WriteToScreen(uint deviceAddress,string text)
  {
   if(text.Length > 40)
    text = text.Remove(40,text.Length-40);
   System.Text.Encoding encoding = System.Text.Encoding.ASCII;
   byte[] m_bytes = new byte[encoding.GetByteCount(text)*7];
   int i = 0;
   byte m_scrPosition;
   byte m_ASCIIchr;
   
   foreach(char ch in text)
   {
    m_scrPosition = Convert.ToByte(i/7);
    m_ASCIIchr = Convert.ToByte(ch);
    Array.Copy(Message.GetMessage(deviceAddress,0x00,0x15,m_scrPosition,m_ASCIIchr),

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/518680
推荐阅读
相关标签
  

闽ICP备14008679号