设置 RS485 串行端口

设置 RS485 串行端口

我尝试在安装了 Debian Jessie 的计算机上使用 RS485 PCI 卡(使用 systemd)。我使用卡制造商提供的补丁调整了内核。这似乎有效,因为检测到了卡并且所有八个串行端口都已初始化。

内核应该设置以下属性:

.flags       = FL_BASE0,
.base_baud   = 921600,
.uart_offset = 0x200,

当我尝试使用这些端口时,我总是看到波特率为 921600。从那时起,我做了以下更改:我卸载了 ModemManager(因为它不停地探测串行端口,而这台计算机上永远不会没有调制解调器)。我向 /etc/udev/rules.d/ 添加了规则,创建了符号链接并更改了这些 RS485 端口的用户和组。我调整了这些组,使其不仅能够以 root 身份读取和写入这些端口。

从那时起,我注意到奇怪的行为。波特率初始化为 921600(我使用“dmsg”查找),但每当我读出它时,它都会设置为 9600(使用“stty -F /dev/stty11 -a”)。

最后我得到以下输出:

me@my-system:$ sudo udevadm info -a -p $(udevadm info -q path -n /dev/ttyS11)

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1b.2/0000:06:00.0/0000:07:0f.0/tty/ttyS11':
    KERNEL=="ttyS11"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{irq}=="17"
    ATTR{line}=="11"
    ATTR{port}=="0x0"
    ATTR{type}=="21"
    ATTR{flags}=="0x13000040"
    ATTR{iomem_base}=="0xDF100000"
    ATTR{custom_divisor}=="0"
    ATTR{iomem_reg_shift}=="0"
    ATTR{uartclk}=="14745600"
    ATTR{xmit_fifo_size}=="64"
    ATTR{close_delay}=="50"
    ATTR{closing_wait}=="3000"
    ATTR{io_type}=="2"

  looking at parent device '/devices/pci0000:00/0000:00:1b.2/0000:06:00.0/0000:07:0f.0':
    KERNELS=="0000:07:0f.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="serial"
    ATTRS{irq}=="17"
    ATTRS{subsystem_vendor}=="0x0702"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x070002"
    ATTRS{driver_override}=="(null)"
    ATTRS{enabled}=="1"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f"
    ATTRS{device}=="0x90f0"
    ATTRS{msi_bus}==""
    ATTRS{local_cpulist}=="0-3"
    ATTRS{vendor}=="0x1402"
    ATTRS{subsystem_device}=="0x0010"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:1b.2/0000:06:00.0':
    KERNELS=="0000:06:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS==""
    ATTRS{irq}=="18"
    ATTRS{subsystem_vendor}=="0x0000"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x060401"
    ATTRS{driver_override}=="(null)"
    ATTRS{enabled}=="1"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f"
    ATTRS{device}=="0x8892"
    ATTRS{msi_bus}=="1"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{vendor}=="0x1283"
    ATTRS{subsystem_device}=="0x0000"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1b.2':
    KERNELS=="0000:00:1b.2"
    SUBSYSTEMS=="pci"
    DRIVERS=="pcieport"
    ATTRS{irq}=="18"
    ATTRS{subsystem_vendor}=="0x8086"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x060400"
    ATTRS{driver_override}=="(null)"
    ATTRS{enabled}=="1"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f"
    ATTRS{device}=="0xa169"
    ATTRS{msi_bus}=="1"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{vendor}=="0x8086"
    ATTRS{subsystem_device}=="0x7270"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="0"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

使用 setserial:

me@my-system:$ sudo setserial -a /dev/ttyS11
/dev/ttyS11, Line 11, UART: undefined, Port: 0x0000, IRQ: 17
    Baud_base: 921600, close_delay: 50, divisor: 0
    closing_wait: 3000
    Flags: spd_normal skip_test

并读取当前设置:

me@my-system:$ sudo stty -F /dev/ttyS11 -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc
-ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

/proc/tty/driver/ 中有一个文件“serial”:

serinfo:1.0 driver revision:
...
11: uart:XR17D15X mmio:0xDF100000 irq:17 tx:0 rx:0
12: uart:XR17D15X mmio:0xDF100200 irq:17 tx:0 rx:0
13: uart:XR17D15X mmio:0xDF100400 irq:17 tx:0 rx:0
14: uart:XR17D15X mmio:0xDF100600 irq:17 tx:0 rx:0
15: uart:XR17D15X mmio:0xDF100800 irq:17 tx:0 rx:0
16: uart:XR17D15X mmio:0xDF100A00 irq:17 tx:0 rx:0
17: uart:XR17D15X mmio:0xDF100C00 irq:17 tx:0 rx:0
18: uart:XR17D15X mmio:0xDF100E00 irq:17 tx:0 rx:0

这里出了什么问题?为什么波特率会改变?我该如何避免这种情况?“UART:未定义”正常吗?

答案1

问题解决了,真是太蠢了。让我设置电脑的人告诉我,电脑里有一张 RS485 卡,但订购并购买了一张 RS232 卡。这两张卡都以同一个名称销售,使用相同的手册和补丁。所以不容易看出来。我借了另一台机器的 RS485 卡,一切正常。

我对此感到非常不舒服但至少这不是我的错。

相关内容