Raspberry does not write in a created file
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I want creat a dataloger with raspberry pi. So I'm trying to create a file and write something on it. But my script only works when run on matlab. When run in a standalone mode the scrip only creat a empty file.
function creatFILE() %#codegen
% Create a Raspberry Pi object
r = raspi('169.254.0.2','pi','matlab');
data_atual = strip(system(r, 'date +"%d_%b_%y_%H_%M_%S"'));
doc_name = "Documents/dataLOG_" + data_atual;
system(r, convertStringsToChars("touch " + doc_name));
system(r, convertStringsToChars("sudo chown pi:pi " + doc_name));
system(r, convertStringsToChars("sudo chmod 777 " + doc_name));
for count = 1:100
system(r, 'sleep 0.5');
nanosegundos = strip(system(r, 'date +"%H_%M_%S_%N"'));
system(r, convertStringsToChars("echo " + nanosegundos + " >> " + doc_name));
system(r, 'sleep 0.5');
nanosegundos = strip(system(r, 'date +"H_%M_%S_%N"'));
system(r, convertStringsToChars("echo " + nanosegundos + " >> " + doc_name));
end
end
The result when it runs in standalone mode is a empty file:
댓글 수: 0
채택된 답변
Ryan Livingston
2019년 7월 25일
편집: Ryan Livingston
2019년 7월 25일
This is because of a bug in the Raspberry Pi system command in codegen. It doesn't trim the output to the proper size and instead returns a very large char array filled with zeros after the actual content. If I trim out the zeros then I get the expected behavior in the generated code:
data_atual = system(r, 'echo hello');
% Work around system issue
data_atual = deblank(data_atual(data_atual ~= 0));
nanosegundos = system(r, 'date +"%H_%M_%S_%N"');
% Work around system issue
nanosegundos = deblank(nanosegundos(nanosegundos ~= 0));
This problem has been reported to the development team so it can be fixed. Note that I've also changed strip to deblank because of another issue with strip. That's also been reported.
Thanks for taking the time to tell us about these issues.
댓글 수: 2
추가 답변 (1개)
Walter Roberson
2019년 7월 24일
Code generation for system() applied to a raspi object would generate host code for ssh into the pi. I would expect that when you generate code for deployment that it would ignore the operation -- though I cannot rule out the possibility that the Pi would attempt to shell into itself.
You should be using coder.ceval() to make C library calls and system calls -- or possibly to run a shell script that you pass the document name into.
댓글 수: 2
Ryan Livingston
2019년 7월 25일
This is incorrect. The generated executable runs directly on the Raspberry Pi and runs the system comand there.
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!