如何确定是否从Linux命令行打开LCD监视器

Cer*_*rin 21 linux shell command-line

如何判断计算机的显示器是否在Linux中从命令行打开/关闭?我传统上认为监视器只是输出设备,但我注意到Gnome Monitor Preferences对话框有一个"detect monitor"功能.是否可以推广以确定显示器是否已实际关闭?

Joe*_*erg 14

VESA DDC连接是一个I2C连接,可用于查询监视器的存在.

Linux暴露了I2C设备,用户程序可以直接与监视器通信,代码如http://jaffar.cs.msu.su/oleg/ddcci/

请注意以下内容: Control 0xe1: +/1/1 [SAM: Power control (0 - off/1 - on)]

# ddcci-tool /dev/i2c-2 -e -c -d


ddcci-tool version 0.03

Reading EDID : 0x50@/dev/i2c-2
    Plug and Play ID: SAM00BA
    Input type: Analog

Using ddc/ci : 0x37@/dev/i2c-2

Capabilities:
(type(LCD)vcp(04 05 10 12 60(1 3) B0(1 2) B6 C6 C8 C9 D6(1 4) DC(1 2 3 4) DF))

Controls (valid/current/max):
Control 0x04: +/0/1 [Reset Factory Defaults]
Control 0x05: +/0/1 [SAM: Reset Brightness and Contrast]
Control 0x06: +/0/1 [Reset Factory Geometry]
Control 0x08: +/0/1 [Reset Factory Default Color]
Control 0x0e: +/60/120 [SAM: Image Lock Coarse]
Control 0x10: +/0/100 [Brightness]
Control 0x12: +/50/100 [Contrast]
Control 0x16: +/8/16 [Red Video Gain]
Control 0x18: +/8/16 [Green Video Gain]
Control 0x1a: +/8/16 [Blue Video Gain]
Control 0x1e: +/0/2 [SAM: Auto Size Center]
Control 0x20: +/50/100 [Horizontal Position]
Control 0x30: +/25/54 [Vertical Position]
Control 0x3e: +/39/50 [SAM: Image Lock Fine]
Control 0x60: +/1/3 [Input Source Select]
Control 0x62: +/0/100 [Audio Speaker Volume Adjust]
Control 0x6c: +/140/255 [Red Video Black Level]
Control 0x6e: +/127/255 [Green Video Black Level]
Control 0x70: +/121/255 [Blue Video Black Level]
Control 0xb0: +/0/2 [Settings]
Control 0xb6: +/3/8 [???]
Control 0xc6: +/1/1 [???]
Control 0xc8: +/5/16 [???]
Control 0xc9: +/1/0 [???]
Control 0xca: +/2/2 [On Screen Display]
Control 0xcc: +/2/11 [SAM: On Screen Display Language]
Control 0xd6: +/1/4 [SAM: DPMS control (1 - on/4 - stby)]
Control 0xdc: +/4/4 [SAM: MagicBright (1 - text/2 - internet/3 - entertain/4 - custom)]
Control 0xdf: +/512/0 [VCP Version]
Control 0xe0: +/0/2 [SAM: Color preset (0 - normal/1 - warm/2 - cool)]
Control 0xe1: +/1/1 [SAM: Power control (0 - off/1 - on)]
Control 0xe2: +/0/1 [???]
Control 0xed: +/108/255 [SAM: Red Video Black Level]
Control 0xee: +/101/255 [SAM: Green Video Black Level]
Control 0xef: +/103/255 [SAM: Blue Video Black Level]
Run Code Online (Sandbox Code Playgroud)

一个有趣的问题是您的监视器是否返回该数据,如果不是,它是否会响应,如果它当前已关闭.

  • 确实如此.甚至可以从命令行打开和关闭显示器. (2认同)
  • ddcci现在是ddccontrol:http://sourceforge.net/projects/ddccontrol/正如Eren所说的那样,你甚至可以用`ddccontrol -r 0xe1 -w 0来自己做 (2认同)

0x9*_*x90 11

systembash.com,这里是从链接中获取的代码,以防有一天它将关闭:

#!/bin/bash
export DISPLAY=:0.0

if [ $# -eq 0 ]; then
  echo usage: $(basename $0) "on|off|status"
  exit 1
fi

if [ $1 = "off" ]; then
  echo -en "Turning monitor off..."
  xset dpms force off
  echo -en "done.\nCheck:"
  xset -q|grep "Monitor is"
elif [ $1 = "on" ]; then
  echo -en "Turning monitor on..."
  xset dpms force on
  echo -en "done.\nCheck:"
  xset -q|grep "Monitor is"
elif [ $1 = "status" ]; then
  xset -q|sed -ne 's/^[ ]*Monitor is //p'
else 
  echo usage: $(basename $0) "on|off|status"
fi
Run Code Online (Sandbox Code Playgroud)


hag*_*i_e 5

如果您的视频驱动程序支持此扩展,您可以使用xrandr命令行实用程序获取一些信息.

  • 它似乎给了我与xset相同的错误阅读. (3认同)

mat*_*uer 3

您可能想查看以下输出

$ xset -q
Run Code Online (Sandbox Code Playgroud)

我不确定它是否会起作用,但我认为“监视器是(开|关)”这一行应该告诉你答案。

  • “即使我将其关闭,监视器仍然处于打开状态” - 你怎么知道?也许它足够聪明,可以在检测到您打开显示器进行检查时返回并更改输出。现在我只需要弄清楚当你关上门时冰箱灯是否_真的_熄灭。 (5认同)
  • 即使我将其关闭,仍然显示“监视器已打开”。 (4认同)
  • 这可能只是显示显示器是否已插入。我认为没有办法查看它是否真正打开。如果已插入,操作系统会假定它已打开。Gnome 可能只是在显示器插入时检测显示器,而不是在显示器打开/关闭时检测。我想尝试这个的唯一方法是输入前面的命令,拔下显示器,按 Enter 键,然后重新插入显示器并查看它显示的内容。我无法测试这个 b/c 我在笔记本电脑上。 (2认同)
  • 从不同的终端进行 ssh 时,哪个终端的监视器没有关闭? (2认同)