dump hex input from software serial to serial console

Hi, i have an ipcamera i am trying to decode the serial communication between ptz module and camera module. The data is being sent in hex format between the modules. I want to use software serial to receive data input from camera and display it to serial console on pc in original format. How can i do this?

Are you sure that the interface between the PTZ module and the camera is Serial ? Where did you find this detail ?

How are the two connected together physically and what voltage levels are used ?

A link to the devices would help

UKHeliBob:
Are you sure that the interface between the PTZ module and the camera is Serial ? Where did you find this detail ?

How are the two connected together physically and what voltage levels are used ?

A link to the devices would help

UKHeliBob:
Are you sure that the interface between the PTZ module and the camera is Serial ? Where did you find this detail ?

How are the two connected together physically and what voltage levels are used ?

A link to the devices would help

well im not 100% sure that its serial. it is simply using rx/tx/gnd. i am assuming the data is in HEX format. im not sure that it is the standard ptz protocol there is no documentation to read. the camera has some bug with autofocusing 24,000 times a day and i want to try and learn about the messages being sent between the modules.
the voltage is 3.3v
for my test code i was trying to mirror the data assuming its in hex format. i was trying to get the first 8 bytes and print them on their own lines.
Im pretty new at decoding things like this. i would like to try to start in the right direction though.

#include <SoftwareSerial.h>
SoftwareSerial s(D6, D5);
int counter = 0;
void setup() {
  s.begin(9600);
  Serial.begin(9600);
}

void loop() {

  if (s.available()) {     

    Serial.print(s.read(), HEX); 
    counter++;
    if (counter >= 7 ) {
      Serial.println();
      counter = 0;
    }
  }

}

im not even 100% sure the baud rate. i do however have an oscilloscope but again not sure what to do with it in this case

Try my code at reply #3

Can you share more info about your IPCamera (brand, model,...)?
IP in the name tend to hint at TCP-IP/Ethernet type of communication. Or is it an USB type of webcam?

J-M-L:
Can you share more info about your IPCamera (brand, model,...)?
IP in the name tend to hint at TCP-IP/Ethernet type of communication. Or is it an USB type of webcam?

J-M-L:
Can you share more info about your IPCamera (brand, model,...)?
IP in the name tend to hint at TCP-IP/Ethernet type of communication. Or is it an USB type of webcam?

yea its a anjvison ptz 4818 8mp ip camera poe.
their website is anjvision.com the camera module is mc800n2
the manufacture told me they dont make the 18x ptz board they only make 4x and that a third party make the ptz board and customized firmware. they may be full of it but i dont know. i know the ptz board runs a stm8 processor with no lock bytes. i dumped the chip but dont know what to do with the firmware.
i was wonder though, what is the data being sent between the modules. this camera only has a problem at night. i figured worst case scenario i could intercept this comm with an arduino and make it behave differently as a sort of "band aid"
the manufacture gave me 3 custom firmwares and concluded its not their fault it dont work.

I also have their tool to enabled a hidden console and dump the slog. it has some information about what going on but it dont seem like alot. and without some kind of documentation its all guess work for a noob that dont even really know what hes doing lol

With no documentation it’s definitely a shot in the dark...a salae type of logic analyzer could help assess what you see on the supposed serial comm link.

there is a possibility that it is pelco d protocol. according my oscilloscope there are a lot of the same message being sent from camera module to stm8 ptz module. if i issue a ptz command then the message sent from camera module to the ptz board changes. If i were to assume the messages are hex, whats the best way to display the captured data to the serial console so i can look for patterns/cmds . i want to assure i at least am at least displaying the hex in the console correctly.
this is what im looking at now. but as i figure out baud rate i want to know the data im looking at is not just garabled data

64
FC
FE
FE
FF
4
FF
FF
24
E4
FF
F8
FE
48
FC
8
F8
FC
FF
FC
FC
FE
10
C1
F8
FF
FF
FC
FE
FE
F0
FC
FE
FF
F8
FE
FC
FF
FE
FC
F0

Your code to print hex is ok.

J-M-L:
Your code to print hex is ok.

i notice a lot of " 8 F8 FC " patterns in the messages. . how could i move forward. i would like to maybe send a command with arduino if i can possibly decode one. Im going to try to communicate with the ptz module.

How do i format my message to be sent to the ptz module. I would like to send '8 F8 FC' but how do i present it to the ptz module correctly with arduino?

notsolowki:
I would like to send ‘8 F8 FC’ but how do i present it to the ptz module correctly with arduino?

assuming the Serial connection is setup the right way, sending binary is just a matter of using ‘write()’ either with a buffer and the number of bytes in the buffer, or one by one (it’s a Serial protocol so it’s similar)

something like this (typed here based on your previous code, mind typos)

#include <SoftwareSerial.h>
SoftwareSerial camera(D6, D5);

const uint8_t command[] = {0x08, 0xF8, 0xFC};

void displayIncomingBytes()
{
  static uint8_t n = 0;
  if (camera.available()) {
    uint8_t received = camera.read();
    if (received < 0x10) Serial.write('0');
    Serial.print(received, HEX);
    if (++n >= 7 ) {
      Serial.println();
      n = 0;
    } else Serial.write(' ');
  }
}


void setup() {
  Serial.begin(115200); // no need to go slow with the communication to the Mac/PC
  camera.begin(9600);   // the camera seems to be configured as a serial comm. 8N1 at 9600 bauds

  // send a command to the camera through the Serial link
  camera.write(command, sizeof command);
  // *** you could also do instead ***
  // camera.write(0x08);
  // camera.write(0xF8);
  // camera.write(0xFC);
  // **********************************
}

void loop() {
  displayIncomingBytes();
}

I just improved a bit you HEX printing, adding a ‘0’ in front of numbers not fitting on 2 characters

EDIT: Note that I changed the speed of the Serial console on the PC to 115200. You’ll have to adjust the Serial monitor settings (pop up at the bottom right) to see data getting printed

Note that it is important to know whether you want/need to send 0xF8, ie binary data or "F8", ie ASCII data

@UKHeliBob - good point (I had assumed a binary protocol since what OP gets is outside ASCII range)

i Asked the manufacture if they have any documentation of the ptz protocol. they must because this is an third party component controlling the stepper motors so maybe they will provide me with more. if not idk what to do. there seems to be a lot more than ptz cmds being transmitted because the protocol is very busy. i think there is some kind of focal data being relayed between the modules. it does not only rely on a calibrated position. what a piece of crap this camera is with this ptz module. stay away from 8mp ptz 18x zoom no name camera lol

good luck!

I'm just about to start mucking about with a Floureon DVR that has an RS485 output and have been scouring the web for any information on what protocols may exist. This link describes the Pelco protocol so it may help you out.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.