Skip to content

Instantly share code, notes, and snippets.

@StefanoBelli
Created August 26, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanoBelli/fb65543553ce48dbd2744c513b3935e2 to your computer and use it in GitHub Desktop.
Save StefanoBelli/fb65543553ce48dbd2744c513b3935e2 to your computer and use it in GitHub Desktop.
SANE API usage example
// SANE API usage example
// link against libsane
// --> http://www.sane-project.org/html/doc012.html
#include <sane/sane.h>
#include <stdio.h>
int main() {
//
// Initialize SANE
//
SANE_Int version;
sane_init(&version, NULL);
//
// Request SANE backend to perform device lookup
// and retrieve a list
//
SANE_Device** devices;
sane_get_devices((const SANE_Device***)&devices, 0);
do {
printf("found: %s\n", (*devices)->vendor);
} while(*(++devices));
devices--;
//
// Open selected devices, get an handle to that
//
SANE_Handle hnd;
sane_open((*devices)->name, &hnd);
//
// Start scanning
//
sane_start(hnd);
//
// Read scanning data
//
SANE_Int len;
SANE_Byte data[1024];
sane_read(hnd, data, 1024, &len);
printf("%d\n", len);
//
// We're done, cleanup...
//
sane_exit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment