iia Geschrieben December 15, 2013 at 00:25 Geschrieben December 15, 2013 at 00:25 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: apibindingsexamples 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.ziptf_perl_api.tar.bz2 Zitieren
Nic Geschrieben December 16, 2013 at 09:11 Geschrieben December 16, 2013 at 09:11 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. Zitieren
iia Geschrieben December 16, 2013 at 18:49 Autor Geschrieben December 16, 2013 at 18:49 Thanks Nic. Zitieren
schrorg Geschrieben December 28, 2013 at 15:38 Geschrieben December 28, 2013 at 15:38 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 Zitieren
borg Geschrieben December 28, 2013 at 17:11 Geschrieben December 28, 2013 at 17:11 Your version of the bindings seem to be complete and could be automatically generated like the other bindings. Ishraqs Bindings are already generated! Zitieren
iia Geschrieben December 28, 2013 at 17:29 Autor Geschrieben December 28, 2013 at 17:29 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. Zitieren
schrorg Geschrieben January 5, 2014 at 12:13 Geschrieben January 5, 2014 at 12:13 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. Robindevice_pack_length_fix.patchtest.pl Zitieren
iia Geschrieben January 6, 2014 at 09:34 Autor Geschrieben January 6, 2014 at 09:34 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. Zitieren
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.