Exemplo n.º 1
0
 /// <summary>
 /// Check whether the given option descriptor supports the given capability
 /// </summary>
 /// <param name="des">
 /// A <see cref="API.SANE_Option_Descriptor"/>
 /// </param>
 /// <param name="cap">
 /// A <see cref="API.SANE_Capability"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public static bool hasCapability(API.SANE_Option_Descriptor des,API.SANE_Capability cap)
 {
     return (des.cap & cap) != API.SANE_Capability.NONE;
 }
Exemplo n.º 2
0
 public static Status wrap(API.SANE_Status s)
 {
     if(_cache == null)
     {
         _cache = new Dictionary<API.SANE_Status, Status>();
     }
     if(_cache.Keys.Count > 5)
     {
         Debugging.Debug.WriteLine(TAG,"Clear Status Cache");
         _cache.Clear();
     }
     if(!_cache.ContainsKey(s))
     {
         Debugging.Debug.WriteLine(TAG,"Status Cache -- Grow");
         _cache.Add(s,new Status(s));
     }
     return _cache[s];
 }
Exemplo n.º 3
0
 /// <summary>
 /// Retrieve an array of the string representations of the valid options for the given descriptor
 /// </summary>
 /// <param name="desc">
 /// A <see cref="API.SANE_Option_Descriptor"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.String[]"/>
 /// </returns>
 public static string[] getValidOptionStringList(API.SANE_Option_Descriptor desc)
 {
     IntPtr strList=desc.string_list;
     int count = 0;
     while(Marshal.ReadIntPtr(strList,count*IntPtr.Size) != IntPtr.Zero)
     {
         ++count;
     }
     if(count < 0)
     throw new ArgumentOutOfRangeException("Count","< 0");
     string[] members = new string[count];
     for(int i = 0; i < count;++i)
     {
         IntPtr s = Marshal.ReadIntPtr(strList,i*IntPtr.Size);
         //members[i] = PtrToDevice(s);
         members[i]=Marshal.PtrToStringAuto(s);
     }
     return members;
 }
Exemplo n.º 4
0
 public static Option wrap(IntPtr handle,API.SANE_Option_Descriptor desc,int index)
 {
     Option o = new Option(handle);
     o._innerDesc=desc.desc;
     o._innerName=desc.name;
     o._innerSize=desc.size;
     o._innerTitle=desc.title;
     o._innerCap = (Capabilities)desc.cap;
     o._constraint = (Constraint)desc.constraint_type;
     o._validOpString = Helpers.getValidOptionsStr(desc);
     o._innerDescriptor = desc;
     o.opIndex=index;
     o.type = (OptionType)desc.type;
     return o;
 }
Exemplo n.º 5
0
 private Range(API.SANE_Range range)
 {
     _innerRange=range;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Check if the given SANE_Frame is a basic frame
 /// </summary>
 /// <param name="frame">
 /// A <see cref="API.SANE_Frame"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 private static bool is_basicframe(API.SANE_Frame frame)
 {
     return (frame == API.SANE_Frame.SANE_FRAME_GRAY||
             frame == API.SANE_Frame.SANE_FRAME_RGB||
             frame == API.SANE_Frame.SANE_FRAME_RED||
             frame==API.SANE_Frame.SANE_FRAME_GREEN||
             frame== API.SANE_Frame.SANE_FRAME_BLUE);
 }
 public InvalidStatusException(API.SANE_Status innerStatus)
     : base(Sane.Status.wrap(innerStatus).description)
 {
     _innerStatus=Sane.Status.wrap(innerStatus);
 }
Exemplo n.º 8
0
 public static bool getOptionBool(IntPtr handle,API.SANE_Device d, int num)
 {
     IntPtr ptr = getOption(handle,num);
     if(ptr == IntPtr.Zero)return false;
     return (ptr.ToInt32() == 1);
 }
Exemplo n.º 9
0
 public static double getOptionFixed(IntPtr handle,API.SANE_Device d, int num)
 {
     IntPtr ptr = getOption(handle,num);
     if(ptr.Equals(IntPtr.Zero))return 0d;
     int l = ptr.ToInt32();//Marshal.ReadInt32(getOption(handle,d,num));
     return unfix(l);
 }
Exemplo n.º 10
0
 private void _fireStatus(API.SANE_Status s)
 {
     _fireStatus(Status.wrap(s));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Retrieve a pointer to the value of the option at the given index for the given device
 /// </summary>
 /// <param name="handle">
 /// A <see cref="IntPtr"/>
 /// </param>
 /// <param name="d">
 /// A <see cref="API.SANE_Device"/>
 /// </param>
 /// <param name="num">
 /// A <see cref="System.Int32"/>
 /// </param>
 /// <returns>
 /// A <see cref="IntPtr"/>
 /// </returns>
 public static IntPtr getOption(IntPtr handle,API.SANE_Device d, int num)
 {
     API.SANE_Option_Descriptor desc = getOptionDescriptor(API.sane_get_option_descriptor(handle,num));
     if(desc.size == 0)return IntPtr.Zero;
     IntPtr vPtr = IntPtr.Zero;
     int nAction=0;
     API.SANE_Status status=API.sane_control_option(handle,num,0,out vPtr,ref nAction);
     assert_status(status);
     if(vPtr.Equals(IntPtr.Zero))
     {
         return IntPtr.Zero;
     }
     return vPtr;
 }
Exemplo n.º 12
0
 public static Parameters Wrap(API.SANE_Parameters p)
 {
     Parameters my_p = new Parameters();
     my_p._innerParameters=p;
     return my_p;
 }
Exemplo n.º 13
0
 public CoreException(string message,API.SANE_Status _status)
     : base(message)
 {
     _innerStatus=_status;
 }
Exemplo n.º 14
0
 public CoreException(API.SANE_Status _status)
     : base("No message given")
 {
     _innerStatus=_status;
 }
Exemplo n.º 15
0
        /// <summary>
        /// Print all options in a format similar to that of scanimage
        /// </summary>
        /// <param name="handle">
        /// A <see cref="IntPtr"/>
        /// </param>
        /// <param name="d">
        /// A <see cref="API.SANE_Device"/>
        /// </param>
        public static void printOptions(IntPtr handle,API.SANE_Device d)
        {
            int cnt = getOptionInt(handle,d,0);
            Console.WriteLine("{0} has {1} Options",d.name,cnt.ToString());
            for(int i = 1; i<cnt;++i)
            {
                API.SANE_Option_Descriptor desc = getOptionDescriptor(handle,i);
                //Set default values if capable
                string advstr="";
                if(hasCapability(desc,API.SANE_Capability.ADVANCED))
                {
                    //Console.WriteLine("HAS AUTO CAP");
                    advstr="(ADVANCED)";
                }
                string mval="";
                switch(desc.type)
                {
                case API.SANE_Value_Type.STRING:
                    mval=getOptionStr(handle,i);
                    break;
                case API.SANE_Value_Type.BOOL:
                    mval=(getOptionBool(handle,i)?"TRUE":"FALSE");
                    break;
                case API.SANE_Value_Type.INT:
                    mval=getOptionInt(handle,d,i).ToString();
                    break;
                case API.SANE_Value_Type.FIXED:
                    //mval=getOptionFixed(handle,d,i).ToString();
                    mval=string.Format("{0}",System.Math.Round(getOptionFixed(handle,d,i),2));
                    //mval=getOptionStr(handle,d,i);
                    break;
                case API.SANE_Value_Type.GROUP:
                    continue;
                case API.SANE_Value_Type.BUTTON:
                    mval="[BUTTON]";
                    break;
                default:
                    mval="[UNKNOWN TYPE]";
                    break;
                }
                if(hasCapability(desc,API.SANE_Capability.INACTIVE))continue;
                setDefault(handle,i);
                Console.WriteLine("OP: {0} {1}",desc.title,advstr);
                Console.WriteLine("\tName: {0}",desc.name);
                Console.WriteLine("\tDesc: {0}",desc.desc);
                Console.WriteLine("\tSize: {0}",desc.size.ToString());
                Console.WriteLine("\ttype: {0}",desc.type.ToString());
                Console.WriteLine("\tuint: {0}",desc.unit.ToString());
                Console.WriteLine("\tValue: {0}",mval);
                if(desc.constraint_type != API.SANE_Constraint_Type.SANE_CONSTRAINT_NONE)
                {
                    Console.WriteLine("\tPossible: {0}",getValidOptionsStr(desc));
                }
                Console.WriteLine("--------------------------------------");

            }
        }
Exemplo n.º 16
0
 public static int getOptionInt(IntPtr handle,API.SANE_Device d, int num)
 {
     IntPtr ptr = getOption(handle,num);
     if(ptr == IntPtr.Zero)return 0;
     return ptr.ToInt32();
 }
Exemplo n.º 17
0
 /// <summary>
 /// Throw a System.Exception if the given status is not SANE_STATUS_GOOD
 /// </summary>
 /// <param name="s">
 /// A <see cref="API.SANE_Status"/>
 /// </param>
 private static void assert_status(API.SANE_Status s)
 {
     if(!status_ok(s))
     {
         throw new Exception("BAD STATUS: " + getStatusStr(s));
     }
 }
Exemplo n.º 18
0
        public static string getOptionStr(IntPtr handle,API.SANE_Device d, int num)
        {
            StringBuilder val = new StringBuilder("");
            int action=0;
            API.sane_control_option(handle,num,0,val,ref action);

            return val.ToString();
        }
Exemplo n.º 19
0
 /// <summary>
 /// Check if the given status == SANE_STATUS_GOOD
 /// </summary>
 /// <param name="s">
 /// A <see cref="API.SANE_Status"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 private static bool status_ok(API.SANE_Status s)
 {
     return s == API.SANE_Status.SANE_STATUS_GOOD;
 }
Exemplo n.º 20
0
 public static string getStatusStr(API.SANE_Status status)
 {
     IntPtr ptr = API.sane_strstatus(status);
     return Marshal.PtrToStringAnsi(ptr);
 }
 public InvalidStatusException(string message,API.SANE_Status innerStatus)
     : base(message)
 {
     this._innerStatus=Sane.Status.wrap(innerStatus);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Retrieve the range of acceptable values for the given descriptor
        /// </summary>
        /// <param name="desc">
        /// A <see cref="API.SANE_Option_Descriptor"/>
        /// </param>
        /// <returns>
        /// A <see cref="API.SANE_Range"/>
        /// </returns>
        public static API.SANE_Range getValidOptionRange(API.SANE_Option_Descriptor desc)
        {
            IntPtr rPtr = desc.string_list;
            API.SANE_Range range = (API.SANE_Range)Marshal.PtrToStructure(rPtr,typeof(API.SANE_Range));

            return range;
        }
Exemplo n.º 23
0
        public static Device Wrap(API.SANE_Device d)
        {
            Device r = new Device();
            r._innerMake = d.vendor;
            r._innerModel=d.model;
            r._innerName=d.name;
            r._innerType=d.type;
            //r._innerDevice = d;
            IntPtr handle = r.open();
            string curGroup="global";

            int count = Helpers.getOptionInt(handle,d,0);
            Debugging.Debug.WriteLine(TAG,r.name + " Has " + count.ToString() + " Options");
            for(int i =1;i<count;i++)
            {
                Option o = Option.wrap(handle,Helpers.getOptionDescriptor(handle,i),i);
                Debugging.Debug.WriteLine(TAG,"Load option {0} (TYPE:{1}, CAP:{2})",o.name,o.type,o.capability);
                if(o.type!=Option.OptionType.GROUP)
                {
                    if(!o.hasCapability(Option.Capabilities.INACTIVE))
                    {
                        if(!r._options.ContainsKey(curGroup))
                        {
                            r._options.Add(curGroup,new List<Option>());
                        }
                        if(r._options[curGroup] == null)
                        {
                            r._options[curGroup] = new List<Option>();
                        }
                        r._options[curGroup].Add(o);
                    }
                }else{
                    curGroup = o.title;
                    r._options.Add(curGroup,new List<Option>());

                }
            }
            //API.sane_close(handle);
            return r;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Prints a pipe delimited list of acceptable values for the given descriptor
        /// </summary>
        /// <param name="desc">
        /// A <see cref="API.SANE_Option_Descriptor"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public static string getValidOptionsStr(API.SANE_Option_Descriptor desc)
        {
            if(desc.constraint_type == API.SANE_Constraint_Type.SANE_CONSTRAINT_STRING_LIST)
            {
                IntPtr strList=desc.string_list;
                int count = 0;
                while(Marshal.ReadIntPtr(strList,count*IntPtr.Size) != IntPtr.Zero)
                {
                    ++count;
                }
                if(count < 0)
                throw new ArgumentOutOfRangeException("Count","< 0");
                if(strList == IntPtr.Zero)
                    return "";
                string[] members = new string[count];
                for(int i = 0; i < count;++i)
                {
                    IntPtr s = Marshal.ReadIntPtr(strList,i*IntPtr.Size);
                    //members[i] = PtrToDevice(s);
                    members[i]=Marshal.PtrToStringAuto(s);
                }
                return string.Join("|",members);
            }else if(desc.constraint_type == API.SANE_Constraint_Type.SANE_CONTRAINT_RANGE)
            {
                IntPtr rPtr = desc.string_list;
                API.SANE_Range range = (API.SANE_Range)Marshal.PtrToStructure(rPtr,typeof(API.SANE_Range));
                if(desc.type == API.SANE_Value_Type.FIXED)
                {
                    return "Range: " + Math.Round(unfix(range.min),2).ToString() + "..." + Math.Round(unfix(range.max),2);
                }
                return "RANGE: " + range.min.ToString() + "..." + range.max.ToString();

            }else if(desc.constraint_type == API.SANE_Constraint_Type.SANE_CONTRAINT_WORD_LIST)
            {
                //return "*** WORD ***";
                //WORD is a list of integers
                IntPtr strList=desc.string_list;
                int count = 0;
                while(Marshal.ReadIntPtr(strList,count*sizeof(int)) != IntPtr.Zero)
                {
                    ++count;
                }
                if(count < 0)
                throw new ArgumentOutOfRangeException("Count","< 0");
                if(strList == IntPtr.Zero)
                    return "";
                string[] members = new string[count-1];
                for(int i = 1; i < count;++i)
                {
                    int myint = Marshal.ReadInt32(strList,i*sizeof(int));
                    members[i-1] = myint.ToString();
                }
                return string.Join("|",members);
            }else{
                return "";
            }
            return "";
        }
Exemplo n.º 25
0
 public static Range wrap(API.SANE_Range range)
 {
     return new Range(range);
 }
Exemplo n.º 26
0
 public Status(API.SANE_Status s)
 {
     _innerCode=(int)s;
     _innerDescription=Helpers.getStatusStr(s);
 }