tofferoma

tofferoma

Hi,

i was wondering if there is a way to access smart cards via a PCSC reader.
I was unable to find any lib or bindings to do so (here’s a list samples in different languages [1]).

Maybe there is a different way to accomplish the task, or there has never been a use case for erlang centric applications.

Thanks in advance
T

Showing Posts 13 to 4

LudovicRousseau

LudovicRousseau

No idea.
Maybe.

ghannam80

ghannam80

Is it possible in principle to use those NFC libraries to exchange information between 2 NFC enabled mobile phones ? As an example use it between customer and merchant to get payment details instead of QR or card payment?

LudovicRousseau

LudovicRousseau

My Erlang sample is also ready.
See Ludovic Rousseau's blog: PC/SC sample in Erlang

Thanks

LudovicRousseau

LudovicRousseau

My Elixir sample is ready.
See Ludovic Rousseau's blog: PC/SC sample in Elixir

Thanks to alll

tofferoma

tofferoma OP

@LudovicRousseau I took the liberty to put together an elixir example, which can be found here: GitHub - tofferoma/elixir_pcsc_sample · GitHub

hope it helps

tofferoma

tofferoma OP

I added a pull request for running the code as a relx release via rebar3_run plugin. Maybe someone finds it interesting.

Looking forward to the elixir version :slight_smile:

LudovicRousseau

LudovicRousseau

I added “pcsc” in src/blog.app.src as you suggested and I see some progress.

Now I have:

$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling blog
Erlang/OTP 24 [erts-12.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Eshell V12.3.1  (abort with ^G)
1> ===> Booted syntax_tools
===> Booted compiler
===> Booted goldrush
===> Booted lager
===> Booted pcsc
===> Booted blog
16:51:31.667 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok
16:51:31.721 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok
16:51:31.775 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok
16:51:31.831 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok
16:51:31.887 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok
16:51:31.945 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok
16:51:32.008 [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok

Error -2146435026 is SCARD_E_NO_READERS_AVAILABLE and is not really an error.

Reported upstream at [warning] got pcsc_reader_error: {error,{pcsc_error,-2146435026,no_readers,"Cannot find a smart card reader."}}; restarted ok · Issue #4 · arekinath/erlang-pcsc · GitHub

Thanks @tofferoma.
I may ask for more help very soon about Elixir :slight_smile:

tofferoma

tofferoma OP

So after some more research it is enough to add pcsc to the applications in src/blog.app.src

diff --git a/blog/src/blog.app.src b/blog/src/blog.app.src
index 4793c20..94b4591 100644
--- a/blog/src/blog.app.src
+++ b/blog/src/blog.app.src
@@ -5,7 +5,8 @@
   {mod, {blog_app, []}},
   {applications,
    [kernel,
-    stdlib
+    stdlib,
+    pcsc
    ]},
   {env,[]},
   {modules, []},

This makes the rebar3 shell command work. However, packaging a NIF with an escript seems to be more complicated [1], [2]. The shell example should be enough as a proof of concept though, as the packaging/release method is up to the user.

hope this helps

[1] Escript: can not load argon2_nif - wrong approach for CLI?
[2] escripts look for nifs (.so) in wrong location · Issue #2129 · erlang/rebar3 · GitHub

tofferoma

tofferoma OP

Hi,

changing my rebar.config to

{erl_opts, [debug_info]}.
{deps, [pcsc]}.

{escript_incl_apps, [pcsc]}.

{shell, [
  % {config, "config/sys.config"},
    {apps, [pcsc, blog]}
]}.

gets me further.

With the {escript_incl_apps, [pcsc]} the error changes from undefined function to noproc. The library should now be packaged properly with the escript.
The noproc error occurs in this case, because the pcsc application is not started. So I tried adding it in the apps declaration {apps, [pcsc, blog]} ← works only for shell so far.
When I run rebar3 shell I still get an error because my architectures don’t match, and the NIF can’t load the C code. I’ll try to get around this, but maybe this already solves your problem.
Edit:
I got it working in the shell on a different machine

pcsc_card_db:list_readers()
{ok,[]}

still no luck with the escript tough …

Thanks and good luck
Chris

LudovicRousseau

LudovicRousseau

I am trying to use erlang-pcsc from @arekinath.
But that is my first Erlang program and I blocked on a stupid problem :frowning:

I created a sample code at GitHub - LudovicRousseau/erlang-pcsc-sample: Sample code of PC/SC in Erlang · GitHub
I use rebar3 escriptize to create a binary.
Then I start it using:

$ ./_build/default/bin/blog 
Hello world!
escript: exception error: undefined function pcsc_card_db:list_readers/0
  in function  escript:run/2 (escript.erl, line 750)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1 
  in call from init:do_boot/3

My code does not find the pcsc functions. I guess it is trivial to fix once you know Erlang a bit more.

My goal is to add an Erlang PC/SC sample to Ludovic Rousseau's blog: PC/SC sample in different languages

I also tried:

$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling blog
Erlang/OTP 24 [erts-12.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Eshell V12.3.1  (abort with ^G)
1> ===> Booted blog
pcsc_card_db:list_readers().
** exception exit: {noproc,{gen_server,call,[pcsc_card_db,list_readers]}}
     in function  gen_server:call/2 (gen_server.erl, line 239)
2>

Here the function list_readers() is found but I get an exception.

Sorry to ask stupid questions. Can someone help?

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews