Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Requires Dell P4317Q monitor at firmware M2C104, tested with Python2.7
- # Special thanks to sredniv for inspiration to port my Bash scripts to Python
- # http://en.community.dell.com/support-forums/peripherals/f/3529/t/19995591
- # API reference guide
- # http://downloads.dell.com/manuals/all-products/esuprt_display_projector/esuprt_display/dell-p4317q-monitor_Reference%20Guide2_en-us.pdf
- # Examples
- # http://downloads.dell.com/manuals/all-products/esuprt_display_projector/esuprt_display/dell-p4317q-monitor_Reference%20Guide3_en-us.pdf
- # Thanks to the helpful folks at https://hardforum.com/threads/dell-43-ultra-hd-4k-multi-client-monitor-p4317q.1897889/
- # Send: [H0][H1][Len][R/W][Cmd][Data0]...[DataN][CHK]
- # turn off LED: 375103ea2100ae
- # turn on LED: 375103ea2101af
- # Checksum using SpeedCrunch: xor(0x37;0x51;0x03;0xea;0x21;01) = 0xAF
- # using console calc: 0x37@0x51@0x03@0xea@0x21@0x01
- # Receive: [H2][H3][Len][Reply][RC][Cmd][Data0]...[DataN][CHK]
- # GetPxPSubInput valid: 6f 37 07 02 00 71 10 00 00 00 64
- # GetPxPSubInput error: 6f 37 03 02 ff 71 8f
- import sys
- from binascii import b2a_hex
- from time import sleep
- import subprocess
- # 3rd party
- import serial
- CMD_HEADER = bytearray([0x37, 0x51])
- RSP_HEADER = bytearray([0x6F, 0x37])
- CMD_READ = 0xEB
- CMD_WRITE = 0xEA
- COM_PORT = "com1"
- CMD_LED_OFF = bytearray([0x37, 0x51, 0x03, 0xEA, 0x21, 0x00, 0xAE])
- CMD_LED_ON = bytearray([0x37, 0x51, 0x03, 0xEA, 0x21, 0x01, 0xAF])
- CMD_PBP_OFF = bytearray([0x37, 0x51, 0x03, 0xEA, 0x70, 0x00, 0xFF])
- CMD_PBP_QUAD = bytearray([0x37, 0x51, 0x03, 0xEA, 0x70, 0x08, 0xF7])
- CMD_AUTOSEL_OFF = bytearray([0x37, 0x51, 0x03, 0xEA, 0x60, 0x00, 0xEF])
- CMD_WARM_MODE = bytearray([0x37, 0x51, 0x06, 0xEA, 0x48, 0x00, 0x01, 0x00, 0x00, 0xC3])
- CMD_MDP_PRIMARY = bytearray([0x37, 0x51, 0x06, 0xEA, 0x62, 0x10, 0x00, 0x00, 0x00, 0xF8])
- CMD_DP_PRIMARY = bytearray([0x37, 0x51, 0x06, 0xEA, 0x62, 0x08, 0x00, 0x00, 0x00, 0xE0])
- CMD_HD2_PRIMARY = bytearray([0x37, 0x51, 0x06, 0xEA, 0x62, 0x02, 0x00, 0x00, 0x00, 0xEA])
- CMD_PBP_HD2_BR = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x00, 0x02, 0x00, 0x00, 0x00, 0xF8])
- CMD_PBP_MDP_BL = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x01, 0x10, 0x00, 0x00, 0x00, 0xEB])
- CMD_PBP_DP_BL = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x01, 0x08, 0x00, 0x00, 0x00, 0xF3])
- CMD_PBP_DP_TL = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x02, 0x08, 0x00, 0x00, 0x00, 0xF0])
- CMD_PBP_HD1_TL = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x02, 0x01, 0x00, 0x00, 0x00, 0xF9])
- CMD_PBP_HD1_TR = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x03, 0x01, 0x00, 0x00, 0x00, 0xF8])
- CMD_PBP_MDP_TR = bytearray([0x37, 0x51, 0x07, 0xEA, 0x71, 0x03, 0x10, 0x00, 0x00, 0x00, 0xE9])
- COMMANDS_WORKSTATION = [CMD_LED_OFF, CMD_AUTOSEL_OFF, CMD_PBP_OFF, CMD_DP_PRIMARY, CMD_WARM_MODE, CMD_LED_ON]
- COMMANDS_RYZEN = [CMD_LED_OFF, CMD_AUTOSEL_OFF, CMD_PBP_OFF, CMD_HD2_PRIMARY, CMD_WARM_MODE, CMD_LED_ON]
- COMMANDS_QUAD = [CMD_LED_OFF, CMD_AUTOSEL_OFF, CMD_PBP_QUAD, CMD_PBP_HD1_TL, CMD_PBP_MDP_TR, CMD_PBP_DP_BL, CMD_PBP_HD2_BR, CMD_WARM_MODE, CMD_LED_ON]
- def hex_format(message):
- hex = b2a_hex(message)
- return ':'.join(hex[i:i+2] for i in range(0, len(hex), 2))
- if __name__ == "__main__":
- if len(sys.argv) != 2 or sys.argv[1] not in ["QUAD", "WORK", "RYZEN"]:
- print("Usage: QUAD|4K")
- exit(1)
- ser_port = serial.Serial(COM_PORT)
- if (sys.argv[1] == "WORK"):
- commands = COMMANDS_WORKSTATION
- elif (sys.argv[1] == "RYZEN"):
- commands = COMMANDS_RYZEN
- elif (sys.argv[1] == "QUAD"):
- commands = COMMANDS_QUAD
- for cmd in commands:
- ser_port.write(cmd)
- resp_header = ser_port.read(2)
- if ord(resp_header[0]) != RSP_HEADER[0] or ord(resp_header[1]) != RSP_HEADER[1]:
- print("ERROR: Response is corrupt, aborting")
- exit(1)
- resp_len = ord(ser_port.read(1))
- ord(ser_port.read(1)) # always 02 (reply)
- resp_code = ord(ser_port.read(1))
- if resp_code != 0:
- print("Response error: %d" % resp_code)
- # resp_len excludes checksum and we already read reply / code (-2)
- response = ser_port.read(resp_len - 2)
- checksum = ser_port.read(1)
- print("Response data: %s, checksum: %s" % (hex_format(response), hex_format(checksum)))
- sleep(1)
- # give time for display to settle
- sleep(2)
- # set appropriate resolution
- if (sys.argv[1] == "WORK"):
- # note the escaped backslashes
- # before SLS setup
- # subprocess.call("dc64cmd.exe -monitor=\\\\.\\DISPLAY2 -detach")
- pass
- # SLS does not allow resolution 4k
- # subprocess.call("dc64cmd.exe -monitor=\\\\.\\DISPLAY1 -width=3840 -height=2160 -refresh=max -depth=max -primary")
- elif (sys.argv[1] == "RYZEN"):
- pass
- #subprocess.call("PsExec64 \\\\ryzen -u user -p \"\" -n 5 -c -f -accepteula -nobanner C:\\Users\\user\\Documents\\scripts\\dc64cmd.exe -monitor=\\\\.\\DISPLAY1 -width=3840 -height=2160 -refresh=max -depth=max -primary")
- elif (sys.argv[1] == "QUAD"):
- # before SLS setup
- #subprocess.call("dc64cmd.exe -monitor=\\\\.\\DISPLAY1 -width=1920 -height=1080 -refresh=max -depth=max -primary -more")
- #subprocess.call("dc64cmd.exe -monitor=\\\\.\\DISPLAY2 -width=1920 -height=1080 -refresh=max -depth=max -seconday -above -apply")
- subprocess.call("dc64cmd.exe -monitor=\\\\.\\DISPLAY1 -width=1920 -height=2160 -refresh=max -depth=max -primary")
- #subprocess.call("PsExec64 \\\\ryzen -u user -p \"\" -n 5 -c -f -accepteula -nobanner C:\\Users\\user\\Documents\\scripts\\dc64cmd.exe -monitor=\\\\.\\DISPLAY1 -width=1920 -height=1080 -refresh=max -depth=max -primary")
- ser_port.close()
- sleep(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement