46 int main(
int argc,
char *argv[])
52 if (argc >= 2 && std::string(argv[1]) !=
"-h")
59 std::string devid=argv[k++];
75 std::shared_ptr<GenApi::CNodeMapRef> nodemap=dev->getRemoteNodeMap();
81 std::string devfile=argv[k++];
85 std::vector<std::string> list;
88 for (
size_t i=0; i<list.size(); i++)
90 std::cout << list[i] << std::endl;
106 std::ifstream in(file);
108 buffer << in.rdbuf();
109 std::string data=buffer.
str();
111 std::cout <<
"Input file length: " << data.size() << std::endl;
116 if (rf.
openFile(devfile.c_str(), std::ios::out))
118 size_t n=rf.
write(data.c_str(), 0, data.size(), devfile.c_str());
120 std::cout <<
"Status: " <<
rcg::getString(nodemap,
"FileOperationStatus") << std::endl;
122 if (n != data.size())
124 std::cerr <<
"Error: Can only write " << n <<
" of " << data.size() <<
" bytes" << std::endl;
131 std::cerr <<
"ERROR: Failed to open remote file!" << std::endl;
134 else if (op ==
"-r" || op ==
"")
141 if (rf.
openFile(devfile.c_str(), std::ios::in))
144 std::cout <<
"File size: " << n << std::endl;
145 std::vector<char> buffer(n);
147 n=rf.
read(buffer.data(), 0, buffer.size(), devfile.c_str());
149 std::cout <<
"Status: " <<
rcg::getString(nodemap,
"FileOperationStatus") << std::endl;
151 if (n == buffer.size())
157 std::ofstream out(file);
158 out.write(buffer.data(), buffer.size());
165 std::cout.write(buffer.data(), buffer.size());
170 std::cerr <<
"Error: Can only read " << n <<
" of " << buffer.size() <<
" bytes" << std::endl;
177 std::cerr <<
"Error: Cannot open remote file: " << devfile << std::endl;
182 std::cerr <<
"Error: Expected parameter '-r' or '-w'!" << std::endl;
189 std::cerr <<
"Error: More parameters expected!" << std::endl;
197 std::cerr <<
"Error: Device '" << devid <<
"' not found!" << std::endl;
203 std::cerr <<
"Error: Device name not given!" << std::endl;
209 std::cout << argv[0] <<
" -h | [<interface-id>:]<device-id> -f | (<device-file> [-w|-r <file>])" << std::endl;
210 std::cout << std::endl;
211 std::cout <<
"Downloading or uploading a file via GenICam." << std::endl;
212 std::cout << std::endl;
213 std::cout <<
"-h Prints help information and exits" << std::endl;
214 std::cout <<
"-f Lists names of files on the device" << std::endl;
215 std::cout <<
"-w <file> Writes the given local file into the selected file on the device" << std::endl;
216 std::cout <<
"-r <file> Reads the selected file on the device and stores it as local file" << std::endl;
217 std::cout << std::endl;
218 std::cout <<
"The selected file is printed on std out if none of -f, -w and -r are given." << std::endl;
222 catch (
const std::exception &ex)
224 std::cerr << ex.what() << std::endl;
229 std::cerr << ex.
what() << std::endl;
std::shared_ptr< Device > getDevice(const char *id)
Searches across all transport layers and interfaces for a device.
Definition of ODevFileStream and IDevFileStream.
Adapter between the std::iostreambuf and the SFNC Features representing the device filesystem...
int64_t getInteger(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, int64_t *vmin, int64_t *vmax, bool exception, bool igncache)
Get the value of an integer feature of the given nodemap.
virtual GenICam_streamsize write(const char *buf, int64_t offs, int64_t len, const char *pFileName)
writes data into a file
static void clearSystems()
Clears the internal list of systems.
std::string getEnum(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception)
Get the value of an enumeration of the given nodemap.
int main(int argc, char *argv[])
virtual bool openFile(const char *pFileName, std::ios_base::openmode mode)
open a file on the device
virtual bool attach(GENAPI_NAMESPACE::INodeMap *pInterface)
attach file protocol adapter to nodemap
virtual GenICam_streamsize read(char *buf, int64_t offs, GenICam_streamsize len, const char *pFileName)
read data from the device into a buffer
GenICam's exception class.
std::string getString(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char *name, bool exception, bool igncache)
Get the value of a feature of the given nodemap.
virtual bool closeFile(const char *pFileName)
close a file on the device
virtual const char * what() const
Get error description (overwrite from std:exception)