Products > Test Equipment

siglentRust - software for controlling Siglent devices, written in Rust

(1/1)

TopQuark:
No, this is not a thread about metallic rust found in early Siglent devices, but rather software for controlling Siglent devices, written in Rust.

https://github.com/TopQuark12/siglentRust

I have been playing with data processing for scope waveform captures, and have been quite unhappy with the speed of Python. I want to try things like externally controlled bode plotting, implementing fast DSA spectrum analysis etc. and the slowness of Python is getting into my way.

My current job happens to involve writing embedded software in Rust, so I thought I'd practice my Rust coding skills with this project. For the uninitiated, Rust is a compiled programming language with strong emphasis on memory safety, making it harder to have memory fk ups in the program, yet it compiles into code that runs practically just as fast as C/C++.

I have made some comparisons between Python and Rust doing the same thing, capturing a waveform and plotting it into PNG. Note that both code aren't very optimised, it is just written with best effort to my limited ability.

20Mpts 2GSa/s 12-bit
Python: 17.703s
Rust: 5.865s

200Mpts 2GSa/s 12-bit
Python: 236.24s
Rust: 56.083s

So Rust is around 3-4 times faster, which matters if you are impatient like me I guess.

Not sure how far I'll develop this, and the code is very crude at its current state. But I thought I'd document the existence of the work, both as a bit of an academic curiosity, and so people can at least use the code as an example (or counter-example) in their own scripting setups.

TopQuark:
Pulled out my 8 bit SDS2000x plus and did some testing, fixed some bugs.

On the SDS2000x plus, here are some benchmarks with the rust code:
2Mpts 2GSa/s 8-bit           0.884 sec
20Mpts 2GSa/s 8-bit         3.769 sec
200Mpts 2GSa/s 8-bit       36.608 sec

pope:
Nice.

So this means that it could possibly work on 8-bit scopes like the 1104x-e for example?

tautech:

--- Quote from: pope on November 02, 2022, 09:28:25 pm ---Nice.

So this means that it could possibly work on 8-bit scopes like the 1104x-e for example?

--- End quote ---
There are several preexisting SW packages that work with Siglent devices:
https://int.siglent.com/download/drivers/

And an amount of free SW:
https://int.siglent.com/download/softwares/

Then for instruments with a webserver and SCPI command panel the programming guides can be found here:
https://int.siglent.com/download/documents/

TopQuark:

--- Quote from: pope on November 02, 2022, 09:28:25 pm ---Nice.
So this means that it could possibly work on 8-bit scopes like the 1104x-e for example?

--- End quote ---
Yes, more likely than not it should work, unless Siglent bungles up their SCPI implementation in the 1104x-e. I spent quite some time debugging my code yesterday, only to discover my 8-bit sds2504x plus self reports it has 127 LSB per vertical division  :scared: . Upgraded its firmware and now it reports 30 LSB per div, and the math now works fine. So give it a shot, make sure you have the latest FW, and report back any success or otherwise.


--- Quote from: tautech on November 02, 2022, 09:48:35 pm ---
--- Quote from: pope on November 02, 2022, 09:28:25 pm ---Nice.

So this means that it could possibly work on 8-bit scopes like the 1104x-e for example?

--- End quote ---
There are several preexisting SW packages that work with Siglent devices:
https://int.siglent.com/download/drivers/

And an amount of free SW:
https://int.siglent.com/download/softwares/

Then for instruments with a webserver and SCPI command panel the programming guides can be found here:
https://int.siglent.com/download/documents/

--- End quote ---

Don't get me bloody started on Siglent's remote programming resources, or this will become a rant post. Their VISA implementation causes the scope to hang and report junk data half of the time, the only reliable way to talk to the device is through sockets.

And look at this example python code from Siglent's own programming manual.

--- Code: ---convert_data = []
if BIT[MODEL] > 8:
    for i in range(0, int(len(recv_all) / 2)):
        data_16bit = recv_all[2 * i + 1] * 256 + recv_all[2 * i]
        data = data_16bit >> (16-BIT[MODEL])
        convert_data.append(data)
else:
    convert_data = recv_all
    volt_value = []
for data in convert_data:
    if data > pow(2,BIT[MODEL]-1)-1:#12bit-2047,8bit-127
        data = data - pow(2,BIT[MODEL])
    else:
        pass
    volt_value.append(data)
del recv,recv_all,convert_data
gc.collect()

--- End code ---

especially these two lines

--- Quote ---
--- Code: ---if data > pow(2,BIT[MODEL]-1)-1:#12bit-2047,8bit-127
        data = data - pow(2,BIT[MODEL])

--- End code ---

--- End quote ---

Look, my favourite programming language is solder, and I self identify as an EE, not a programmer. But this is beyond hopeless

- Calculating 2 to the power of bit depth for every single data point (there are literally hundreds of millions of data points) , TWICE per loop, instead of calculating it once outside of the loop. And it is Python, so not like there's a compiler to optimise that bit of code away. WHY?

- The person that wrote this piece of gem has likely slept through programming 101 class and never heard of 2's complement. Why else would someone in their right mind write this instead of just casting the one or two u8 into signed integers?

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod