Hi all,
I'm writing a class library to facilitate communication with instruments utilizing the Modbus Application Protocol that are connected to a NI cRIO-9073 via a serial-to-ethernet cable plugged into an NI 9870 DAQ card that is plugged into the cRIO. The specific instrument I am talking to is an MKS Optitemp Heat Exchanger, which uses the RTU serial transmission mode (http://modbus.org/docs/PI_MBUS_300.pdf).
I've been successful in communicating with it, using the Query(byte[] dataToWrite, int countToRead) method of the SerialSession class inherited from the MessageBasedSession class. However, I need to specify the exact number of bytes to read, or else I get the following VisaException:
"Timeout expired before operation completed. VISA error code -1073807339 (0xBFFF0015), ErrorTimeout"
Unfortunately, I don't always know how many bytes the Query is going to return. Namely, if the slave returns an error, the response is fewer bytes than expected, throwing the above exception. I want to be able to recover the details of the error message for debugging purposes, but right now am stuck with just reporting a generic error message if a VisaException is caught.
I've tried the Query( byte[] dataToWrite) overload, but that results in a timeout every time. The Modbus RTU protocol specifies that each message be terminated with "a silent interval of at least 3.5 character time", and I don't know how to set the SerialSession.TerminationCharacter property to reflect this.
Is there a way I can read the bytes already in the buffer, even if the buffer isn't completely filled?
The only workaround I can think of is sending the same query multiple times, each time incrementing the countToRead by 1, but there must be a better way.
Thanks,
Joe