首页 > 解决方案 > 通过 RS-422 串行端口控制摄像机

问题描述

我目前正在研究并编写一个简单的程序来通过串行端口控制相机,更具体地说是 RS-422。我从制造商那里得到了相机控制协议文档。我已经阅读和测试了几天,但不幸的是,我还没有成功。我使用 Python (3.7) 来加快测试速度。下面是我的示例代码:

import serial

ser_port = serial.Serial(
    port='COM4',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
    )

sccp_cmd_null = [0x00]
sccp_cmd = [0xE7, 0x40, 0x11, 0x43, 0x00, 0x00]  # Chroma Key "GREEN"

if ser_port.isOpen():
    # Try sending a break code first
    try:
        print("Sending Break Code: ", serial.to_bytes(sccp_cmd_null))
        ser_port.write(serial.to_bytes(sccp_cmd_null))
    except:
        print("Failed Sending Break Code!")


    # Try Sending The Commands
    try:
        print("Sending Commands: ", serial.to_bytes(sccp_cmd))
        ser_port.write(serial.to_bytes(sccp_cmd))
    except:
        print("Failed Sending Commands!")

ser_port.close()

请注意,这是我第一次编写处理串行端口的代码。

提前感谢那些可以提供帮助的人^_^

标签: python-3.xcameraserial-port

解决方案


推荐阅读