Author Topic: ngscopeclient - Ultimate acquisition software / protocol decoder / debug tool ?  (Read 31889 times)

0 Members and 1 Guest are viewing this topic.

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
How to get around the Error and rre there any way to tell the ngscopeclient that the Rigol MSO5072 actually does have 4 channels?

The number of channels is linked to the model name, as returned by the SCPI command ‘*IDN?’. The last digit determines the number of available channels. That's what it says in the source code.
I can't comment on the error.

Peter
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30420
  • Country: nl
    • NCT Developments
How to get around the Error and rre there any way to tell the ngscopeclient that the Rigol MSO5072 actually does have 4 channels?

The number of channels is linked to the model name, as returned by the SCPI command ‘*IDN?’. The last digit determines the number of available channels. That's what it says in the source code.
I can't comment on the error.
Unfortunately this is one of the problems with ngscopeclient; trying to infer the number of channels and bandwidth from the model number instead of having a translation table to translate model number into channels and bandwidth.
« Last Edit: December 22, 2025, 05:28:44 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
The analog channels are already working.

Peter
 

Online voltsandjolts

  • Supporter
  • ****
  • Posts: 3914
  • Country: gb
Yeh, that needs an option to override. Everyone here has hacked scopes ::)
 

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
@Wiljan, @nctnico, @voltsandjolts maybe you should get in touch with @diggit on github : he's working on Rigol driver and he's in search for testers.
Check his PR for more information: https://github.com/ngscopeclient/scopehal/pull/1017
 

Online Hydron

  • Super Contributor
  • ***
  • Posts: 1647
  • Country: gb
Thanks, will try and find time to have a look. I'm also very interested in the work on the RTB2k driver once released - I had a look at modifying the other R&S driver to work with the RTB quite while back but never had a chance to do the work on it myself.
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
Hello Hydron,

I haven't published the driver for the RTB2000, or passed it on to the ngscopeclient project.
I have a GitHub account, so maybe I can create a pull request when the driver is working properly. If you would like to have the code, feel free to send me a message.

At the moment, I have an error when reading or displaying more than 10 kSamples of memory. Until now, I was able to copy and adapt the code from other drivers, but now it's getting more difficult.

Peter
 

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
I'm new to ngscopeclient and I have a question that I hope someone more experienced may be able to answer;

TLDR: Can it make a histogram of pulse heights, like a pulse height analyser? I accept there would be performance limitation compared to real PHA due to increased deadtime from the limits of scope waveforms/sec and data transfer time.
Sometinhg like that @voltsandjolts  ?
 
The following users thanked this post: voltsandjolts

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
I have discovered that with the Raspberry Pi OS (Debian 13, arm64) and P500, I cannot read data larger than ~60 kBytes via USBTMC.
The error ‘data depleted’ is displayed in the terminal by the function ‘SCPITMCTransport::ReadRawData()’.
With the LAN connection, I can read 80 MB without any errors. USBTMC would be faster than LAN.

Peter

Snippet from my log entries:
Code: [Select]
OK
RTB2k: converse() >CHAN1:DATA:POIN MAX;HEAD?< - >-3.0140E-06,3.0136E-06,15070,1<
RTB2k: DATA:HEAD? -> -0.000003,0.000003,15070,1
RTB2k: SCPI-Block Size DATA? -> 60280
RTB2k: Waveform download and processing took 269.233 ms

ERROR
RTB2k: converse() >CHAN1:DATA:POIN MAX;HEAD?< - >-3.0740E-06,3.0736E-06,15370,1<
RTB2k: DATA:HEAD? -> -0.000003,0.000003,15370,1
RTB2k: SCPI-Block Size DATA? -> 61480
ReadRawData: data depleted.
RTB2k: Waveform download and processing took 260.720 ms
 

Online Wiljan

  • Regular Contributor
  • *
  • Posts: 237
  • Country: dk
@Wiljan, @nctnico, @voltsandjolts maybe you should get in touch with @diggit on github : he's working on Rigol driver and he's in search for testers.
Check his PR for more information: https://github.com/ngscopeclient/scopehal/pull/1017
Thank you  :-+ Will give @diggit on github a try and see if he can help
 
The following users thanked this post: fredo_

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
I have discovered that with the Raspberry Pi OS (Debian 13, arm64) and P500, I cannot read data larger than ~60 kBytes via USBTMC.
The error ‘data depleted’ is displayed in the terminal by the function ‘SCPITMCTransport::ReadRawData()’.
Never tested USBTMC but you might need to give transport some time to refill its buffer.
Maybe try something like:

   size_t readBytes = 0;
   uint8_t* resultData = <your read buffer>;
   while(readBytes < len)
   {
      size_t newBytes = m_transport->ReadRawData(len-readBytes,resultData+readBytes,progress);
      // Add some timeout detection / count of zero returns here to prevent locking on protocol errors
      readBytes += newBytes;
   }
 

Offline Xyphro

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: de
    • www.gpibee.com
So the magnova ngscopeclient would support UsbTmc too theoretically?

Note that Magnova has an USBTMC bug. It does not send Zero length frames to signal to the host completion of a USB read packet when it is exactly the size of the endpoint. Proven that issue also by utilizing a USB HW analyzer.

There is a workaround described by me in the Magnova thread:
https://www.eevblog.com/forum/testgear/magnova-oscilloscope/1375/

Reply #1395
Looking for a unique, cheap versatile USB to GPIB adapter with standard USBTMC interface? Build it yourself :-) https://github.com/xyphro/UsbGpib
Or get the more "pro" version: https://www.gpibee.com
Interested in I3C protocol? Check this out: https://github.com/I3CBlaster
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
Maybe try something like:
Thanks for your help. The data is read in one go and the while loop is only executed once. So I can't insert a pause, the error remains.
Since the data is being read and displayed correctly with the LAN connection, I will try to read the digital channels.
The Raspberry Pi is probably not ideal, but it is the only computer on which I can run ngscopeclient at all.

Peter
 

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
So the magnova ngscopeclient would support UsbTmc too theoretically?
It might... on might not!  :-//
There is no USBTMC support for ngscopeclient on Windows, so I don't have the environment to test it...
 

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
Thanks for your help. The data is read in one go and the while loop is only executed once. So I can't insert a pause, the error remains.
What do you mean only once? With the snippet I provided the idea is to loop on ReadRawData() until you get all the expected data bytes.
If you expect 80M you should loop on ReadRawData() until you get all the 80M bytes.
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
Hello fredo_,
I have now changed the test code. 80,000 bytes should be read in. If 0 is returned, ‘sleep’ waits 100 ms. The error message appears for over 60,000 bytes.

Peter

Code: [Select]
size_t readBytes = 0;
size_t len = 2000;
length *= sizeof(float); // length is 20.000 Samples * 4 Bytes = 80.000
size_t count = 0;
uint8_t* resultData = (unsigned char*)cap->m_samples.GetCpuPointer();
while(readBytes < length)
{
count += 1;
size_t newBytes = m_transport->ReadRawData(len,resultData+readBytes);
// Add some timeout detection / count of zero returns here to prevent locking on protocol errors
readBytes += newBytes;
if (newBytes == 0)
{
LogDebug("RTB2k: ReadRawData newBytes = 0, readBytes = %li\n", readBytes);
this_thread::sleep_for(c_readrawdata_delay);
}
if ((len * count) > length)
{
LogDebug("RTB2k: ReadRawData break\n");
break;
}
}
LogDebug("RTB2k: ReadRawData count = %li\n", count);

Log:
Code: [Select]
RTB2k: SCPI-Block Size DATA? -> 80000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
ReadRawData: data depleted.
RTB2k: ReadRawData newBytes = 0, readBytes = 62000
RTB2k: ReadRawData break
RTB2k: ReadRawData count = 41

Edit:
I also tested a program where I programmed the USBTMC protocol myself using libusb-1. I can use it to read and save 40 MB in less than 4 seconds.
« Last Edit: December 23, 2025, 04:19:17 pm by Fenstergucker »
 

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
OK no luck with that lead :-/
Did you try changing transfer size on connection path (see: https://www.ngscopeclient.org/manual/Transports.html#usbtmc ) ?
/dev/usbtmc0:<transfer_size>
This will adjust the number of bytes fetched from usb connection at once.
Default is 2032.
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
I have now tested it with different values, but the error persists.
I changed the ‘SCPITMCTransport::ReadRawData()’ function for ‘usbtmc driver v2’, but this did not improve the situation either.

Peter
 
The following users thanked this post: fredo_

Online Hydron

  • Super Contributor
  • ***
  • Posts: 1647
  • Country: gb
Hello Hydron,

I haven't published the driver for the RTB2000, or passed it on to the ngscopeclient project.
I have a GitHub account, so maybe I can create a pull request when the driver is working properly. If you would like to have the code, feel free to send me a message.

At the moment, I have an error when reading or displaying more than 10 kSamples of memory. Until now, I was able to copy and adapt the code from other drivers, but now it's getting more difficult.

Peter
Thanks, your call RE how to make the driver available, I'm sure it'll be useful to others though. I won't be able to test till February unfortunately as I don't have access to the RTB2K until then (have the Rigol with me as it's more portable).

Any idea on how much slower LAN is than USBTMC? It is much nicer connecting everything via LAN, shame that it is slower.
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
Any idea on how much slower LAN is than USBTMC? It is much nicer connecting everything via LAN, shame that it is slower.

Here is a simple measurement using my own program.

20 MSamples
usbtmc  8 bit:    03.527 s - 20 MB
rawtcp  8 bit:    07.308 s - 20 MB

usbtmc 16 bit:    06.853 s - 40 MB
rawtcp 16 bit:    14.762 s - 40 MB

usbtmc 32 bit:    13.386 s - 80 MB
rawtcp 32 bit:    29.096 s - 80 MB

I read the data with ngscopeclient as 32-bit float. I will change that to 16-bit integer and convert it on the computer, which will be faster.

Peter
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
Just a quick note about the problem with reading data from the RTB2000 with more than 60 kB via USBTMC.
With my programming language PureBasic, I can also use the C functions open/read/write, as they are used in the file ‘SCPITMCTransport.cpp’.
This allows me to read in more than 60 kB of data. Several packets have to be read in. The screenshot shows the 80,000 bytes plus 7 bytes for the SCPI block and 1 byte at the end for termination, resulting in 80,008 bytes.
I don't know yet where the error lies.

Peter
 

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
I think I understand. The function ‘SCPITMCTransport::ReadRawData()’ only returns data from the first packet. Once all data from this packet has been read, ‘m_data_depleted’ is set to true. However, the next time ‘ReadRawData()’ is called, ‘m_data_depleted’ is not reset, and the error ‘data depleted’ is returned. Or something like that, that's how I understand it at the moment.

Peter
 

Offline fredo_Topic starter

  • Regular Contributor
  • *
  • Posts: 207
  • Country: fr
Yep, looks like tough after re-reading the code... SCPITMCTransport assumes that all data will be read in one go, and that does not seem to be the case for you.
Not sure what it will do, but a workaround (without changing the code of SCPITMCTransport) coud be to call SendCommand("") in the read loop to reset the m_data_depleted state ?
 
The following users thanked this post: Fenstergucker

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
I changed the code and can now read data larger than 60 kB via USBTMC without errors. Both variants work.

Peter

Code: [Select]
size_t SCPITMCTransport::ReadRawData(size_t len, unsigned char* buf, std::function<void(float)> progress)
{
// Data in the staging buffer is assumed to always be a consequence of a SendCommand request.
// Since we fetch all the reply data in one go, once all this data has been fetched, we mark
// the staging buffer as depleted and don't issue a new read until a new SendCommand
// is issued.

if (!m_staging_buf || !IsConnected())
return 0;

if (!m_data_depleted)
{
if (m_data_in_staging_buf == 0 || (m_data_in_staging_buf - m_data_offset) < (int)len)
{

if (m_data_in_staging_buf == 0)
m_data_offset = 0;
#if 1
// This is what we'd use if we could be sure that the installed Linux kernel had
// usbtmc driver v2.
int packet = 0;
do
{
m_data_in_staging_buf += read(m_handle, (char *)m_staging_buf + m_data_in_staging_buf, m_staging_buf_size - m_data_in_staging_buf);

if (progress && packet > 0)
progress((float)(m_data_in_staging_buf - m_data_offset) / (float)len);
packet += 1;
} while((m_data_in_staging_buf - m_data_offset) < (int)len);
#else
// Split up one potentially large read into a bunch of smaller ones.
// The performance impact of this is pretty small.
const int max_bytes_per_req = 2032;
int i = m_data_in_staging_buf;
int bytes_fetched, bytes_requested;
int packet = 0;

do
{
do
{
if(m_fix_buggy_driver == false)
{
bytes_requested = (max_bytes_per_req < len) ? max_bytes_per_req : len;
bytes_fetched = read(m_handle, (char *)m_staging_buf + i, m_staging_buf_size - i);
}
else
{
// limit each request to m_transfer_size
bytes_requested = m_transfer_size;
bytes_fetched = read(m_handle, (char *)m_staging_buf + i, m_transfer_size);
}
i += bytes_fetched;
} while(bytes_fetched == bytes_requested);

if (progress && packet > 0)
progress((float)(i - m_data_offset) / (float)len);
packet += 1;
} while((i - m_data_offset) < (int)len);

m_data_in_staging_buf = i;
#endif

if (m_data_in_staging_buf <= 0)
m_data_in_staging_buf = 0;
}

unsigned int data_left = m_data_in_staging_buf - m_data_offset;
if (data_left > 0)
{
int nr_bytes = len > data_left ? data_left : len;

memcpy(buf, m_staging_buf + m_data_offset, nr_bytes);

m_data_offset += nr_bytes;
}

if (m_data_offset == m_data_in_staging_buf)
{
m_data_depleted = true;
}
}
else
{
// When this happens, the SCPIDevice is fetching more data from device than what
// could be expected from the SendCommand that was issued.
LogDebug("ReadRawData: data depleted.\n");
return 0;
}

return len;
}

Edit: I added code to display the progress.
« Last Edit: December 25, 2025, 11:52:17 am by Fenstergucker »
 
The following users thanked this post: egonotto, fredo_

Offline Fenstergucker

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
After spending two days searching for an error because the program crashed when I activated a channel while it was running, the analog channels now work correctly.
As long as no measurements are activated, the CPU is at 3% utilization and the GPU is always at ~28% utilization on the Raspberry Pi 500.
Since I'm struggling quite a bit with C++, I don't know how long it will take me to be able to read the digital channels.

Does anyone know if the bus decoders such as SPI work? I can't use a decoder with the analog channels. Do the decoders only work with the digital channels?

Peter
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->