| Products > Test Equipment |
| Download speed from Rigol DS1054Z or similar oscilloscope to a PC |
| << < (6/8) > >> |
| alm:
--- Quote from: RoGeorge on November 17, 2022, 11:14:15 pm ---I don't know how to apply read/write_termination before opening the instrument. If I open the instrument first, by default the driver sends '*CLS' without the 0x0a terminator, which hangs the oscilloscope communication, and can recover only by a power cycle. --- End quote --- Maybe calling dso._write('\n') right after instantiating the DS1104Z object would remove the hang? This would send the termination character the scope is waiting for. --- Quote from: RoGeorge on November 17, 2022, 11:14:15 pm ---However, the read/write_termination settings seems to apply only for ivi functions. For example, if I use osc._ask_raw(':WAV:DATA?\n'), then I must add the 0x0a manually, as '\n'. --- End quote --- Looking at the PyVISA source, write adds a termination character, and write_raw not. So it's not a matter of ivi vs non-ivi functions, but of write_raw() not adding termination, because you're saying you want to write verbatim what you send. Does it work if you use dso._write(':WAV:DATA?') and then output = dso._read_raw()? ask is nothing more than write + read. --- Quote from: RoGeorge on November 17, 2022, 11:14:15 pm ---I had to look more into the ivi sources. Maybe there is a way to set the automatic addition of the 0x0a terminator in pyvisa-py, so I won't end with a mixture of functions where some requires 0x0a while others don't. --- End quote --- Setting dso._interface.instrument.write_termination already sets the terminator in PyVISA, not ivi. dso._interface.instrument is the PyVISA resource. --- Quote from: RoGeorge on November 17, 2022, 11:14:15 pm ---The transfer speed is 65 seconds to fetch 24MSa. Not bad, but still 3 times slower than the 22 seconds I get when downloading with https://github.com/morgan-at-keysight/socketscpi I wonder if it would be possible to use 'socketscpi' instead of 'pyvisa', or maibe to configure 'pyvisa' to use 'socketscpi' instead of 'pyvisa-py'. --- End quote --- Changing Python-ivi to use socketscpi would probably be a big change. What you could consider is just like python-ivi currently supports using python-vxi11 directly without going through PyVISA, you could also add support for calling the python socket library directly for ::SOCKET resources without going through PyVISA. This would involve writing an instrument class around the socket library like the PySerial interface, and some minor changes to ivi.py around hereto add a case where it instantiates the newly created PySocket instrument instead of the vxi11 of PyVISA instruments. |
| RoGeorge:
Talking about configuring PyVISA to use 'socketscpi' as its LAN back-end because of this recent commit into socketscpi, commit that changed the old names of the socketscpi functions in order to match the pyvisa syntax, https://github.com/morgan-at-keysight/socketscpi/commit/3d8bea9b012c03a29d6676b60a21ac7e5a655ae4. By the commit description, 'socketscpi' might be already usable as a backend for PyVISA, just like now it is possible to force PyVISA to use 'pyvisa-py' instead of proprietary ni-visa shared libs (when both ni-visa and pyvisa-py are installed) like in this example from https://pyvisa.readthedocs.io/projects/pyvisa-py/en/latest/index.html --- Quote ---You can select the PyVISA-py backend using @py when instantiating the visa Resource Manager: --- End quote --- --- Code: ---# pyvisa usage example import pyvisa as visa # rm = visa.ResourceManager() # will look for proprietary ni-visa or alike first, if installed rm = visa.ResourceManager('@py') # will ignore any installed VISA libs, and use pyvisa-py instead inst = rm.open_resource('<VISA_format_resource_of_an_instrument_to_open_here>') print(inst.query("*IDN?")) --- End code --- I don't know how to tell PyVISA to use socketscpi instead of pyvisa-py, or if socketscpi is ready to use as a pyvisa backend or not. Will try to learn that by digging through sources. Does this look feasible as a fix (python-ivi with prefer pyvisa --> pyvisa with forced backend socketscpi --> socketscpi using python's SOCKET)? |
| RoGeorge:
Got 24MSamples in 22 seconds, with python-ivi, pyvisa, pyvisa-py and SOCKET connection!!! :scared: :-DMM Found what was making 'pyvisa-py' 3 times slower than 'socketscpi' by looking side by side at the opening socket parameters in 'pyvisa-py' vs 'socketscpi'. It was the default value of the TCP_NODELAY. The download becomes fast if I add this extra line --- Code: --- self._set_tcpip_nodelay(constants.VI_ATTR_TCPIP_NODELAY, True) --- End code --- at the end of the '_connect()' definition, inside the file lib/python3.10/site-packages/pyvisa_py/tcpip.py. It's the line number five hundred and something in the modules installed with pip, probably would have to be inserted after line 840 if the same change were to be added in the github source file: https://github.com/pyvisa/pyvisa-py/blob/main/pyvisa_py/tcpip.py#L840 However, I suspect there might be a way to set the nodelay parameter as True, but I don't know enough Python and/or OOP to figure myself the syntax for setting TCPIP NODELAY from the end user code, without changing the sources inside pyvisa-py files. Any idea how to set the nodelay parameter using python-ivi? |
| alm:
--- Quote from: RoGeorge on November 18, 2022, 09:08:24 am ---Talking about configuring PyVISA to use 'socketscpi' as its LAN back-end because of this recent commit into socketscpi, commit that changed the old names of the socketscpi functions in order to match the pyvisa syntax, https://github.com/morgan-at-keysight/socketscpi/commit/3d8bea9b012c03a29d6676b60a21ac7e5a655ae4. I don't know how to tell PyVISA to use socketscpi instead of pyvisa-py, or if socketscpi is ready to use as a pyvisa backend or not. Will try to learn that by digging through sources. Does this look feasible as a fix (python-ivi with prefer pyvisa --> pyvisa with forced backend socketscpi --> socketscpi using python's SOCKET)? --- End quote --- I know that this might be a red herring at this point, but when I said earlier that I thought integrating socketscpi with PyVISA, I was confusing socketscpi with another library, so my statement that it would be hard was wrong. It does not look super hard, but would require looking at how PyVISA-py registers itself with PyVISA, and doing the same with a class that wraps socketscpi. --- Quote from: RoGeorge on November 18, 2022, 01:34:32 pm ---Found what was making 'pyvisa-py' 3 times slower than 'socketscpi' by looking side by side at the opening socket parameters in 'pyvisa-py' vs 'socketscpi'. It was the default value of the TCP_NODELAY. The download becomes fast if I add this extra line --- Code: --- self._set_tcpip_nodelay(constants.VI_ATTR_TCPIP_NODELAY, True) --- End code --- at the end of the '_connect()' definition, inside the file lib/python3.10/site-packages/pyvisa_py/tcpip.py. It's the line number five hundred and something in the modules installed with pip, probably would have to be inserted after line 840 if the same change were to be added in the github source file: https://github.com/pyvisa/pyvisa-py/blob/main/pyvisa_py/tcpip.py#L840 --- End quote --- Congratulations on finding this! It makes sense that it's a socket option that has such a performance impact. It suggests me that there's something sub-optimal in the Rigol scope about assembling the data into TCP packets, but this is a good workaround. --- Quote from: RoGeorge on November 18, 2022, 01:34:32 pm ---Any idea how to set the nodelay parameter using python-ivi? --- End quote --- It took a bit of digging, but I think this should work: dso._interface.instrument.visalib.sessions[dso._interface.instrument.session]._set_tcpip_nodelay(...) |
| RoGeorge:
--- Quote from: alm on November 18, 2022, 09:23:53 pm --- --- Quote from: RoGeorge on November 18, 2022, 01:34:32 pm ---Any idea how to set the nodelay parameter using python-ivi? --- End quote --- It took a bit of digging, but I think this should work: dso._interface.instrument.visalib.sessions[dso._interface.instrument.session]._set_tcpip_nodelay(...) --- End quote --- Wow, thanks, I've tried today a thousand combinations and couldn't find any that works. Now it gets all the 24 million samples in 22 seconds, connected like this: --- Code: ---import ivi # 24Msa in 22 seconds ivi.set_prefer_pyvisa() dso = ivi.rigol.rigolDS1104Z(resource='TCPIP0::192.168.1.3::5555::SOCKET', id_query=False, reset=False) from pyvisa import constants dso._interface.instrument.visalib.sessions[dso._interface.instrument.session]._set_tcpip_nodelay(constants.VI_ATTR_TCPIP_NODELAY, True) # 24Msa in 16 minutes # dso = ivi.rigol.rigolDS1104Z(resource='TCPIP0::192.168.1.3::INSTR', id_query=False, reset=False) --- End code --- Don't celebrate yet, (re)found one more issue! ;D - A (telnet) data transfer will drop if inside any data packets it receives a 0x00. This is some RFC spec (for text Telnet IIRC). - The ADC samples are coming as bytes, which means the incoming data packets will be truncated if one of the bytes is zero, because in the Telnet RFC 0x00 is considered a terminator, and will drop any bytes coming after a 0x00. - This issue is only observed when the input signal in the ADC is less than 5 divisions on the screen (ADC outputs 0x7f for zero volts, and 0x00 for any input voltage that is -5*volts/div or under) - Both the pyvisa->pyvisa-py->socket and the socketscpi are affected Don't know how to overcome this, or if it is possible at all to open some other kind of socket connection, one that doesn't consider 0x00 as a terminator. :-// From when I've written my own SCPI scripts, I had to modify the Python's telnet module such that it won't end a data transfer at the first 0x00 in a data stream. Since the 0x00 as a terminator is part of the RFC854 spec, this modification can not be merged upstream, so I've just made a local copy of the telnet.py (module) file, and modified the local copy to disregard 0x00 as terminator (commented out those two "if c==" lines: https://github.com/RoGeorge/DS1054Z_screen_capture/blob/master/telnetlib_receive_all.py --- Code: --- try: while self.rawq: c = self.rawq_getchar() if not self.iacseq: #if c == theNULL: # continue #if c == "\021": # continue if c != IAC: buf[self.sb] = buf[self.sb] + c continue else: self.iacseq += c elif len(self.iacseq) == 1: --- End code --- Not elegant, but it worked. The plan was to remove the telnetlib.py module later, and use a SOCKET connection instead of a Telnet one, though never implemented that/ TL;DR So far PythonIVI using SOCKET and NO_DELAY is the fastest one, but it only works if the oscilloscope trace is nicely contained inside the screen. Do you happen to know any SOCKET parameter, so to transfer a specified number of bytes until all bytes were transferred (or timeout has occurred), but for binary, such that 0x00 is not considered a data terminator? |
| Navigation |
| Message Index |
| Next page |
| Previous page |