For Agilent 33512 it does not automatically return an answer for *IDN? command, but returns an answer for FREQ? command. On the other hand, for Keithley DMM7510, it responds properly to *IDN? command but does not respond to read? command. In all cases, the answer can be obtained by sending an extra ++read command. See attached log file.
Thanks for your further feedback. I could partially replicate this on the Keithley here. After power up I could send an *idn? and the DMM would reply with its ID string. I then send a read? and get a beep with a -213 (init ignored) error. Subsequent read? commands always result in a beep although sometimes a reading is returned. A logic analyser trace showed the command string terminated with a CR+LF always gets sent to the meter, but the meter, more often than not, does not return any data. By contrast, the fetc? command seemed to work every time. If I sent a meas?, a reading was returned and after that, all 3 commands - fetc?, read? and meas? would work normally without any beeps. It seems that at least in this respect, the meas? command behaves differently from read?, at least on the Keithley. After a power cycle it was back to the same behaviour.
After a bit of digging I found a reference that suggested that if the meter returned -213 errors, then sending an *rst command should clear it. So I power cycled the meter, did and *idn? and followed this by *rst and sure enough all 3 commands now worked OK without any bleeps. So was the *idn? command leaving the meter in some sort of error state? To test this, I power cycled the meter again and this time without sending a *idn? command, just started sending read? commands, but got the same problem result. Therefore it was nothing to do with the *idn? command and once again sending an *rst cleared it.
At this point in time, I don't know why the DMM is behaving in that way. I did notice that when the meter is power cycled, after starting up, it sits periodically refreshing its display with a reading. It continues to do this even after sending an *idn?, read? or fetc? commands. However after sending an *rst, the display shows "------- VDC" until a read? or meas? is sent, at which point it will show a reading. Not surprisingly if a fetc? is sent while there is no reading displayed, the meter returns an error as no data is available yet. If you send a read? after the *rst, or send a meas? at any time (either before or after an *rst), the display shows a static reading and no longer refreshes periodically. It therefore seems that meas? and *rst both stop the meter from automatically taking readings (equivalent to ':init:cont off' perhaps?), but read? does not, and will display readings without error only after an *rst. The meas? command does not require additional commands such as *rst to be sent. Not sure if that is significant, but clearly meas? and read? behave differently on the Keithley.
It would be really nice to add a couple of extra functionalities to this program. One would be to have a loop where it sends one string over and over and reads the response. One could have something called auto_str that can be set to save the command string (like "FETCH?") to be send to the instrument to get a response.
Another functionality is to have a skeleton for a custom routine that can be added to Arduino code by the user. Here one can program a more complicated series of commands for processing (such as limit checking or basic arithmetic). This will shift the program to the Arduino, so the output can be used easily for logging, for example, without requiring another programming layer.
[/quote]
Implementing the command loop should not be too difficult, but the second function is a rather more complex proposition. Given the memory constraints of a Nano or Uno, the "complicated series of commands" would have to take no more than 256 bytes of memory, and that is provided it can be implemented in a way that does not impact adversely on the already tight runtime memory. The Mega2560 has greater memory capacity and would offer more possibilities in this regard. It might just be pushing things a bit too far on the Nano and the Uno.
I will have an attempt at implementing the first function, but will have to give the second one some careful thought.