Page 1 of 1

.NET with sensor

Posted: Fri Mar 17, 2023 9:45 am
by weekendowel
I am using this code to get value from a temperature sensor:

Code: Select all

 private void Form1_Load(object sender, EventArgs e)
        {
             TelldusNETWrapper t = new TelldusNETWrapper();
           
            t.tdRegisterRawDeviceEvent(EventCallbackFunction, null);

        }
        public int EventCallbackFunction(string data, int controllerId, int callbackId, Object obj)
        {
            listBox1.Items.Add(DateTime.Now + data);
          


           

            return 0;
        }

It works and as soon as the temp sensor sends it value it shows up in the listbox. But it works only once, then it stops. What am I doing wrong?

Re: .NET with sensor

Posted: Fri Mar 17, 2023 9:45 am
by weekendowel
I wrote the code in VB.NET instead and for anybody interested here it is:

Code: Select all

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Dim t As New TelldusNETWrapper()

        Dim k As New RawListeningCallbackFunction(AddressOf eventhappened)




        t.tdRegisterRawDeviceEvent(k, Nothing)


    End Sub

    Function eventhappened(ByVal data As String, ByVal controllerId As Integer, ByVal callbackid As Integer, ByVal obj As Object) As Integer

        ListBox1.Items.Add(data)


    End Function
And it is working great. Values keep coming in :-)

Re: .NET with sensor

Posted: Fri Mar 17, 2023 9:45 am
by Brungle
hi,
thanks for the code, which temp sensor are you using?
thanks

Re: .NET with sensor

Posted: Fri Mar 17, 2023 9:45 am
by weekendowel
I´m using a jenkinsbird sensor, but the code should be valid for any sensor

Re: .NET with sensor

Posted: Fri Mar 17, 2023 9:45 am
by pekkak
Does anyone have a working C# example to read sensors? I can't figure it out from previous posts.