Multos Forums

   

MULTOS Smartcard COM component

RankRankRank

Total Posts: 74

Joined 2012-02-21

PM

SmartDeck includes a really useful COM component for accessing smartcard readers, with a host of MULTOS specific features.

htermlib.dll (listed as COM component MultosTerminalTypeLib) is used by the SmartDeck tools themselves but there is no reason why you cannot use it to easily add smartcard functionality to your own Windows applications.

As well as the basics, such as

  o listing available PCSC readers
  o connecting to readers
  o selecting applications
  o sending APDUs

you can also use this component to

o load and delete MULTOS applications
o list the applications on the card
o get information about the type of card

When loading / deleting applications to / from developer cards, it is even possible for the component to generate the required certificates for you.

Here is some sample C# code that waits for a contactless card to be tapped on the reader then loads an application to it.

MultosTerminalComponent term;

        private 
bool waitForCard()
        
{
            bool cardOk 
false;
            
int numberOfSleeps 0;

            while (!
cardOk)
            
{
                
try
                
{
                    term
.connectpcsc("Broadcom Corp Contactless Smartcard 0");
                    
cardOk true;
                
}
                
catch
                
{
                    Thread
.Sleep(500);
                    
numberOfSleeps++;
                    if (
numberOfSleeps 30)
                        break;
                
}
            }
            
return cardOk;
        
}

        
private void button1_Click(object senderEventArgs e)
        
{
            bool cardOk 
waitForCard();

            if (
cardOk)
            
{
                
try
                
{
                    
// Do the actual load
                    
term.loadALU("myapp.alu""myapp.alc");

                    
// Confirm loaded
                    
try
                    
{
                        term
.selectbyaid("F3000001");
                        
term.setcommand("7001000033");
                        
term.exchange();
                        
string s term.getresponse();
                    
}
                    
catch (Exception err)
                    
{
                        MessageBox
.Show("Failed to confirm app loaded: " err.Message);
                    
}
                }
                
catch (Exception err)
                
{
                    MessageBox
.Show("ALU load failed: " err.Message);
                
}
                term
.disconnect();
            
}
            
else
                
MessageBox.Show("Try again");