CD108 Geschrieben January 25, 2013 at 10:23 Geschrieben January 25, 2013 at 10:23 Guys, I'm looking for a way to be able to add bricklets without coding for each one individually. For example i want to add a database row in a table that allows me to put in the bricklet info and have the value updated in that row. Currently i have to add a callback in the code for each sensor which is a pain when i want to add more sensors. Is there an easy way to do this so that the sensor network can be expanded without changing the code in the application? Zitieren
borg Geschrieben January 25, 2013 at 10:45 Geschrieben January 25, 2013 at 10:45 Sure, you can do that with the enumeration callback, see here: http://www.tinkerforge.com/doc/Tutorials/Tutorial_Rugged/Tutorial.html#c Note: This tutorial is for protocol 2.0, i don't know if you already updates the tools and your Bricks/Bricklets to the new protocol. Zitieren
AuronX Geschrieben January 25, 2013 at 10:54 Geschrieben January 25, 2013 at 10:54 Use the enumeration callback of the IPConnection. 2.0 example: public void main(...) { //... ipcon.Enumerate += EnumerateCB; } static void EnumerateCB(IPConnection sender, string uid, string connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType) { if(enumerationType == IPConnection.ENUMERATION_TYPE_DISCONNECTED) { return; //we don't care for disconnected devices } if(deviceIdentifier == 216) //Temperature-Bricklet, as of http://www.tinkerforge.com/doc/Software/Device_Identifier.html#device-identifier { var bricklet = new BrickletTemperature(uid, sender); bricklet.SetTemperatureCallbackPeriod(100); bricklet.Temperature += TemperatureCB; } } private static void TemperatureReached(BrickletTemperature sender, short temperature) { //update your database with sender.uid and temperature } This example contains mostly code from my mind, so there might be typos. Also: I saw that there is no Accessor for the UID on the Device-class. So my comment about "use sender.UID" is wrong, but I think this needs to be changed (Pull Request in preparation ^^) Zitieren
CD108 Geschrieben January 25, 2013 at 11:19 Autor Geschrieben January 25, 2013 at 11:19 OK, i have got this to work using static void Temp1CB(BrickletTemperature sender, short temperature) { string uid; string connecteduid; char position; byte[] hardwareversion; byte[] firmwareversion; int deviceidentifier; sender.GetIdentity(out uid,out connecteduid,out position,out hardwareversion,out firmwareversion,out deviceidentifier); //code to update database with uid and temperature } Is there simpler way to get the uid without all the other information? As you pointed out there doesn't seem to be a sender.uid Thanks for the quick help! Zitieren
AuronX Geschrieben January 25, 2013 at 11:29 Geschrieben January 25, 2013 at 11:29 The simpler solution is to add the missing accessor, my Pull Request for the C#-Bindings can be found here: https://github.com/Tinkerforge/generators/pull/30 Lets see how TF likes this change Zitieren
CD108 Geschrieben January 25, 2013 at 11:31 Autor Geschrieben January 25, 2013 at 11:31 Ok, In about 2 simple changes to my code i now have this working perfectly! Thanks again for the quick reply! Zitieren
AuronX Geschrieben February 4, 2013 at 15:56 Geschrieben February 4, 2013 at 15:56 The latest C# Bindings should include an accessor for the UID 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.