twain / twain-direct-android

Java framework and application for TWAIN Direct on Android
MIT License
12 stars 4 forks source link

How to use USB scan #4

Open JakeWoki opened 4 years ago

Mghanem91 commented 2 years ago

Hey, @JakeWoki did you find a way to use USB for scanning?

JakeWoki commented 2 years ago
        val usbManager = getApplication<Application>().getSystemService(Context.USB_SERVICE) as UsbManager?
        if (usbManager == null) {
            _readIdCardEvent.value = Event(Results.Error(TypeCastException(getString(R.string.id_card_err))))
        } else {
            val deviceList: HashMap<String, UsbDevice> = usbManager.deviceList
            for ((_, value) in deviceList) {
                if (value.vendorId == 1024 && value.productId == 50005) {
                    val var10 = value.getInterface(0)
                    _endpointWrite = var10.getEndpoint(0)
                    _endpointRead = var10.getEndpoint(1)
                    Intrinsics.checkExpressionValueIsNotNull(_endpointRead, "endpointRead")
                    _connection = usbManager.openDevice(value)
                    _connection?.claimInterface(var10, true)
                    return
                }
            }
            _readIdCardEvent.value = Event(Results.Error(TypeCastException(getString(R.string.id_card_err))))
        }

You can try this. It's been too long, and I forgot

ghadeerAqraa commented 2 years ago

@JakeWoki Hi How to discover the scanner using USB connected as I understand the twain direct is working with network and to start the session we need the scanner ip can you help ? your help is more than appreciated

JakeWoki commented 2 years ago

Porting Linux to Android, and it's very difficult.Or use WIFI or use SDK.

WIFI use reference

        val xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<scan:ScanSettings xmlns:scan=\"http://schemas.hp.com/imaging/escl/2011/05/03\" xmlns:pwg=\"http://www.pwg.org/schemas/2010/12/sm\">\n" +
                "<pwg:Version>2.6</pwg:Version>\n" +
                "<pwg:ScanRegions>\n" +
                "<pwg:ScanRegion>\n" +
                "<pwg:Height>3507</pwg:Height>\n" +
                "<pwg:ContentRegionUnits>escl:ThreeHundredthsOfInches</pwg:ContentRegionUnits>\n" +
                "<pwg:Width>2480</pwg:Width>\n" +
                "<pwg:XOffset>0</pwg:XOffset>\n" +
                "<pwg:YOffset>0</pwg:YOffset>\n" +
                "</pwg:ScanRegion>\n" +
                "</pwg:ScanRegions>\n" +
                "<scan:DocumentFormatExt>image/jpeg</scan:DocumentFormatExt>\n" +
                "<pwg:ContentType>Photo</pwg:ContentType>\n" +
                "<pwg:InputSource>Platen</pwg:InputSource>\n" +
                "<scan:XResolution>200</scan:XResolution>\n" +
               "<scan:YResolution>200</scan:YResolution>\n" +
                "<scan:ColorMode>RGB24</scan:ColorMode>\n" +
                "</scan:ScanSettings>"

request boby

ghadeerAqraa commented 2 years ago

@JakeWoki thanks for the quick response what do you mean with use SDK ?

JakeWoki commented 2 years ago

Some machine manufacturers provide SDK services.eg epson