我想使用arrdio调用.net NationalInstruments.Visa.dll来实现用仪器设备用通讯,先用串口进行测试验证,结果可以正常写入,但是回读的时候报错“ivi.visa.timeoutexception异常”,经查资料有可能是因为终止符的原因,但是我写入的数据是带有"\n"终止符的(USB串口工具TX-RX短接验证)。请各位大牛帮看一下有哪里不对。
aardio验证代码如下:
Code AardioLine:19复制
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.import
console;import
dotNet;- dotNet.reference(
- [
"Ivi.Visa"
] = $"~\lib\visa\.res\Ivi.Visa.dll"
; - [
"NationalInstruments.Visa"
] = $"~\lib\visa\.res\NationalInstruments.Visa.dll"
; - )
- dotNet.
import
("Ivi.Visa"
) - dotNet.
import
("NationalInstruments.Visa"
) var
power=NationalInstruments.Visa.SerialSession("ASRL6::INSTR"
);- power.SendEndEnabled=
true
- power.TerminationCharacterEnabled=
true
- power.TerminationCharacter=
10
- power.TimeoutMilliseconds=
2000
- power.RawIO.Write(
"hello world!\n"
); sleep
(1000
)var
pdata=power.RawIO.ReadString() - console.log(pdata)
以上验证所使用的dll在C#中验证OK,且有测试写的字符串去掉"\n"也会报Ivi.Visa.IOTimeoutException异常。
与C#代码相比,串口的打开方式不同,C#代码如下:
Code AardioLine:34复制
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.- using System;
- using NationalInstruments.Visa;
- using Ivi.Visa;
namespace
SerialPortExample_NationalInstruments- {
-
class
Program - {
- static void Main(
string
[] args) - {
-
- NationalInstruments.Visa.ResourceManager powerrs = new ResourceManager();
- NationalInstruments.Visa.SerialSession powerseesion = (NationalInstruments.Visa.SerialSession)powerrs.Open(
"ASRL6::INSTR"
); -
- powerseesion.SendEndEnabled =
true
; - powerseesion.TerminationCharacterEnabled =
true
; - powerseesion.TerminationCharacter =
10
; - powerseesion.TimeoutMilliseconds =
2000
; -
-
- powerseesion.RawIO.Write(
"hello world!\n"
); -
-
string
response = powerseesion.RawIO.ReadString(); -
- Console.WriteLine(
"Response: "
+ response); -
- Console.ReadKey();
- }
- }
- }