Android Question How to send byte array to Smart Card

Culjko

Member
After reading your posts I realized that I cannot call a class as static if it is public. The problem I have now is how to forward the byte array to the methods, I read the posts but I didn't find anything similar.
 

Culjko

Member
I just write in B4A what i see in library and that wotk

B4X:
    Dim ADPU_SEND(520) As Byte
    Dim bytePos As Int = 0
        
    For i = 0 To 3
        ADPU_SEND(i) = cmd(i)
    Next
    Dim LoByte As Byte = Lc / 256
    Dim HiByte As Byte = Lc  Mod 256
    
    ADPU_SEND(4) = LoByte
    ADPU_SEND(5) = HiByte
    
    bytePos = 6
    For i = 0 To Data.Length-1
        ADPU_SEND(bytePos) = Data(i)
        bytePos = bytePos + 1
    Next
    Dim bLen As Int = Le + 4
    Dim LoByte As Byte = bLen / 256
    Dim HiByte As Byte = bLen  Mod 256

    ADPU_SEND(518) = LoByte
    ADPU_SEND(519) = HiByte

Thanks for helping
 
Upvote 0

Culjko

Member
hi again
What is here problem with this error?

B4X:
    Dim recvBuffer(520) As Byte
    Log("slot "& slotNum)
    mReader.RunMethod ("transmit",Array  (slotNum, cmd, cmd.Length, recvBuffer, recvBuffer.Length))
    Log(bytesToHexString(recvBuffer))



State 0
PRESENT 0
Scard Applet
slot 0
Error occurred on line: 68 (cardReader)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at com.ciontek.ePos.cardreader._transmit(cardreader.java:306)
at com.ciontek.ePos.cardreader._scardapplet(cardreader.java:420)
at com.ciontek.ePos.b4xmainpage._button1_click(b4xmainpage.java:352)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i have no idea what is on line 68...
my guess would be this line
mReader.RunMethod ("transmit",Array (slotNum, cmd, cmd.Length, recvBuffer, recvBuffer.Length))
has caused the error.
i do not know what the cmd is, i do not know if you are connected. you refuse to use try/catch blocks. you are not listening. it's very difficult for me.
 
Upvote 0

Culjko

Member
I am new here, need time to figure out about what u talk about

here is error with try

B4X:
Logger connected to:  Ciontek CS10
--------- beginning of system
--------- beginning of main
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
class com.ciontek.ePos.main
Error occurred on line: 78 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at com.ciontek.ePos.cardreader._openreader(cardreader.java:392)
    at com.ciontek.ePos.b4xmainpage._button1_click(b4xmainpage.java:340)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: Cannot claim interface.
    at com.acs.smartcard.Reader.open(SourceFile:1142)
    ... 21 more
** Activity (main) Create (first time) **
bluetoothadapter
CS10
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
class com.ciontek.ePos.main
java.lang.Object@458dca9
State 0
PRESENT 0
slot 0
Atr null
ovde je doslo
0
1
2
0
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
class com.ciontek.ePos.main
Error occurred on line: 79 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at com.ciontek.ePos.cardreader._openreader(cardreader.java:384)
    at com.ciontek.ePos.b4xmainpage._button1_click(b4xmainpage.java:340)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: Cannot claim interface.
    at com.acs.smartcard.Reader.open(SourceFile:1142)
    ... 28 more
(Exception) java.lang.Exception:  java.lang.reflect.InvocationTargetException
java.lang.Object@69442dd
State 0
PRESENT 0
slot 0
Error occurred on line: 155 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at com.ciontek.ePos.cardreader._getatr(cardreader.java:268)
    at com.ciontek.ePos.b4xmainpage._button1_click(b4xmainpage.java:352)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: The reader is not opened.
    at com.acs.smartcard.Reader.getAtr(SourceFile:1453)
    ... 21 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
bluetoothadapter
CS10
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
class com.ciontek.ePos.main
java.lang.Object@458dca9
State 0
PRESENT 0
slot 0
Error occurred on line: 155 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at com.ciontek.ePos.cardreader._getatr(cardreader.java:268)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: The slot number is invalid.
    at com.acs.smartcard.Reader.getAtr(SourceFile:1457)
    ... 20 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
bluetoothadapter
CS10
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
class com.ciontek.ePos.main
java.lang.Object@458dca9
State 0
PRESENT 0
slot 0
Error occurred on line: 156 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: The slot number is invalid.
    at com.acs.smartcard.Reader.getAtr(SourceFile:1457)
    ... 19 more
(Exception) java.lang.Exception:  java.lang.reflect.InvocationTargetException
ovde je doslo
0
1
2
0
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
class com.ciontek.ePos.main
Error occurred on line: 79 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: Cannot claim interface.
    at com.acs.smartcard.Reader.open(SourceFile:1142)
    ... 19 more
(Exception) java.lang.Exception:  java.lang.reflect.InvocationTargetException
java.lang.Object@dc9ad9e
State 0
PRESENT 0
slot 0
Error occurred on line: 156 (cardReader)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalArgumentException: The reader is not opened.
    at com.acs.smartcard.Reader.getAtr(SourceFile:1453)
    ... 19 more
(Exception) java.lang.Exception:  java.lang.reflect.InvocationTargetException
 
Upvote 0

Culjko

Member
Ciontek CS10 is POS android printer wich have build in Printer and Smard card reader. I have and other types of POS without Smart card reader. My intention is to write driver for smart card reader and use over USB C adapter. How that looks like you can see on picture.
 

Attachments

  • viber_image_2024-02-15_16-06-40-056.jpg
    211.2 KB · Views: 82
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the topic of this theme is "How to send byte array to Smart Card"
i was hoping to help, but we are very far from that now.

you don't answer questions, you post lines of meaningless codes:
B4X:
state=0
PRESENT 0   
ovde je doslo
0
1
2
0
i have no idea what any of that means. and i have no access to any of the software you are using.
i have to stop. i'm sorry. i wish you good luck.
 
Upvote 0

Culjko

Member
Ill send you code what i write in class

B4X:
Sub Class_Globals
    ' ************
    ' JAVA VARS
    '*************
    Dim uManager As UsbManager
    Dim uDevice As UsbDevice

    Dim mReader As JavaObject
    Dim device As JavaObject
    Dim Manager As JavaObject
    Dim Reader As JavaObject
    Private EventName As String 'ignore
    Private CallBack As Object 'ignore
    Private openState As Boolean
    
    Dim slotNum As Int
    Dim prevState As Int
    Dim currState As Int
    Dim getState As Int
    Dim Unknown As Int
    Dim Absent As Int
    Dim Present As Int
    Dim Undefined As Int
    
    Dim CARD_POWER_DOWN As Int = 0
    Dim CARD_COLD_RESET As Int = 1
    Dim CARD_WARM_RESET As Int = 2
    Dim PROTOCOL_UNDEFINED As Int = 0
    Dim PROTOCOL_T0 As Int = 1
    Dim PROTOCOL_T1 As Int = 2
    Dim PROTOCOL_RAW  As Int = 65536
    Dim PROTOCOL_TX As Int = 3
    Dim PROTOCOL_DEFAULT As Int = -2147483648
    Dim PROTOCOL_OPTIMAL As Int = 0
    Dim CARD_UNKNOWN As Int = 0
    Dim CARD_ABSENT As Int = 1
    Dim CARD_PRESENT As Int = 2
    Dim CARD_SWALLOWED As Int = 3
    Dim CARD_POWERED As Int = 4
    Dim CARD_NEGOTIABLE As Int = 5
    Dim CARD_SPECIFIC As Int = 6
    Dim IOCTL_CCID_ESCAPE As Int = 3500
    Dim IOCTL_ACR128_READER_COMMAND As Int = 2079
    Dim IOCTL_ACR83_GET_FIRMWARE_VERSION As Int = 2078
    Dim IOCTL_ACR83_DISPLAY_LCD_MESSAGE As Int = 2079
    Dim IOCTL_ACR83_READ_KEY As Int = 2080
    Dim IOCTL_GET_FEATURE_REQUEST As Int = 3400
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(vCallback As Object, vEventName As String)
    mReader.InitializeContext
    Reader.InitializeContext
    device.InitializeContext
    uManager.Initialize
    
    EventName = vEventName
    CallBack = vCallback
    'GetBA

    verificaUsbDevice
    NewReader
    CreateEvent

End Sub


Sub NewReader As JavaObject
    Private jo As JavaObject
    jo.InitializeContext
    Manager= GetContext.RunMethod("getSystemService", Array("usb"))
    mReader = jo.InitializeNewInstance ("com.acs.smartcard.Reader",Array As Object (Manager))
    Log(mReader)
End Sub

Sub CreateEvent As JavaObject

    'Private CallBack As Object

    'CallBack=mReader.CreateEvent  ("com.acs.smartcard.Reader.OnStateChangeListener", "status", Null)
    'Private cObject As Object = mReader.RunMethod("setOnStateChangeListener",Array As Object  (CallBack))


End Sub

Sub OpenReader As JavaObject
    openState = True
    Log(uDevice)
    Log(uDevice.IsInitialized)
    Log(mReader.IsInitialized)
    Log(mReader.RunMethod ("isSupported",Array As Object(uDevice)))
    Log(mReader.RunMethod ("isOpened", Null))
    'Try
        device=mReader.RunMethod ("open",Array As Object(uDevice))
    'Catch
    '    Log(LastException)
    'End Try
    'device.InitializeContext
    Log("open = " & device)
    Log("is Open "&device.RunMethod ("isOpened", Null))
    Log("get device " & mReader.RunMethod ("getDevice", Null))
    Log("get num slots " & mReader.RunMethod ("getNumSlots", Null))
    Log("get reader name " & mReader.RunMethod ("getReaderName", Null))
''    Log(mReader.RunMethod ("power", Array(slotNum,CARD_COLD_RESET)))
    setProtocol(PROTOCOL_T1)
End Sub

Sub CloseReader As JavaObject
    openState = False
    mReader.RunMethod ("close",Null)
End Sub


Sub transmit(cmd() As Byte)

    Dim recvBuffer() As Byte
    Log("slot "& slotNum)
    Try
        mReader.RunMethod ("transmit",Array As Object(slotNum, cmd, cmd.Length, recvBuffer, recvBuffer.Length))
    Catch
        Log(LastException)
    End Try
      
    Log(bytesToHexString(recvBuffer))
    'sendBuffer() As Byte) , sendBufferLength As Int, recvBuffer() As Byte, recvBufferLength As Int) As Byte()

End Sub


Public Sub ScardApplet
    Log("Scard Applet")
    Dim cmd(23) As Byte
    Dim Data1(16) As Byte
    Dim Lc As Byte
    Dim Le As Int
    
    cmd(0) = 0x00
    cmd(1) = 0xa4
    cmd(2) = 0x04
    cmd(3) = 0x00
    cmd(4) = 0x10
    cmd(5) = 0xA0
    cmd(6) = 0x00
    cmd(7) = 0x00
    cmd(8) = 0x07
    cmd(9) = 0x48
    cmd(10) = 0x46
    cmd(11) = 0x4A
    cmd(12) = 0x49
    cmd(13) = 0x2D
    cmd(14) = 0x54
    cmd(15) = 0x61
    cmd(16) = 0x78
    cmd(17) = 0x43
    cmd(18) = 0x6F
    cmd(19) = 0x72
    cmd(20) = 0x65
    cmd(21) = 0x65
    cmd(22) = 0x00
    
    transmit(cmd)

End Sub


Sub getProtocol As Int
    
    Log("slot "& slotNum)
    Log("protocol " & mReader.RunMethod ("getProtocol",Array  (slotNum)))

End Sub

Sub setProtocol(Protocol As Int) As Int
    
    Log("slot "& slotNum)
    Try
        Log("protocol " & mReader.RunMethod ("setProtocol",Array As Object(slotNum, Protocol)))
    Catch
        Log(LastException)
        Log("set protocol false")
    End Try
    

End Sub

Sub getAtr(slot1 As Int)
    Log("slot "& slotNum)
    Try
        Log("Atr " & mReader.RunMethod ("getAtr",Array  As Object(slot1)))
    Catch
        Log(LastException)
    End Try
    
End Sub

Public Sub getStateReader
    Return mReader.RunMethod ("getState", Array As Object (slotNum))
End Sub



Sub status_event(MethodName As String, Args() As Object)
    
Log("ovde je doslo")
    If Not (openState) Then Return
    For i = 0 To Args.Length-1
        Log(Args(i))
    Next
    slotNum =Args(0)
    prevState =Args(1)
    currState =Args(2)
    'getState As Object
    Unknown =mReader.GetField ("CARD_UNKNOWN")
    Absent =mReader.GetField ("CARD_ABSENT")
    Present =mReader.GetField ("CARD_PRESENT")
    Undefined =mReader.GetField ("PROTOCOL_UNDEFINED")
    getState= getStateReader
    Log(slotNum)
    If currState=Unknown Then
        Log("Card Unknown")
    End If
    If prevState > currState And currState<>Unknown Then
        Log ("Card Removed")
    Else
        If currState<>Unknown Then
            Log("Card Inserted")
        End If
    End If
End Sub

Sub verificaUsbDevice As Object
    
    Dim usbdevices() As UsbDevice
    usbdevices = uManager.GetDevices
    For i = 0 To usbdevices.Length - 1
        ' Dim ud As UsbDevice
        Dim ud As UsbDevice = usbdevices(i)
        Dim inter As UsbInterface
        inter = ud.GetInterface(i)
        Log("class "& inter.InterfaceClass)
        Log("subclass "& inter.InterfaceSubclass)
        If inter.InterfaceClass = 11 And inter.InterfaceSubclass = 0 Then
            'found our device and interface
            ''interface = inter
            uDevice = ud   
            Log("Device name " & ud.DeviceName)
            Log(ud.ProductId)
            Log(ud.VendorId)
            'Find correct endpoints
'            For b = 0 To interface.EndpointCount - 1
'                Dim endpoint As UsbEndpoint
'                endpoint = interface.GetEndpoint(b)
'                If endpoint.Type = Manager.USB_ENDPOINT_XFER_BULK Then
'                    If endpoint.Direction = Manager.USB_DIR_IN Then
'                        inEndpoint = endpoint
'                    Else If endpoint.Direction = Manager.USB_DIR_OUT Then
'                        outEndpoint = endpoint
'                    End If
'                End If
'            Next
        End If
        
        
    Next
    
    If uManager.HasPermission(uDevice) = False Then
        uManager.RequestPermission(uDevice)
    End If
    Return uDevice
End Sub


Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = CallBack
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO ("processBA")
End Sub

Public Sub bytesToHexString(data() As Byte) As String
    Dim bc As ByteConverter
    Return bc.HexFromBytes(data)
End Sub

when i write log afther open i get
open = (JavaObject) Not initialized
i dont know how to initialized

B4X:
Logger connected to:  SUNMI V2
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
/storage/emulated/0/Android/data/com.ciontek.ePos/files
class 11
subclass 0
Device name /dev/bus/usb/001/006
45312
1839
(Reader) com.acs.smartcard.Reader@81d2322
(UsbDevice) UsbDevice[mName=/dev/bus/usb/001/006,mVendorId=1839,mProductId=45312,mClass=0,mSubclass=0,mProtocol=0,mManufacturerName=ACS,mProductName=ACR39U ICC Reader,mVersion=1.16,mSerialNumber=null,mConfigurations=[
UsbConfiguration[mId=1,mName=null,mAttributes=128,mMaxPower=50,mInterfaces=[
UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=11,mSubclass=0,mProtocol=0,mEndpoints=[
UsbEndpoint[mAddress=129,mAttributes=2,mMaxPacketSize=64,mInterval=0]
UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=64,mInterval=0]
UsbEndpoint[mAddress=131,mAttributes=3,mMaxPacketSize=8,mInterval=24]]]]
true
true
true
false
open = (JavaObject) Not initialized
Error occurred on line: 100 (cardReader)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:259)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
    at com.ciontek.ePos.cardreader._openreader(cardreader.java:529)
    at com.ciontek.ePos.b4xmainpage._button1_click(b4xmainpage.java:316)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5719)
    at android.view.View$PerformClick.run(View.java:22837)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6367)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)

Now errors look like this, is obvious to smart card is not open, but there not send any error just pass and return next
open = (JavaObject) Not initialized
 
Upvote 0

Culjko

Member
B4X:
Dim aca As cardReader
    
    
    aca.Initialize(Main,"aca")
'    aca.verificaUsbDevice
'    aca.NewReader
'    aca.CreateEvent
    aca.OpenReader
    Log(aca.getstateReader)
    Log("State " & aca.currState)
    Log("PRESENT " & aca.Present)
    aca.getAtr(0)
    
    ''aca.setprotocol(1)
    ''aca.getprotocol
    
    aca.ScardApplet
 
Upvote 0

Culjko

Member
What i do wrong here?

B4X:
Public Sub GetSmartCardSlot As Int

    Private iccSmartCard As JavaObject
    iccSmartCard.InitializeContext
    iccSmartCard.InitializeStatic("com.sunmi.pay.hardware.aidl.readcard.ReadCardOpt")
    'iccSmartCard.InitializeNewInstance("com.sunmi.pay.hardware.aidl.readcard.ReadCardOpt", Null)
    Dim i As Int
    For i = 0 To 4
        Dim Slot(1) As Byte
        Slot(0) = i
        Dim ff As Long
        Try
            Log( iccSmartCard.RunMethod("getCardExistStatus",Array(i)) ) ' line 243
        Catch
            Log(LastException)
        End Try
        
    Next
    Return slotNumber
End Sub

B4X:
Error occurred on line: 243 (SunmiV2)
java.lang.IllegalArgumentException: Expected receiver of type com.sunmi.pay.hardware.aidl.readcard.ReadCardOpt, but got java.lang.Class<com.sunmi.pay.hardware.aidl.readcard.ReadCardOpt>
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at com.ciontek.universal_eLPFR.sunmiv2._getsmartcardslot(sunmiv2.java:96)
    at com.ciontek.universal_eLPFR.b4xmainpage._button1_click(b4xmainpage.java:471)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7455)
    at android.view.View.performClickInternal(View.java:7428)
    at android.view.View.access$3600(View.java:813)
    at android.view.View$PerformClick.run(View.java:28495)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7700)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
(Exception) java.lang.Exception:  java.lang.IllegalArgumentException: Expected receiver of type com.sunmi.pay.hardware.aidl.readcard.ReadCardOpt, but got java.lang.Class<com.sunmi.pay.hardware.aidl.readcard.ReadCardOpt>
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…