2012年7月10日 星期二

Pelco D/P protocols


Introduction

This is GPL software. Do with it as you want, but feed us back any improvements.
This is a full C# classes to control a PELCO PTZ cameras, matrix switching systems,
reciever devices and more via RS422/485 'P' and 'D' protocol.
It supports all of the commands including UP, DOWN, IN, OUT, LEFT, RIGHT, NEAR, FAR, as well as other extended commands.
To use this, you need to put a RS232->RS422 adapter on the output of your desired serial port.
The Pelco doesn't return ANY usefull info back, so you only really need 2-wire support (one way) communications out. However, I advice to read it in order to know if the command was recieved by the device.
This section describes the protocol used when sending commands to an Intercept Dome in the “P” version protocol and Coaxitron series equipment and with Pelco’s “D” version receivers. Those protocols use no parity, one start bit, eight data bits, and one stop bit. The recommended baud rate is 4800 (4800, 8, N, 1, 1).

Theory

In those protocols the messages structure are different. However both of protocols using RS-485 port to send and recieve messages.
All values below are shown in hexadecimal (base 16).
Pelco P message structure
Byte
Value
Function
1
$A0
STX (start transmission)
2
$00 to $1F
Address
3
Data byte 1
(see below)
4
Data byte 2
(see below)
5
Data byte 3
(see below)
6
Data byte 4
(see below)
7
$AF
ETX (end transmission)
8
$00-$FF
Check Sum
Byte 1 is always $A0
Byte 2 is the receiver address, set by DIP switch in the receiver
Byte 3-6, see below
Byte 7 is always $AF
Byte 8 is an XOR sum of Bytes 1-7
The protocol is “zero indexed” so that the hexadecimal address sent in the protocol for the first receiver is $00 which corresponds to address 1.
Pelco D message structure
The “D” protocol has some added overhead to improve the reliability of transmissions. The format for a message is:
Word 1
Word 2
Word 3
Word 4
Word 5
Word 6
Word 7
Synch Byte
Address
Command 1
Command 2
Data 1
Data 2
Check Sum
The synchronization byte is always $FF.
The address is the logical address of the receiver/driver being controlled.
But in Pelco D protocol they are quite different:

Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Command 1
Sense
Reserved
Reserved
Auto / Manual Scan
Camera On / Off
Iris Close
Iris Open
Focus Near
Command 2
Focus Far
Zoom Wide
Zoom Tele
Down
Up
Left
Right
Always 0

The sense bit (command 1 bit 7) indicates the meaning of bits 4 and 3. If the sense bit is on and bits 4 and 3 are on the command will enable autoscan and turn the camera on. If the sense bit is off and bits 4 and 3 are on the command will enable manual scan and turn the camera off. Of course, if either bit 4 or bit 3 are off then no action will be taken for those features.
The reserved bits (6 and 5) should be set to 0.
Word 5 contains the pan speed. Pan speed is in the range $00 (stop) to $3F (high speed) and $FF for “turbo” speed. Turbo speed is the maximum speed the device can obtain and is considered separately because it is not generally a smooth step from high speed to turbo. That is, going from one speed to the next usually looks smooth and will provide for smooth motion with the exception of going into and out of turbo speed.
Word 6 contains the tilt speed. Tilt speed is in the range $00 (stop) to $3F (maximum speed).
Word 7 is the check sum. The check sum is the sum of bytes (excluding the synchronization byte) modulo 256.

Extended Command Set

In addition to the “PTZ” commands shown above, there are control commands that allow you access to the more advanced features of some equipment.
For Pelco P protocol the extended command set will have bit 0 of data byte 2 set and will follow the format in the following table:

Command
Data byte 1
Data byte 2
Data byte 3
Data byte 4
Set Preset XX
00
03
00
01 to FF
Clear Preset XX
00
05
00
01 to FF
Go To Preset XX
00
07
00
01 to FF
Flip (rotate 180º)
00
07
00
21
Zero Pan Position
00
07
00
22
Auto scan
00
09
00
00
Stop auto scan
00
0B
00
00
Remote Reset
00
0F
00
00
Zone Start
00
11
00
01 to 08
Zone End
00
13
00
01 to 08
Write char to screen
00
15
0 to 28
0 to 7F
Clear Screen
00
17
00
00
Alarm Ack
00
19
00
01 to 08
Zone Scan On
00
1B
00
00
Zone Scan Off
00
1D
00
00
Pattern Start
00
1F
00
00
Pattern Stop
00
21
00
00
Run Pattern
00
23
00
00
Zoom Lens Speed
00
25
00
00 to 03
Focus Lens Speed
00
27
00
00 to 03

In Pelco D implementation they are as following:

Command
Word 3
Word 4
Word 5
Word 6
Set Preset
00
03
00
01 to 20
Clear Preset
00
05
00
01 to 20
Go To Preset
00
07
00
01 to 20
Flip (180° about)
00
07
00
21
Go To Zero Pan
00
07
00
22
Set Auxiliary
00
09
00
01 to 08
Clear Auxiliary
00
0B
00
01 to 08
Remote Reset
00
0F
00
00
Set Zone Start
00
11
00
01 to 08
Set Zone End
00
13
00
01 to 08
Write Char. To Screen
00
15
X Position 00 to 28
ASCII Value
Clear Screen
00
17
00
00
Alarm Acknowledge
00
19
00
Alarm No.
Zone Scan On
00
1B
00
00
Zone Scan Off
00
1D
00
00
Set Pattern Start
00
1F
00
00
Set Pattern Stop
00
21
00
00
Run Pattern
00
23
00
00
Set Zoom Speed
00
25
00
00 to 03
Set Focus Speed
00
27
00
00 to 03

Please note that in Pelco P implementaiton the checksum is calculation by XOR binary sum of bytes 1-7, but in D one is by madulo 256 sum of bytes 1-6
0A        00001010
88        10001000
Subtotal  10010010  92
90        10010000
Subtotal  00100010  22   (modulo 256 allows the high bit to roll off)
00        00000000
Subtotal  00100010  22
40        01000000
01100010  62  
Final check sum value


The response of devices not really important, however just to know that in Pelco P the response will be ACK command, when in Pelco D the response to one of these commands is four bytes long. The first byte is the synchronization character (FF), the second byte is the receiver address, the third byte contains the alarm information and the fourth byte is the check sum.

沒有留言:

張貼留言

我的網誌清單