04-20-2011 09:44 AM
Hello all,
I am using VISA COM library and C# to communication with my instrument via TCPIP.
I add referrence "VISA COM 3.0 Library Type" to my C# project and try to establish the communication by using the following codes:
*********************************
Ivi.Visa.Interop.ResourceManager ResMsg = new Ivi.Visa.Interop.ResourceManager();
Ivi.Visa.Interop.FormattedIO488Class ioClass = new Ivi.Visa.Interop.FormattedIO488Class();
Ivi.Visa.Interop.IMessage Imsg = (ResMsg.Open("TCPIP0::192.168.0.170::10001::SOCKET", Ivi.Visa.Interop.AccessMode.NO_LOCK, 8000, "") as IMessage);
ioClass.IO = Imsg;
ioClass.WriteString("*RST", true);
ioClass.WriteString("*IDN?", true);
String ret = ioClass.ReadString();
Console.WriteLine("ID: " + ret);
**********************************
I could write "*RST" command to the device without errors. And I could see the device really performed a reset by the command.
But when I send "*IDN?" and read the response, I always get a TIME_OUT error. Even though I add "\r\n" at the end of the command and increase the timeout value, I still can the same error. Not only "*IDN?" but also other read command like "*STB?", they all can the same timeout error.
But when I use the VISA-ReadSTB function, it returns the correct data.
I also tried to use Labview VISA-Open, VISA-Write, VISA-Read to do the same test. I also get a error (BFF0015) after VISA-Read.
I also use a IO Monitor programm to see the data. I find out that I could see the response but still I got a timeout error. Currently I could only successfully read the response by Agilent IO control.
I am using C# 2008, Labview 8.2.1, VISA 5.0.3,
Any advice will be really appreciated!
Regards,
Solved! Go to Solution.
04-26-2011 09:25 AM
Please have a look at this KB. Maybe this can help you to fix your problem.
http://digital.ni.com/public.nsf/allkb/874B379E24C0A0D686256FCF007A6EA0?OpenDocument
Cheers
04-27-2011 03:47 AM
When using TCP/IP SOCKET resource, you need:
(1)explicitly add an LF character ("\n") for each command string
(2)set TerminationCharacterEnabled property to TRUE
04-27-2011 05:49 AM - edited 04-27-2011 05:50 AM
Thanks!
I've found the error. The trick is I have to set the BytesToRead to a proper value. Unlike RS232, there is no BytesAtPort property for TCP/IP Socket. So I need to read byte by byte until I read "\n".Otherwise, I have to know in advance how many bytes I expected and set the proper timeout value to get all the bytes before timeout.
Regards,