Author Topic: New Perl Bindings Beta Test  (Read 3568 times)

iia

  • Tinkerforge Staff
  • Newbie
  • *
  • Posts: 9
    • View Profile
New Perl Bindings Beta Test
« on: December 15, 2013, 01:25:57 »
Hei people,

I am a new employee at Tinkerforge and recently I have been working on a new perl binding. Attached are the compressed files of the binding in current state.

Directory Structure:
  • api
  • bindings
  • examples

api: Contains the main api files.
bindings: Contains the device class files.
examples: Contains examples to get an idea of the API usage.

This API requires that your system's perl installation has the latest Thread::Queue perl module.

One can update this via CPAN,

Code: [Select]
sudo cpan

and then on the CPAN console,

Code: [Select]
upgrade Thread::Queue

Note the two lines at the beginning of the example scripts,

Code: [Select]
use lib '../api';
use lib '../bindings';

Change these two lines accordingly to point to the api and bindings directories (if you changed/moved the files).

While using the examples don't forget to change the device and their UIDs according to your setup and the same for the host.

Try the beta API out and report findings, bugs, suggestions etc here.
« Last Edit: December 15, 2013, 15:59:37 by iia »

Nic

  • Hero Member
  • *****
  • Posts: 1.419
  • Pano.photogr. - Just for fun: Delphi, C#...
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #1 on: December 16, 2013, 10:11:56 »
Hi Ishraq, welcome home to the TF world. Good to have a new member to empower the team and this Tinker community. :)
I think new bindings for pearl is a good starting point.

iia

  • Tinkerforge Staff
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #2 on: December 16, 2013, 19:49:35 »
Thanks Nic. :)

schrorg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #3 on: December 28, 2013, 16:38:14 »
Hi Ishraq,

very nice work! I quickly tried the enumerate example (without the display code) and it worked like a charm (after I recompiled my perl with "-Dusethreads"...)!

I will reimplement the C/C++ part of my weather station (wind measurement with anemometer from Amazon and IO-4 bricklet) in perl in the next days and see, if callbacks and the stuff run stable.

The rest of my weather station is already implemented in perl. I use the perl bindings from CPAN (http://search.cpan.org/~joba/TinkerForge-0.01/lib/TinkerForge.pm), but in a newer version from here: https://git.rub.de/gitweb/?p=tinkerforgeperl.git;a=summary

The problem with the CPAN perl bindings (which are actually from a friend and me) is, that they use the C/C++ bindings and wrap them in XS. They have only the functionality we need and don't need a perl with thread support (mainly because of stability problems on our machines and with our test suite). Callbacks are not implemented.

Your version of the bindings seem to be complete and could be automatically generated like the other bindings. I would prefer them over the version from CPAN, if they would be further developed.

I would really like the perl bindings to be official. If I can help in any way, don't hesitate to ask! :-)

Robin

borg

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 3.135
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #4 on: December 28, 2013, 18:11:31 »
Your version of the bindings seem to be complete and could be automatically generated like the other bindings.
Ishraqs Bindings are already generated! ;D
Wir sind die Borg, Widerstand ist Spannung durch Stromstärke!

iia

  • Tinkerforge Staff
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #5 on: December 28, 2013, 18:29:50 »
Hei Robin,

Thanks for your feedback.

As borg mentioned, the bindings are already generated and resembles the previous bindings.

It will be official and we also planned to put it in CPAN.

But before that little bit more testing is needed for the implementation.

Ishraq.

schrorg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #6 on: January 05, 2014, 13:13:41 »
Hi Ishraq,

i think i found a bug in api/Device.pm while playing with my LCD20x4 bricklet: When displaying exactly 20 characters, the last character will not be printed on the display.

For me, a fix in the function send_request() in api/Device.pm makes it work: While packing the string (with 'Z20') in line 111, the 20th character will be exchanged with a null character. So my fix is to pack with one more character instead:

Code: [Select]
diff -ur api_orig/Device.pm api/Device.pm
--- api_orig/Device.pm  2014-01-05 12:44:59.515125343 +0100
+++ api/Device.pm       2014-01-05 12:47:13.621152531 +0100
@@ -108,7 +108,9 @@
                                        # Strings should be treated different even if its in Z<count> form
                                        if($form_data_arr_tmp[0] eq 'Z')
                                        {
-                                                $packed_data .= pack("$form_data_arr[$i]", @{$data}[$i]);
+                                                $form_data_arr[$i] =~ /^Z(\d+)$/;
+                                                my $packsize = $1;
+                                               $packed_data .= pack("Z" . ($packsize + 1), @{$data}[$i]);
                                                next;
                                        }
 
@@ -121,7 +123,13 @@
                                }
                                if(split('', $form_data_arr[$i]) == 1)
                                {
-                                       $packed_data .= pack("$form_data_arr[$i]", @{$data}[$i]);
+                                        if ($form_data_arr[$i] =~ /^Z(\d+)$/) {
+                                            my $packsize = $1;
+                                            $packed_data .= pack("Z" . ($packsize + 1), @{$data}[$i]);
+                                        }
+                                        else {
+                                            $packed_data .= pack("$form_data_arr[$i]", @{$data}[$i]);
+                                        }
                                }
                        }
                }

I'm not sure if my fix is harmful in any other way, so I would kindly ask you to review the problem.

I attached the patch and a small test program.

Robin

iia

  • Tinkerforge Staff
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: New Perl Bindings Beta Test
« Reply #7 on: January 06, 2014, 10:34:38 »
Hei Robin,

Thanks again for a very important finding! I fixed it in the code. Please do inform us if you find more issues.

Ishraq.