Hello,
I am trying to access the SD card that I have on my Ixora board with Apalis iMX6 trough C++ code written in VS Code with ApolloX.
I can see that the SD Card is mounted and I can access it wtrough SSH with the torizon user.
I also did the changes mentioned in this ticket
This is the VS Code I am using
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream file("/var/rootdirs/media/A68C-7007/zdr.txt");
if (!file.is_open()) {
std::cout << "Error opening file" << std::endl;
// std::cerr << "Error opening file" << std::endl;
return 1;
}
std::string line;
while (std::getline(file, line)) {
std::cout << line << std::endl;
}
file.close();
return 0;
}
And this is what I get:
Error opening file
[Inferior 1 (process 38) exited with code 01]
The program ‘~/app/pesho’ has exited with code 1 (0x00000001).
The path should be as the one that I put but I do not know if that’s not the problem what could be.
Any help would be appreciated.
Hi @Svetoslav ,
Did you bind mount /media
when running your container? Given that the application you’re developing will run inside of a container, by default it can’t see any outside devices, so you need to mount their respective directories in your docker-compose.yml
file.
To do this add the following lines in each service
in docker-compose.yml
:
volumes:
- type: bind
source: /media
target: /media
For instance, I did an example C++ project using ApolloX, and my docker-compose.yml
looks like this:
version: "3.9"
services:
cppfileaccess-debug:
build:
context: .
dockerfile: Dockerfile.debug
image: ${LOCAL_REGISTRY}:5002/cppfileaccess-debug:${TAG}
ports:
- 2230:2230
volumes:
- type: bind
source: /media
target: /media
cppfileaccess:
build:
context: .
dockerfile: Dockerfile
image: ${DOCKER_LOGIN}/cppfileaccess:${TAG}
volumes:
- type: bind
source: /media
target: /media
You should also change the path referenced in your source file to /media/A68C-7007/zdr.txt
, as we mounted /media
in TorizonCore (this being a symlink to /var/rootdirs/media
) to /media
inside the container. So the app only sees /media
.
With this and using your code I was able to read data inside of an SD card with the same hardware configuration as yours, Apalis iMX6 with Ixora carrier board.
See if this helps you.
Best regards,
Lucas Akira
Hello,
Thank you for the fast response.
Indeed I hadn’t done the step that you mentioned. When I did it I was able to read and write from the memory.
Thank you.