bitfocus / companion-module-sony-visca

MIT License
16 stars 19 forks source link

Tally reading #67

Open coredumped69 opened 7 months ago

coredumped69 commented 7 months ago

Hello,

First: Congratulations for you excellent work.

Second: It is possible to read the tally from a Sony ILME-FR7 PTZ Camera to change the Stream Deck keys colour when the camera is on the air?

With a python code I can read this status:

Inquiry packet: 8x 09 7E 01 0A FF Reply packet: y0 50 0p FF Comments: p: 2=On, 3=Off

Thank you very much.

goseid commented 7 months ago

That should be possible. The companion project just added some functionality that should help with getting data from multiple cameras. I've been waiting on this before implementing feedbacks. If tests go as expected, we'll be moving ahead with this and getting much more data back from the cameras.

coredumped69 commented 7 months ago

If we can help you in any way, you can count on us to do all the necessary tests.

Thank you very much.

goseid commented 7 months ago

@coredumped69 can you take a look at #68 and see if your experience is the same or if you can shed any light on the issue? Thanks.

coredumped69 commented 7 months ago

@goseid Finally I adapted this python code to ask the tally status at the cameras and publish it using MQTT to Companion.

Regards.

#!/usr/bin/env python
import socket
import os
import time
import binascii # for printing the messages we send, not really necessary
from time import sleep

camera_ip = '192.168.144.152'
camera_port = 52381
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # IPv4, UDP
# for receiving
buffer_size = 1024
s.bind(('', camera_port)) # use the port one higher than the camera's port

# Payloads
received_message = '' # a place to store the OSC messages we'll receive
sequence_number = 1 # a global variable that we'll iterate each command, remember 0x0001
reset_sequence_number = '02 00 00 01 00 00 00 01 01'

TallyStatus = '80 09 7E 01 0A FF'

def send_message(message_string):
    global sequence_number
    payload_type = bytearray.fromhex('01 00')
    payload = bytearray.fromhex(message_string)
    payload_length = len(payload).to_bytes(2, 'big')
    message = payload_type + payload_length + sequence_number.to_bytes(4, 'big') + payload
    sequence_number += 1
    s.sendto(message, (camera_ip, camera_port))

    try:
        data = s.recvfrom(buffer_size)
        received_message = binascii.hexlify(data[0])
        #print('Estat Tally: ', received_message[21:22])
        if received_message[21:22] == b'3':
            print ('Tally CAM2 Off')
            os.system("mosquitto_pub -h localhost -t cam2 -m 0")

        if received_message[21:22] == b'2':
            print ('Tally CAM2 On')
            os.system("mosquitto_pub -h localhost -t cam2 -m 1")

    except socket.timeout: # s.settimeout(2.0) #above
        received_message = 'No response from camera'
      #  print(received_message)

def reset_sequence_number_function():
    global sequence_number
    reset_sequence_number_message = bytearray.fromhex('02 00 00 01 00 00 00 01 01')
    s.sendto(reset_sequence_number_message,(camera_ip, camera_port))
    sequence_number = 1
    return sequence_number

# start by resetting the sequence number
reset_sequence_number_function()

while True:
    time.sleep(0.1)
    send_message(TallyStatus)

goseid commented 7 months ago

Until recently it would have caused more problems implementing it than waiting. Many folks that use the Sony-VISCA module use more than one camera. The way Sony has implemented their protocol all the cameras send their responses to the first instance of the companion module so in multiple camera configurations the first camera would get the wrong data much of the time and the rest would get no data.

That's in the past now though and I just have to finish implementing the feedback section. I'll definitely point you at the module when it's ready for testing. I'm on a show now through Saturday though so unless I get some unexpected down time you probably won't see any progress until next week.

Sorry for the delays, I wish I had completed code for my show this week too.