简体   繁体   English

仅在 Linux 中与 TDK-Lambda ZUP 的串行 RS485 / RS232 通信非常慢

[英]Serial RS485 / RS232 communication with TDK-Lambda ZUP very slow only in Linux

In our experiment, we use many ZUP power supplies to power up the electronics.在我们的实验中,我们使用许多 ZUP 电源为电子设备供电。 The exact models are TDK-Lambda ZUP80-2.5 and ZUP6-33.确切的型号是 TDK-Lambda ZUP80-2.5 和 ZUP6-33。 They are remotely controlled and monitored by a server running Linux.它们由运行 Linux 的服务器远程控制和监视。

The problem is that the serial communication is very slow.问题是串行通信非常慢。 By slow I mean that the ZUP baud rate can be set between 300 and 9600. To communicate (almost) reliably with the PSU I have to set the baud rate to the minimum 300 bps.慢是指 ZUP 波特率可以设置在 300 到 9600 之间。为了(几乎)可靠地与 PSU 通信,我必须将波特率设置为最低 300 bps。

At first, I was suspecting a hardware or wiring issue but nothing seemed to improve the situation.起初,我怀疑是硬件或接线问题,但似乎没有任何改善。 Then I tested the PSU with the official proprietary Windows application (using the very same hardware setup) and I could communicate at 9600 baud rate without problems.然后我用 官方专有的 Windows 应用程序(使用完全相同的硬件设置)测试了 PSU,我可以毫无问题地以 9600 波特率进行通信。 So the problem lies undoubtedly in the Linux driver or in my code.所以问题无疑出在 Linux 驱动程序或我的代码中。

The ZUP can communicate with the PC using RS232 or RS485. ZUP 可以使用 RS232 或 RS485 与 PC 通信。 I tried them both with the same results.我对它们都进行了尝试,结果相同。 I tried to use a cheap RS485-USB adapter, the RS232 serial port of a desktop PC and a professional-grade PCIe RS485 card, all without success.我尝试使用便宜的 RS485-USB 适配器、台式 PC 的 RS232 串口和专业级的 PCIe RS485 卡,均未成功。

As a programming language, I am using Python.作为一种编程语言,我使用的是 Python。 I tried to use pyvisapy and a scientific software called Pyrame that essentially provides a wrapper around the serial Python module.我尝试使用pyvisapy和一个名为Pyrame的科学软件,它本质上为serial Python 模块提供了一个包装器。 Should I try with a different language?我应该尝试使用不同的语言吗?

Here is a minimal example to show how I am accessing the unit in pyvisapy:这是一个最小的示例,显示我如何在 pyvisapy 中访问该单元:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import visa
from visa import constants
rm = visa.ResourceManager('@py')
inst = rm.open_resource('ASRL/dev/ttyUSB0::INSTR')
inst.baud_rate = 9600 # 300
inst.write_termination = ''
inst.read_termination = '\r\n'
inst.set_visa_attribute(constants.VI_ATTR_ASRL_FLOW_CNTRL, constants.VI_ASRL_FLOW_XON_XOFF)
inst.stop_bits = constants.StopBits.one
inst.parity = constants.Parity.none
inst.data_bits = 8

print(inst.write(":ADR01;"))
print(inst.write(":REV?;"))
print(inst.read())

In Linux, the above code works with 300 bps but not with 9600 bps (the situation get worse and worse gradually as I increase the baud rate).在 Linux 中,上述代码适用于 300 bps 但不适用于 9600 bps(随着我提高波特率,情况逐渐恶化)。 Even with 300 bps, sometimes I get some timeout or data corruption errors when sending or receiving long commands.即使使用 300 bps,有时在发送或接收长命令时也会出现超时或数据损坏错误。

PS our DAQ runs only in Linux so using Windows is not an option. PS 我们的 DAQ 仅在 Linux 中运行,因此不能使用 Windows。

It turned out to be an issue with Python itself, as pointed out by the user Marcos G.. As I have written in the comments I have tried to write a driver using both pyserial and arduino-serial .正如用户 Marcos G. 所指出的那样,事实证明 Python 本身存在问题。正如我在评论中所写,我尝试使用pyserialarduino-serial编写驱动程序。 Despite some initial partial success, both of them turned out to have more or less the same issues.尽管最初取得了一些部分成功,但事实证明他们俩都或多或少存在相同的问题。 So I have re-written completely the driver in C++ using the libserialport C library .所以我使用libserialport C library完全重写了 C++ 中的驱动程序。 Now I can communicate with the ZUP at almost full speed.现在我几乎可以全速与 ZUP 进行通信了。

I had similar issues with 9600 Baud until I discovered Paragraph 5.6.1 from TDK-Lambda's Zup User Manual.在我从TDK-Lambda 的 Zup 用户手册中发现第 5.6.1 段之前,我在 9600 波特上遇到了类似的问题。

There's a Python library for Zup control at https://github.com/Amphenol-Borisch-Technologies/Zup-Python-Library. https://github.com/Amphenol-Borisch-Technologies/Zup-Python-Library 有一个 Python 库用于 Zup 控制。

Look at class Zup's _write_command() method.查看 class Zup 的 _write_command() 方法。

Per Zup Manual, paragraph 5.6.1:根据 Zup 手册,第 5.6.1 段:

  • 10mSec minimum delay is required before sending ADR command.发送 ADR 命令前需要 10 毫秒的最小延迟。
  • 15mSec average command processing time for the Zup Series. Zup 系列的平均命令处理时间为 15 毫秒。
  • 30mSec delay required after sending ADR command.发送 ADR 命令后需要 30 毫秒的延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM