08-27-2010 03:15 PM
In labview under visa there is a number of bytes at serial port property. How do I access this from c# if I'm using ni visa? When I use the ReadString() function it throws an exception unless I specify this number of bytes. Is there a way to call Readstring to report only what is in the buffer without having to worry about how many bytes to read?
08-30-2010 07:08 AM
VB uses SerialPort1.BytesToRead. I would guess there is a C# equivalent.
08-30-2010 08:16 AM
I need to use the visa serial ports because I want to make my drivers able to use any available interface on the fly.
08-31-2010 11:16 AM
Hi,
I don't know if this will help, but when I use a Visa Serial Session with C# I set the termimnation character property to true
and select a terminating character. In this case char 13.
Curt
private
private int m_comport = 2;
private int m_baudrate = 19200;
private int m_timeout = 10000;
SerialSession m_session;
public bool OpenSession() { try { m_session = new SerialSession("ASRL" + m_comport + "::INSTR"); m_session.BaudRate = m_baudrate; m_session.StopBits = StopBitType.One; m_session.Parity = Parity.None; m_session.FlowControl = FlowControlTypes.None; m_session.Timeout = m_timeout; m_session.TerminationCharacter = 13; m_session.TerminationCharacterEnabled = true; return true; } catch (NationalInstruments.VisaNS.VisaException visaex) { Trace.WriteLine("OpenSession VisaException: " + visaex.Message); return false; } catch (Exception ex) { Trace.WriteLine("OpenSession Exception: " + ex.Message); return false; } } //and then read it strReceive = m_session.ReadString();
08-31-2010 03:00 PM
Hi Steve,
Take a look at the following VISA function:
viGetAttribute (, VI_ATTR_ASRL_AVAIL_NUM, );
You may need to change the parameters accordingly, but use the NI-VISA Help as a reference (Start->All Programs->National Instruments->VISA).
08-31-2010 04:02 PM
So far Brohan's response is the closest to what I'm looking for. This looks like a CVI parameter though and I need to know how to access it in C#. The other answers don't suffice because they are serial port specific and I need code that allows me to interchange protocals freely.
09-01-2010 11:37 AM
Check out the .NET help for VISA from the same location. I found this function call:
public byte GetAttributeByte( AttributeType attribute );
You can use the AsrlAvailNum attribute.