From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

NI VISA .NET C# Serial Read in a loop

I am trying to build a test tool for a customer's hardware, the hardware will send "Ready" in Hex thru the serial once powered on. I've been thinking how to make the program actively listening this activity at the background. So far for some hours glancing in the library Help docs I could only think about using a loop and RawIO.Read() to constantly read from Serial until it hits the term "Ready". But this is so not elegant and inefficient and I don't see WaitOnEvent have similar functions to it. Anyone can point me into a right direction?

0 Kudos
Message 1 of 2
(1,217 Views)

For a serial connection you don't need Visa, the Net serialport class is simpler to use and works well,  for asynchronous reading you just need to implement the DataReceived event handler:

https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport.datareceived?view=dotnet-plat...

0 Kudos
Message 2 of 2
(1,170 Views)