This project has moved and is read-only. For the latest updates, please go here.

Custom capability and String

Sep 10, 2014 at 10:34 AM
Hi,
I'm sorry for my bad English.
How can I pass a string to a custom capability?

This code not work:
   TwCap TestoCap = (TwCap)0x8002;
   TwQC temp = this._twain.IsCapSupported(TestoCap);
   if ((temp&TwQC.GetCurrent) != 0)
   {
      this._twain.SetCap(TestoCap, "prova");
   }
Thanks
Sep 10, 2014 at 12:03 PM
Hello, silog.
What exactly does not work? What error are you getting? Specify the type of the exception and the stack trace.
Sep 10, 2014 at 4:16 PM
Thanks for your response.

The type exception is "KeyNotFoundException" (TwainDefs.cs -> TwTypeHelper -> TypeOf(Type type))
            internal static TwType TypeOf(Type type) {
            Type _type=type.IsEnum?Enum.GetUnderlyingType(type):type;
            foreach(var _item in TwTypeHelper._typeof) {
                if(_item.Value==_type) {
                    return _item.Key;
                }
            }
            if(type==typeof(bool)) {
                return TwType.Bool;
            }
            if(type==typeof(float)) {
                return TwType.Fix32;
            }
            if(type==typeof(RectangleF)) {
                return TwType.Frame;
            }
            throw new KeyNotFoundException();
        }
if I add this code (only for testing), exception is not throw but device not print "prova"
            if (type == typeof(String))
            {
                return TwType.Str32;
            }
Sep 10, 2014 at 9:56 PM
Hello, silog.
I implemented capabilities with string values. See latest source code.

Try follow code:
TwCap _capId=(TwCap)0x8002;
if((this._twain32.IsCapSupported(_capId)&TwQC.Set)!=0) {
    this._twain32.SetCap(_capId,"string value".PadLeft(32,'\0')/*TW_STR32*/);
}
Sep 17, 2014 at 9:38 PM
Hi,
thanks for your reply and for your work.
I download and compiled the latest sorce code, unfortunately this solution not work for me... None exception is throw but device not print "string value"
Sep 18, 2014 at 8:55 AM
Hello, silog.
Why did you decide that this a custom capability supported by your device, and whether there is a description of this a custom capability?
Sep 18, 2014 at 1:50 PM
Edited Sep 18, 2014 at 1:51 PM
Hi Saraff,

In "Twain reference manual" of device, in section "Custom capabilities" it's wrote:
0x8002 
Type : TW_STR255
Container : TW_ONEVAL
Default value : “”
Note. The string has to be specified in a suitable syntax in order to exploit the barcode printing feature. The string segments that have to be printed in plain text must be preceded by the substring “\t” (in C/C++ code it will be “\\t”), whereas the string segments that have to be printed in barcode must be preceded by the substring “\b” (in C/C++ code it will be “\\b”). The backslash “\” printing is done by the substring “\\”(in C/C++ code it will be “\\\\”).
Ex. : “\tText.\bBarcode.” (in C/C++ code it will be “\\tText.\\bBarcode.”).
But also if I use this code not work
TwCap _capId=(TwCap)0x8002;
if((this._twain32.IsCapSupported(_capId)&TwQC.Set)!=0) {
    this._twain32.SetCap(_capId,"\\tstring value \\b123456".PadLeft(255,'\0')/*TW_STR255*/);
}
Thanks
Sep 18, 2014 at 3:10 PM
Edited Sep 18, 2014 at 3:13 PM
Hello, silog.
Execute follow code
string _name=this._twain32.GetSourceProductName(this._twain32.SourceIndex);
string _value=this._twain32.IsCapSupported((TwCap)0x8002).ToString();
and show values of the _name and _value variables
Sep 18, 2014 at 3:40 PM
Hi Saraff,
these are the results
_name = "MicroRE"
_value = "Get, Set, GetDefault, GetCurrent, Reset"
Thanks
Sep 18, 2014 at 10:33 PM
Hello, silog.
Try follow code
TwCap _capId=(TwCap)0x8002;
if((this._twain32.IsCapSupported(_capId)&TwQC.Set)!=0) {
    this._twain32.SetCap(_capId,"\\tstring value \\b123456".PadRight(255,'\0')/*TW_STR255*/);
}
Marked as answer by SARAFF on 9/19/2014 at 10:26 AM
Sep 19, 2014 at 1:48 PM
EUREKA, Work!

Thanks for your help and for the work you are doing