12-17-2018 09:56 AM
> Just now I tried to use Byte (), and the result of transmission is the same as that of Stringbuilder.
yes, this is what I was saying, here it is the same because the string returned by viRead is an ASCII string i.e. coded with one byte per character, so that both formats contain physically the same data. You can easily convert between them eg.:
str = System.Text.Encoding.ASCII.GetString(array, 0, length)
or
array = System.Text.Encoding.ASCII.GetBytes(str)
> I've thought about using byte (), but viRead transfers files by "#" marking the length of the file.
"#" has nothing to do with viRead. Visa, if you are using GPIB, USB or TCPIP connection, uses its own methods to pass the information about the length of the data to transfer (EOI signal in GPIB and its equivalents in other protocols) but this is invisible to your application: viRead returns exactly the byte stream coming from your instrument without adding any terminating characters. Therefore "#" and maybe some other characters ("2Courier New" characters ?) are part of the data sent by your instrument.
You have to check in the manual how the response is formatted to withdraw the image from it (I don't know your instrument but it could be something like <header><data><footer>, e.g. for some Textronix scopes I remember that the waveform data had an "#"followed by the data length in the header, I had to strip it off to acess the waveform data) and then parse this data record accordingly.
PS. I forgot to add a ref. to my code in my last post:
https://www.codeproject.com/Articles/1166996/Multithreaded-communication-for-GPIB-Visa-Serial-i
You can also try this library to check if you get the same data, but of course this will not solve your problem of parsing the data correctly to extract the image. NB. Note that my code automatically repeats reading as long as EOI is not asserted, therefore it works in principle even if the buffer is smaller than the size of the data. I say in principle because there are apparently a few buggy instruments that don't handle correctly repeated readings.
good luck!