Jump to content

C# automatically add bricklets


Recommended Posts



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?

Link to comment
Share on other sites

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.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 :D (Pull Request in preparation ^^)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...