Read the outgoing serial data to an IR camera

Hi,

I have an infrared (IR) camera which can be operated serially. It comes with a GUI which provides various buttons to zoom in, zoom out, control brightness and contrast, display overlay etc. The protocol consists of a total 77 bytes, out of which I am concerned only with a few bits regarding zoom in and zoom out.

My question is if there is any way I can read the data that is sent on the serial port (connected to the IR camera) whenever I press a particular button (e.g. zoom in) on that GUI? I need to see that data because I need to control that camera without using that GUI (for example using MATLAB or arduino). I tried using hyper terminal but I guess only one software can connect to the COM port at one time, either hyper terminal or that GUI.

Sorry if the question is too trivial.

Thanks.

Hey!

I'm no expert(not even close :slight_smile: ), but i think you can use processing to check serial data being exchanged between the GUI and Camera.to achieve that you have to use a serial monitor to see the serial data being exchanged and and then use the same serial data to manipulate your camera.

Btw i don't think you need sophisticated software....

gd luck!

You need to give us details of how the camera is connected to your PC.

If the camera appears to the PC as a serial device it should be possible to write a program in (say) Python to recieve the data and display it.

I presume, at this stage, you are just trying to figure out the data so you can later program an Arduino to send it ?

...R

Robin2:
You need to give us details of how the camera is connected to your PC.

If the camera appears to the PC as a serial device it should be possible to write a program in (say) Python to recieve the data and display it.

I presume, at this stage, you are just trying to figure out the data so you can later program an Arduino to send it ?

...R

As I mentioned in my post, the camera can be controlled via a serial port. I don't have a serial port in my laptop, so I am using a serial-to-USB converter (picture attached).

And to answer your question, yes, I want to read the serial port at the moment when the GUI sends the commands to the camera over the serial port so that I can send that same data using MATLAB or arduino.

serial.PNG

hydr:
I want to read the serial port at the moment when the GUI sends the commands to the camera over the serial port

I misunderstood. I thought you wanted to intercept data coming into the PC.

I think you could do what you want if you connect an Arduino to the serial port in place of the camera and use the Arduino to receive the data and display it on the Serial Monitor. However if there is a "conversation" between the camera and the PC that would not work.

If you have a Mega you could perhaps hack into the Tx and RX lines between the camera and the PC. Connect one of them to Rx on (say) Serial1 and the other to Rx on Serial2. That would allow the Mega to capture both sides of the conversation.

...R

Robin2:
I think you could do what you want if you connect an Arduino to the serial port in place of the camera and use the Arduino to receive the data and display it on the Serial Monitor. However if there is a "conversation" between the camera and the PC that would not work.

...R

I tried this. My Arduino UNO is showing on COM15 in the device manager. So I configured my GUI to send data on the same port i.e. COM15. But when I try to open the Arduino's serial monitor to "see" the data, it gives me an error saying that "Serial port COM15 already in use. Try quitting any programs that may be using it."

I had this same problem with the hyper terminal i.e. two softwares cannot connect to the same port at the same time. It can be either Arduino or that GUI. Is there any way around this?

I had this same problem with the hyper terminal i.e. two softwares cannot connect to the same port at the same time. It can be either Arduino or that GUI. Is there any way around this?

The easiest thing to do would be to use a port monitoring program on the pc to show what is being sent. You might have the serial monitor and arduino do the monitoring, but the usb to serial adaprers use the inverted rs232 type protocol which would need to be converted to TTL. Probably not hard to do.

hydr:
I tried this. My Arduino UNO is showing on COM15 in the device manager. So I configured my GUI to send data on the same port i.e. COM15.

What I was trying to suggest is nothing like that.

You need to have the camera's USB connection connected to the PC but do not connect the camera to its serial device. Then connect the Arduino to the serial device using a second serial connection (SoftwareSerial if you have an Uno) and also connect your Arduino's USB to the PC as normal. Hope this diagram helps

Normal system (if I understand correctly)

PC ---- USB-Serial ----- Camera

Data capture system

PC -------USB-Serial ------ Uno SoftwareSerial
| |
--------------------Arduino USB -------

...R

Robin2:
What I was trying to suggest is nothing like that.

You need to have the camera's USB connection connected to the PC but do not connect the camera to its serial device. Then connect the Arduino to the serial device using a second serial connection (SoftwareSerial if you have an Uno) and also connect your Arduino's USB to the PC as normal. Hope this diagram helps

Normal system (if I understand correctly)

PC ---- USB-Serial ----- Camera

Data capture system

PC -------USB-Serial ------ Uno SoftwareSerial
| |
--------------------Arduino USB -------

...R

I am afraid I don't quite understand you as I am fairly new to all this. Can you please elaborate a little on the connections?

When I connect both the Arduino and camera (using USB-to-Serial converter), they appear in the device manager as shown in the picture attached. Arduino on COM15 and camera on COM27.

Now on which port should I configure my camera GUI to connect out of these two?

Will the actual HardwareSerial of Arduino be reading the data sent by the GUI or the SoftwareSerial?

Also, can you please explain a little bit on the hardware connections that I would need to make on the Arduino board for SoftwareSerial or AltSoftSerial?

Thanks!

comm ports.PNG

hydr:
When I connect both the Arduino and camera (using USB-to-Serial converter), they appear in the device manager as shown in the picture attached. Arduino on COM15 and camera on COM27.

Now on which port should I configure my camera GUI to connect out of these two?

The GUI will connect to COM27 (thinking it is connected to the camera) and the Arduino Serial Monitor will connect to COM15

Will the actual HardwareSerial of Arduino be reading the data sent by the GUI or the SoftwareSerial?

HardwareSerial will be sending to the Serial Monitor whatever the Arduino receives from the USB-Serial connector via SoftwareSerial. (Assuming that is what your Arduino program is designed to do)

Also, can you please explain a little bit on the hardware connections that I would need to make on the Arduino board for SoftwareSerial or AltSoftSerial?

With SoftwareSerial you define two pins to be Rx and Tx. Connect Rx on the USB-Serial to the pin you designate as Tx and Tx to Rx. Also connect GND from the USB-Serial to GND on the Arduino.
[/quote]

...R

Robin2:
The GUI will connect to COM27 (thinking it is connected to the camera) and the Arduino Serial Monitor will connect to COM15
HardwareSerial will be sending to the Serial Monitor whatever the Arduino receives from the USB-Serial connector via SoftwareSerial. (Assuming that is what your Arduino program is designed to do)
With SoftwareSerial you define two pins to be Rx and Tx. Connect Rx on the USB-Serial to the pin you designate as Tx and Tx to Rx. Also connect GND from the USB-Serial to GND on the Arduino.

...R

Thank you very much for your help.

Robin2:
The GUI will connect to COM27 (thinking it is connected to the camera) and the Arduino Serial Monitor will connect to COM15
HardwareSerial will be sending to the Serial Monitor whatever the Arduino receives from the USB-Serial connector via SoftwareSerial. (Assuming that is what your Arduino program is designed to do)
With SoftwareSerial you define two pins to be Rx and Tx. Connect Rx on the USB-Serial to the pin you designate as Tx and Tx to Rx. Also connect GND from the USB-Serial to GND on the Arduino.

...R

@Robin2, I was successfully able to "see" the data being sent by the camera's GUI to the serial port using a virtual serial port monitor (com0com) and it is coming out to be as expected. The camera is working properly using the GUI (i.e. it zooms in when I press the zoom in button on the GUI and zooms out when zoom out button on GUI is pressed). As you can see in the GUI screenshot attached that the camera's serial protocol comprises of 77 bytes. You can also see buttons for zoom in, zoom out, calibration and a bunch of other buttons. As I have mentioned earlier, my concern is mainly with the zoom in and zoom out operations. The bits responsible for zoom in and zoom out are bit numbers 4 and 3 of 47th byte (bit value 1 for action and 0 for no action). It means that when none of the zoom in or zoom out button is pressed, that byte shows hex value of 0X01, when zoom in i.e. near focus button is pressed, that byte shows value of 0X11 and value 0X09 for zoom out i.e. far focus.

I have logged a sample of GUI's data (by pressing zoom in and zoom out buttons for some time alternatively) in a text file using mikroC PRO's USART terminal. The logged file (in hex format) is attached herewith. You can see 47th byte's value changing confirming the pressing of GUI's zoom in and zoom out buttons. Now when I send the exact same logged file to the camera using HyperTerminal or miroC PRO, it doesn't respond at all.

Simply put, camera responds to GUI's serial data but does not respond to the exactly same data (obtained via logging) sent via HyperTerminal or mikroC etc. What may be the reason?

I have tried to explain the problem but if there is any confusion, please do ask.

Thanks!

logfile.txt (11.5 KB)

hydr:
@Robin2, I was successfully able to "see" the data being sent by the camera's GUI to the serial port using a virtual serial port monitor
....SNIP.....
Now when I send the exact same logged file to the camera using HyperTerminal or miroC PRO, it doesn't respond at all.

You will appreciate that I cannot repeat your tests so I must go on what you say plus some guesswork.

As you have not said that you were monitoring data in both directions my guess is that there must be a 2-way conversation between the camera and the GUI. When you send the text file it is only a 1-way conversation.

I did mention this in Reply #4

Is there any reason why the first message in your log file is a different length ?

If this was my project I would want to check for data flowing in both directions of the sort "When you send me X I will reply with Y"

For example, maybe the GUI only sends all that data when requested.

...R

Robin2:
As you have not said that you were monitoring data in both directions my guess is that there must be a 2-way conversation between the camera and the GUI. When you send the text file it is only a 1-way conversation.

Yes you are right. I have only captured what the GUI is sending and not what the camera responds (if it does). I will try to capture that side of the conversation as well.

Robin2:
Is there any reason why the first message in your log file is a different length ?

That is because the 76th byte at the end of the first line is carriage return (hence the value 0x0D) and the next byte is reserved for line feed (having the value of 0X0A) which inserts a new line and the last byte of the first message i.e. 77th byte (which is the first one in the second line) is the checksum obtained by XORing all the previous 76 bytes. So first message consists of first complete line along with the first byte of the second line. The second message starts from the second byte of the second line and so on. That is why there is a single byte in the last line (which is actually the last byte of the last message). I hope this answers your question.

Thanks for taking out the time to answer the queries.

Robin2:
my guess is that there must be a 2-way conversation between the camera and the GUI.

@Robin2, camera's serial connector comes with an attached RS232 converter as shown in the pictures attached. So, I don't need to use an external level converter (MAX232), right?

Also, to read what the camera is sending to the GUI/PC, which of the two pins (R+ and R-) do I need to DIRECTLY connect to the receiver pin of the aruino's serial?

Thanks.

I think that just converts RS232 into RS422 and I don't really know anything about RS422. No doubt Google does.

...R

Okay thanks.