Jump to content

Recommended Posts

Geschrieben

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,

 

sudo cpan

 

and then on the CPAN console,

 

upgrade Thread::Queue

 

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

 

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.

tf_perl_api.zip

tf_perl_api.tar.bz2

  • 2 weeks later...
Geschrieben

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

Geschrieben

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.

Geschrieben

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:

 

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

device_pack_length_fix.patch

test.pl

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...