Improvement of speed for code for hex serial command list
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
First of all, sorry for my bad english writing.
My matlab versions are 2015b and 2016a.
Followed by my previous question https://www.mathworks.com/matlabcentral/answers/340723-serial-communication-with-hex-code, I am writing to ask another questions regarding my code as attached file.
Also, I am sorry that I cannot clarify company/model of my device and cannot show a document including details for serial command list and explanation, because the manufacturer indicated that this document is confidential document.
Now, anyway, communication between computer and my sensor device is good.
The variable 'data' is usually 41*2 or 40*2 depending on existence of escape octet, 7D, when I send the command list in the variable 'Str' (so variable 'D').
The part of the command list ('Str'), '2B', '01', '01', is for auto-output from the device to the computer.
So, principly, I do not need to send the command list again everytime, because the device send (or I can use fread() I think) every 1 second once I send the command list at a very first time.
However, when I did not send it again, 'data' length is very weird. (It goes up to 512*2 and varies a lot from 40*2 to 512*2)
This is first question. Why it is?. Did I make any mistake you think?
Another question is that this code might be in-effective. So, please suggest any solution to improve running speed for this code.
Last question is...... if you can convert this code into C or C++, please help me.
I think I can improve running speed by compiling C code into mex file.
Thanks
0 Kommentare
Antworten (2)
Yuebin Zhou
am 26 Mai 2017
Can you provide more details to the first question? The second question about performance optimization would also depend on how the code is like.
Regarding code conversion, if the code is in MATLAB, you may be able to use code generation toolboxes to generate C/C++ code, but note that not all functions are supported by code generation.
If you want to rewrite your MATLAB code with equivalent C code, then you can MEX it referring to the link below
https://www.mathworks.com/help/matlab/matlab_external/introducing-mex-files.html
However, MEX is mainly used for bringing C code to MATLAB. As far as performance is concerned, it may not be always boosted, which is a common confusion.
Walter Roberson
am 26 Mai 2017
Do not convert to binary and back to invert the bit: use bitxor() with 2^5
fprintf('%02x',value) might be faster than dec2hex
0 Kommentare
Siehe auch
Kategorien
Mehr zu Troubleshooting in MATLAB Compiler SDK finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!