我在 POS 计算机上安装了 PCI 串行卡,并尝试在其中安装旧的热敏打印机。测试命令 ls > /dev/ttyS4 运行良好,但只有在我第二次发送它之后才有效。为了让它在我的 ERP 系统上正常工作,我需要它在第一时间就正常工作。
PS:用户已经在组拨出中。
root@pdv3:/home/pdv3# lspci -v
00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Controller (rev 06)
Subsystem: ASRock Incorporation 4th Gen Core Processor DRAM Controller
Flags: bus master, fast devsel, latency 0
Capabilities: [e0] Vendor Specific Information: Len=0c <?>
Kernel driver in use: hsw_uncore
00:02.0 VGA compatible controller: Intel Corporation 4th Generation Core Processor Family Integrated Graphics Controller (rev 06) (prog-if 00 [VGA controller])
Subsystem: ASRock Incorporation 4th Generation Core Processor Family Integrated Graphics Controller
Flags: bus master, fast devsel, latency 0, IRQ 27
Memory at f0000000 (64-bit, non-prefetchable) [size=4M]
Memory at e0000000 (64-bit, prefetchable) [size=256M]
I/O ports at f000 [size=64]
[virtual] Expansion ROM at 000c0000 [disabled] [size=128K]
Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [d0] Power Management version 2
Capabilities: [a4] PCI Advanced Features
Kernel driver in use: i915
Kernel modules: i915
00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06)
Subsystem: ASRock Incorporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller
Flags: bus master, fast devsel, latency 0, IRQ 30
Memory at f0614000 (64-bit, non-prefetchable) [size=16K]
Capabilities: [50] Power Management version 2
Capabilities: [60] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [70] Express Root Complex Integrated Endpoint, MSI 00
Kernel driver in use: snd_hda_intel
Kernel modules: snd_hda_intel
00:14.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB xHCI (rev 05) (prog-if 30 [XHCI])
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family USB xHCI
Flags: bus master, medium devsel, latency 0, IRQ 24
Memory at f0600000 (64-bit, non-prefetchable) [size=64K]
Capabilities: [70] Power Management version 2
Capabilities: [80] MSI: Enable+ Count=1/8 Maskable- 64bit+
Kernel driver in use: xhci_hcd
00:16.0 Communication controller: Intel Corporation 8 Series/C220 Series Chipset Family MEI Controller #1 (rev 04)
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family MEI Controller
Flags: bus master, fast devsel, latency 0, IRQ 28
Memory at f061e000 (64-bit, non-prefetchable) [size=16]
Capabilities: [50] Power Management version 3
Capabilities: [8c] MSI: Enable+ Count=1/1 Maskable- 64bit+
Kernel driver in use: mei_me
Kernel modules: mei_me
00:1a.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB EHCI #2 (rev 05) (prog-if 20 [EHCI])
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family USB EHCI
Flags: bus master, medium devsel, latency 0, IRQ 16
Memory at f061c000 (32-bit, non-prefetchable) [size=1K]
Capabilities: [50] Power Management version 2
Capabilities: [58] Debug port: BAR=1 offset=00a0
Capabilities: [98] PCI Advanced Features
Kernel driver in use: ehci-pci
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 05)
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset High Definition Audio Controller
Flags: bus master, fast devsel, latency 0, IRQ 29
Memory at f0610000 (64-bit, non-prefetchable) [size=16K]
Capabilities: [50] Power Management version 2
Capabilities: [60] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [70] Express Root Complex Integrated Endpoint, MSI 00
Capabilities: [100] Virtual Channel
Kernel driver in use: snd_hda_intel
Kernel modules: snd_hda_intel
00:1c.0 PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #1 (rev d5) (prog-if 00 [Normal decode])
Flags: bus master, fast devsel, latency 0, IRQ 16
Bus: primary=00, secondary=01, subordinate=01, sec-latency=0
I/O behind bridge: 00002000-00002fff
Memory behind bridge: dfa00000-dfbfffff
Prefetchable memory behind bridge: 00000000dfc00000-00000000dfdfffff
Capabilities: [40] Express Root Port (Slot+), MSI 00
Capabilities: [80] MSI: Enable- Count=1/1 Maskable- 64bit-
Capabilities: [90] Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family PCI Express Root Port
Capabilities: [a0] Power Management version 3
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1c.3 PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #4 (rev d5) (prog-if 00 [Normal decode])
Flags: bus master, fast devsel, latency 0, IRQ 19
Bus: primary=00, secondary=02, subordinate=02, sec-latency=0
I/O behind bridge: 0000e000-0000efff
Memory behind bridge: f0500000-f05fffff
Capabilities: [40] Express Root Port (Slot+), MSI 00
Capabilities: [80] MSI: Enable- Count=1/1 Maskable- 64bit-
Capabilities: [90] Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family PCI Express Root Port
Capabilities: [a0] Power Management version 3
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1c.5 PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #6 (rev d5) (prog-if 00 [Normal decode])
Flags: bus master, fast devsel, latency 0, IRQ 17
Bus: primary=00, secondary=03, subordinate=03, sec-latency=0
I/O behind bridge: 0000d000-0000dfff
Memory behind bridge: f0400000-f04fffff
Capabilities: [40] Express Root Port (Slot+), MSI 00
Capabilities: [80] MSI: Enable- Count=1/1 Maskable- 64bit-
Capabilities: [90] Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family PCI Express Root Port
Capabilities: [a0] Power Management version 3
Kernel driver in use: pcieport
Kernel modules: shpchp
00:1d.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB EHCI #1 (rev 05) (prog-if 20 [EHCI])
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family USB EHCI
Flags: bus master, medium devsel, latency 0, IRQ 23
Memory at f061b000 (32-bit, non-prefetchable) [size=1K]
Capabilities: [50] Power Management version 2
Capabilities: [58] Debug port: BAR=1 offset=00a0
Capabilities: [98] PCI Advanced Features
Kernel driver in use: ehci-pci
00:1f.0 ISA bridge: Intel Corporation C220 Series Chipset Family H81 Express LPC Controller (rev 05)
Subsystem: ASRock Incorporation C220 Series Chipset Family H81 Express LPC Controller
Flags: bus master, medium devsel, latency 0
Capabilities: [e0] Vendor Specific Information: Len=0c <?>
Kernel driver in use: lpc_ich
Kernel modules: lpc_ich
00:1f.2 SATA controller: Intel Corporation 8 Series/C220 Series Chipset Family 6-port SATA Controller 1 [AHCI mode] (rev 05) (prog-if 01 [AHCI 1.0])
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family 6-port SATA Controller 1 [AHCI mode]
Flags: bus master, 66MHz, medium devsel, latency 0, IRQ 25
I/O ports at f0b0 [size=8]
I/O ports at f0a0 [size=4]
I/O ports at f090 [size=8]
I/O ports at f080 [size=4]
I/O ports at f060 [size=32]
Memory at f061a000 (32-bit, non-prefetchable) [size=2K]
Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [70] Power Management version 3
Capabilities: [a8] SATA HBA v1.0
Kernel driver in use: ahci
Kernel modules: ahci
00:1f.3 SMBus: Intel Corporation 8 Series/C220 Series Chipset Family SMBus Controller (rev 05)
Subsystem: ASRock Incorporation 8 Series/C220 Series Chipset Family SMBus Controller
Flags: medium devsel, IRQ 3
Memory at f0619000 (64-bit, non-prefetchable) [size=256]
I/O ports at f040 [size=32]
Kernel modules: i2c_i801
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 0c)
Subsystem: ASRock Incorporation Motherboard (one of many)
Flags: bus master, fast devsel, latency 0, IRQ 19
I/O ports at e000 [size=256]
Memory at f0504000 (64-bit, non-prefetchable) [size=4K]
Memory at f0500000 (64-bit, prefetchable) [size=16K]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
Capabilities: [70] Express Endpoint, MSI 01
Capabilities: [b0] MSI-X: Enable+ Count=4 Masked-
Capabilities: [d0] Vital Product Data
Capabilities: [100] Advanced Error Reporting
Capabilities: [140] Virtual Channel
Capabilities: [160] Device Serial Number 01-00-00-00-68-4c-e0-00
Capabilities: [170] Latency Tolerance Reporting
Kernel driver in use: r8169
Kernel modules: r8169
03:00.0 Serial controller: Device 1c00:3250 (rev 10) (prog-if 05 [16850])
Subsystem: Device 1c00:3250
Flags: fast devsel, IRQ 17
I/O ports at d000 [size=256]
Memory at f0408000 (32-bit, prefetchable) [size=32K]
I/O ports at d100 [size=4]
Expansion ROM at f0400000 [disabled] [size=32K]
Capabilities: [60] Power Management version 3
Capabilities: [68] MSI: Enable- Count=1/32 Maskable+ 64bit+
Capabilities: [80] Express Legacy Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Kernel driver in use: parport_serial
Kernel modules: parport_serial
root@pdv3:/home/pdv3#
答案1
这个答案是不正确的,因为我认为打印机是 PCI 设备,但我读错了。并行端口已在系统中。
虽然我不知道问题的本质,但每当 Linux 内核通过连接/断开 PCI 设备时,您都可以可靠地触发自己的脚本udev
,如下所述:(摘录如下)
https://www.pcsuggest.com/run-shell-scripts-from-udev-rules
sudo nano /etc/udev/rules.d/40-switch_modem.rules
My custom rule looks like bellow
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1c9e", ATTR{idProduct}=="f000", RUN+="switch_modem.service"
其中 idVendor 和 idProduct 在 lspci 的输出中可用,并且来自硬件本身。在您的情况下,子系统不是 USB。udev
文档中提供了可能的值。
在本文中,作者创建了他选择的脚本(您可能想向打印机发送一次换行符)
As directly running the script from a custom udev rule didn't worked, I had to create
a new systemd service to run the script through it, when the device is plugged in, a
USB modem in this case.
User created systemd service files are usually stored under /etc/systemd/system/ ,
I'm naming it switch_modem.service
sudo nano /etc/systemd/system/switch_modem.service
The systemd service file,
[Unit]
Description=4G modem switcher
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/bin/switch_modem
[Install]
WantedBy=multi-user.target
这保证了: - 它将在启动期间、到达目标之前运行multi-user
- 它将在每次插入匹配硬件时运行
还有一个选项udev
可以提供自己的脚本,该脚本将在任何设备的每次连接/断开连接时调用,其中udev
将传递适当的信息作为命令行参数或环境变量。这种选择比较灵活,但实施起来也比较困难。