Evgenii Legotckoi
April 7, 2016, 10:07 p.m.

PTZ-camera control. Pelco-D protocol

Pelco-D - is a PTZ-camera control protocol developed by the same name by Pelco. As a rule, used over RS482/485 interface for communicating with cameras equipped with servo drives.

Pelco-D protocol has in the arsenal of a set of standard commands, as well as advanced instruction set. This article will look at how to work with a standard set of commands. Protocol Pelco-D Let us examine the example of the abstract and the abstract command source SDK, which receives the message for onward transmission to its RS485 interface. This reservation was made deliberately, because it is such a challenge recently stood in front of me.

Therefore there is a protocol by which data is transmitted, and further understand the data transmitted to the SDK, which sends a message already in the RS485 transmission path. Below is a picture in which there is a yellow square. It is in this function and will form the necessary us the message you want to convey in the SDK.


Message Structure

Post Pelco-D protocol consists of 7 bytes. Let us analyze the value of each byte:

  1. Byte synchronization - always has #FF value in hexadecimal;
  2. Address - address byte PTZ-camera or any other device on the RS485 / 482 line;
  3. Command 1 - the first byte standard commands Pelco-D;
  4. Command 2 - the second byte standard commands Pelco-D;
  5. Data 1 - byte rotation speed camera left / right, is from #00 to #3F;
  6. Data 2 - speed bytes tilt the camera up / down, is from #00 to #3F;
  7. Checksum - is an 8-bit bytes by the sum of the 2nd to 6th.

Standard set of commands

To send the message must be necessary to form two teams messages. If the data will not be passed on, then it will be necessary to set the zero value bit responsible for this or that functionality.

Consider the structure of commands.

Sense bit charge is meaning of bits 3 and 4. When the bit is lifted, the set bits 3 and 4 have the camera and the auto scan switch, respectively, otherwise raised by bits 3 and 4 have the shutdown. Bits 5 and 6 are reserved and should be set to 0. Other settings are responsible for the diaphragm (Iris), Focus (Focus), Zoom (Zoom), Tilt (Tilt), Rotate (PAN). To enable these parameters should be set to activate the corresponding bits in the unit.

Examples of commands

Rotation to left: FF 01 00 04 00 00 05
Rotation to right: FF 01 00 02 00 00 03
Tilt up: FF 01 00 08 00 00 09
Tilt down: FF 01 00 10 00 00 11
Zoom +: FF 01 00 20 00 00 21
Zoom -: FF 01 00 40 00 00 41

Sample code

In this abstract code was created in a vacuum, such a situation that the function of these values fall:

  • address;
  • PanSpeed - rotation speed with the direction, from - 100 to +100;
  • TiltSpeed - Tilt speed with the direction, from -100 to +100;
  • ZoomSpeed - Zoom speed with direction, from -100 to +100. Why so submitted data for Zuma - is a question for me, given that Pelco is no speed setting, but that is what it is.

But SDK has already formed a team takes a pointer to an array of data, and an indication of the length of the array. The result is the following code.

  1. void ptzCmd(int addressPTZ, int panSpeed, int tiltSpeed, int zoomSpeed)
  2. {
  3. unsigned char *dataPelco;
  4. unsigned char address, command1, command2, data1, data2, checkSum;
  5. address = command1 = command2 = data1 = data2 = checkSum = 0x00;
  6.  
  7. dataPelco = (unsigned char*) malloc(7);
  8. memset(dataPelco,0,7);
  9.  
  10. address = (unsigned char)addressPTZ;
  11. if(panSpeed < 0) {
  12. command2 |= 0x04;
  13. panSpeed *= (-1);
  14. } else if(panSpeed > 0) {
  15. command2 |= 0x02;
  16. }
  17. data1 = (unsigned char)panSpeed*63/100;
  18.  
  19. if(tiltSpeed < 0) {
  20. command2 |= 0x10;
  21. tiltSpeed *= (-1);
  22. } else if(tiltSpeed > 0) {
  23. command2 |= 0x08;
  24. }
  25. data2 = (unsigned char)tiltSpeed*63/100;
  26.  
  27. if(zoomSpeed < 0) {
  28. command2 |= 0x40;
  29. } else if(zoomSpeed > 0) {
  30. command2 |= 0x20;
  31. }
  32. checkSum = address + command1 + command2 + data1 + data2;
  33. checkSum %= 100;
  34.  
  35. dataPelco[0] = 0xFF;
  36. dataPelco[1] = address;
  37. dataPelco[2] = command1;
  38. dataPelco[3] = command2;
  39. dataPelco[4] = data1;
  40. dataPelco[5] = data2;
  41. dataPelco[6] = checkSum;
  42.  
  43. sdk_write_pelco_cmd(7, dataPelco); // 7 - это длина сообщения
  44. free(dataPelco);
  45. }

Recommended articles on this topic

By article asked0question(s)

0

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html