Evgenii Legotckoi
April 12, 2016, 5:26 p.m.

PTZ-camera control. Protocol Pelco-P

In the previous article I was considered an option to work with Pelco-D protocol, and now look to work with Pelco-P protocol - a modified variation of the previous PTZ-camera control protocol, which is also developed by the same name by Pelco. Also used over the RS482 / 485 interface for communicating with cameras equipped with servo drives.

Pelco-P protocol also has a set of standard commands, as well as advanced instruction set. Let us consider how we can work with standard commands. Protocol Pelco-P 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.

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

The checksum is the sum for the exclusive OR, ie XOR, byte from the 1 st to 7 th. As you can see in this protocol using 8 bytes to transmit the message, instead of 7, as in Pelco-D.

It should be noted that the protocol Pelco-P addressing starts with 1 and 0. That is, the first address will be transmitted as #00, but the most interesting is that the PTZ camera settings, the address will be listed as 01, it is necessary to consider this point when developing layer for a given protocol.

PAN and TILT commands

Examples of commands

Rotation to left: A0 00 00 04 20 00 AF 2B
Rotation to right: A0 00 00 02 20 00 AF 2D
Tilt up: A0 00 00 08 00 20 AF 27
Tilt down: A0 00 00 10 00 20 AF 3F
Stop all activities: A0 00 00 00 00 00 AF 0F

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, data1, data2, data3, data4, checkSum;
  5. address = data1 = data2 = data3 = data4 = checkSum = 0x00;
  6.  
  7. dataPelco = (unsigned char*) malloc(8);
  8. memset(dataPelco,0,8);
  9.  
  10. address = (unsigned char)addressPTZ;
  11. --address;
  12. if(pan < 0) {
  13. data2 |= 0x04;
  14. pan *= (-1);
  15. } else if(pan > 0) {
  16. data2 |= 0x02;
  17. }
  18. data3 = pan*63/100;
  19.  
  20. if(tilt < 0) {
  21. data2 |= 0x10;
  22. tilt *= (-1);
  23. } else if(tilt > 0) {
  24. data2 |= 0x08;
  25. }
  26. data4 = tilt*63/100;
  27.  
  28. if(zoom < 0) {
  29. data2 |= 0x40;
  30. } else if(zoom > 0) {
  31. data2 |= 0x20;
  32. }
  33.  
  34. checkSum ^= 0xA0;
  35. checkSum ^= address;
  36. checkSum ^= data1;
  37. checkSum ^= data2;
  38. checkSum ^= data3;
  39. checkSum ^= data4;
  40. checkSum ^= 0xAF;
  41.  
  42. dataPelco[0] = 0xA0;
  43. dataPelco[1] = address;
  44. dataPelco[2] = data1;
  45. dataPelco[3] = data2;
  46. dataPelco[4] = data3;
  47. dataPelco[5] = data4;
  48. dataPelco[6] = 0xAF;
  49. dataPelco[7] = checkSum;
  50.  
  51. sdk_write_pelco_cmd(8, dataPelco); // 8 - length of message
  52. free(dataPelco);
  53. }

Recommended articles on this topic

By article asked1question(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