Bash 列出所有显示输出端口

Bash 列出所有显示输出端口

我正在寻找一个可以打印笔记本电脑拥有的所有视觉输出端口的命令。

我已经在 Stack 和 Google 上搜索了一段时间,但找不到答案。

我得到的最接近的是xandr

eDP-1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 277mm x 156mm
   1366x768      60.00*+  40.00  
   1360x768      59.80    59.96  
   1024x768      60.04    60.00  
   960x720       60.00  
   928x696       60.05  
   896x672       60.01  
   960x600       60.00  
   960x540       59.99  
   800x600       60.00    60.32    56.25  
   840x525       60.01    59.88  
   800x512       60.17  
   700x525       59.98  
   640x512       60.02  
   720x450       59.89  
   640x480       60.00    59.94  
   680x384       59.80    59.96  
   576x432       60.06  
   512x384       60.00  
   400x300       60.32    56.34  
   320x240       60.05  
HDMI-1 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)

寻找类似的东西

HDMI-1 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)

不幸的是,这个输出没有显示我需要的信息。来自的信息xrandr并不准确。

尝试过lspcidmesg也许它在那里但找不到),lshw可能还有一些硬件列表命令。

理想的情况是

VGA x1
HDMI x1 or mini
DP x1
DVI x1

但如果能指出正确的方向,我们将不胜感激。

答案1

所以我正在尝试更改我的机器上的双显示器设置,并找到了您的帖子。因为我对实际显示感兴趣,所以我正在从连接的显示器中查找 EDID 资源:

find /sys/devices -name "edid"

它产生如下输出:

/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-HDMI-A-1/edid
/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-DVI-D-1/edid
/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-DP-2/edid
/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-HDMI-A-2/edid
/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-DP-1/edid

并非所有这些都有效,但如果您查看 /sys 中的各个文件夹,就会发现名为 status 的文件,如下所示:

cat /sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-DP-1/status
connected

通过执行以下操作,还可以了解有关连接的显示设备(与实际显卡输出)的更多详细信息:

cat /sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/drm/card0/card0-DP-1/edid | edid-decode
Extracted contents:
header:          00 ff ff ff ff ff ff 00
serial number:   41 0c 0b 09 cd 0e 00 00 32 1a
version:         01 04
basic params:    b5 46 28 78 3a
chroma info:     59 05 af 4f 42 af 27 0e 50 54
established:     bd 4b 00
standard:        d1 c0 81 80 81 40 95 0f 95 00 b3 00 81 c0 01 01
descriptor 1:    4d d0 00 a0 f0 70 3e 80 30 20 35 00 ba 8e 21 00 00 1a
descriptor 2:    a3 66 00 a0 f0 70 1f 80 30 20 35 00 ba 8e 21 00 00 1a
descriptor 3:    00 00 00 fc 00 50 48 4c 20 33 32 38 50 36 56 0a 20 20
descriptor 4:    00 00 00 fd 00 17 50 1e a0 3c 01 0a 20 20 20 20 20 20
extensions:      01
checksum:        74

Manufacturer: PHL Model 90b Serial Number 3789
Made week 50 of 2016
EDID version: 1.4
Digital display
10 bits per primary color channel
DisplayPort interface
Maximum image size: 70 cm x 40 cm
Gamma: 2.20
DPMS levels: Off
Supported color formats: RGB 4:4:4, YCrCb 4:4:4, YCrCb 4:2:2
First detailed timing is preferred timing
Established timings supported:
  720x400@70Hz
  640x480@60Hz
  640x480@67Hz
  640x480@72Hz
  640x480@75Hz
  800x600@60Hz
  800x600@75Hz
  1024x768@60Hz
  1024x768@75Hz
  1280x1024@75Hz
Standard timings supported:
  1920x1080@60Hz
  1280x1024@60Hz
  1280x960@60Hz
  1440x900@75Hz
  1440x900@60Hz
  1680x1050@60Hz
  1280x720@60Hz
Detailed mode: Clock 533.250 MHz, 698 mm x 398 mm
               3840 3888 3920 4000 hborder 0
               2160 2163 2168 2222 vborder 0
               +hsync -vsync 
Detailed mode: Clock 262.750 MHz, 698 mm x 398 mm
               3840 3888 3920 4000 hborder 0
               2160 2163 2168 2191 vborder 0
               +hsync -vsync 
Monitor name: PHL
Monitor ranges (bare limits): 23-80Hz V, 30-160kHz H, max dotclock 600MHz
Has 1 extension blocks
Checksum: 0x74 (valid)

CEA extension block
Extension version: 3
34 bytes of CEA data
  Video data block
    VIC  16 1920x1080@60Hz 
    VIC  31 1920x1080@50Hz 
    VIC   4 1280x720@60Hz 
    VIC  19 1280x720@50Hz 
    VIC   3 720x480@60Hz 
    VIC  18 720x576@50Hz 
    VIC   2 720x480@60Hz 
    VIC  17 720x576@50Hz 
    VIC   1 640x480@60Hz 
    VIC   5 1920x1080i@60Hz 
    VIC  20 1920x1080i@50Hz 
  Audio data block
    Linear PCM, max channels 2
    Supported sample rates (kHz): 48 44.1 32
    Supported sample sizes (bits): 24 20 16
  Speaker allocation data block
    Speaker map: FL/FR
  Vendor-specific data block, OUI 000c03 (HDMI)
    Source physical address 1.0.0.0
    DC_30bit
    DC_Y444
    DVI_Dual
    Maximum TMDS clock: 600MHz
    Extended HDMI video details:
      HDMI VIC 0 3840x2160@30Hz
      HDMI VIC 1 3840x2160@25Hz
      HDMI VIC 2 3840x2160@24Hz
Underscans PC formats by default
Basic audio support
Supports YCbCr 4:4:4
Supports YCbCr 4:2:2
1 native detailed modes
Detailed mode: Clock 27.000 MHz, 698 mm x 398 mm
                720  736  798  858 hborder 0
                480  489  495  525 vborder 0
               -hsync -vsync 
Detailed mode: Clock 74.250 MHz, 698 mm x 398 mm
               1280 1390 1430 1650 hborder 0
                720  725  730  750 vborder 0
               +hsync +vsync 
Detailed mode: Clock 148.500 MHz, 698 mm x 398 mm
               1920 2448 2492 2640 hborder 0
               1080 1084 1089 1125 vborder 0
               +hsync +vsync 
Detailed mode: Clock 147.170 MHz, 698 mm x 398 mm
               2048 2096 2128 2208 hborder 0
               1080 1083 1093 1111 vborder 0
               +hsync -vsync 
Checksum: 0x18 (valid)

EDID block does NOT conform to EDID 1.3!
        Detailed block string not properly terminated

答案2

这是一个复杂的问题。

xrandr将根据 X11 服务器控制下的所有 GPU 的知识显示任何和所有输出。但硬件制造商可能会添加内置转换器,例如将 GPU 芯片的 DisplayPort 输出转换为 DVI,或者只是保留某些 GPU 的输出未连线。 GPU,以及扩展的xrandr,没有办法知道这样的变化。此外,列出的 DisplayPort 输出在物理上可能是 Mini-DP 或 Thunderbolt 连接。

如果您有一台带有两个 GPU 的笔记本电脑,并且禁用了其中一个(通过 BIOS 或通过 Bumblebee for NVidia Optimus 技术等软件),则禁用 GPU 的输出信息显然将无法用于xrandr.

解决该问题的另一种方法可能是使用dmidecode:通过dmidecode -t 8,您应该获得硬件制造商在 BIOS DMI 数据中描述的所有连接器/端口的列表。但是,此信息可能并不总是正确或完整:我的笔记本电脑根本没有列出任何 DMI 连接器信息。

答案3

sysfs 中的 kernal DRI 调试显示视频内核模块识别的连接器。

例如我的视频内核模块是i915,那么我可以

 sudo grep "^connector" /sys/kernel/debug/dri/0/i915_display_info

并得到

connector 71: type eDP-1, status: connected
connector 80: type DP-1, status: disconnected
connector 86: type HDMI-A-1, status: disconnected
connector 90: type DP-2, status: disconnected
connector 95: type HDMI-A-2, status: disconnected
connector 97: type DP-3, status: disconnected
connector 105: type DP-4, status: connected
connector 101: type DP-5, status: connected

请注意,此处列出的端口可能与 的输出不同xrandr。例如,我的 xrandr 输出为eDP-1, DP-2-2, DP-2-3

答案4

xrandr | awk 'BEGIN { hdmi=dp=0; }; 
    /^HDMI-/ { hdmi++;}; /^DP-/ { dp++; };
    END { printf "%8s%s\n","HDMI x",hdmi; printf "%8s%s\n","DP x",dp; }' 

  HDMI x1
    DP x0

相关内容