DarthAffe / OBD.NET

C#-Library to read data from car through an ELM327-/STN1170-Adapter
GNU General Public License v2.0
184 stars 83 forks source link

WebService Issue #12

Closed dakriege closed 5 years ago

dakriege commented 5 years ago

I created a simple .net WebService API to retrieve PID values to display on a page.

I confirmed that my OBD2 module is working via the example Client.

When I make a call to the requestDataAsync<> function it sends the data to the module and receives the hex response. At that point it appears to hang / timeout. Eventually the call completes but by that time the web service call has timed out and returns an error to the Page.

The web service method is using await when it calls the requestDataAsync function.

Any ideas?

DarthAffe commented 5 years ago

That's somehow weird. I see no reason why it should behave different just because it's called by a web service. How long is the timeout it hits? Some request (especially the first few after starting the car) can take quite a while to complete.

dakriege commented 5 years ago

I changed the debug logger to save to a flat file so I could watch all of the events.

I created a C# and VB .net .asmx page. I’m using VB so I thought maybe it had an issue with the DLL’s.

HTML5 Page Ajax Call to the Web Service -> Web Service does an await call to .RequestDataAsync()

It parses the Command, Queues it, Writes it and gets a reply.

I added a Task.Run() to the RequestDataAsync(pid).

I ended up creating a routine that subscribes to the data that I need and then use a timer to fire the request data triggers.

BTW – If I run this for an extended period of time I’ve had an exception occur that crashes IIS.

Would you know how to do the code below in VB ?

This is code I have working

    public int pubSubscribeRpm()

    {

        try

        {

            if (OBD2Dev == null)

            {

                return -2;

            }

            //Can’t figure out the VB equivalent to specify the event handler

            OBD2Dev.SubscribeDataReceived<EngineRPM>((sender, data) => updateRpm(data.Data));

            return 1;

        }

        catch (Exception ex)

        { 

            LogMsg("subscribe Rpm RT Err: " + ex.Message);

        return -1;

        }

    }

    public void updateRpm(EngineRPM dataUpdate)

    {

        curRPM = dataUpdate.Rpm.ToString();

    }

This is the vb code

Public Sub subscribeToRpm()

   ‘This line reports a syntax error on the updateRpm((Of EngineRPM))) 

    OBD2Dev.SubscribeDataReceived(Of EngineRPM)(AddressOf updateRpm((Of EngineRPM)))

End Sub

Private Sub updateRpm(dataRecd As EngineRPM)

    CurRPM = dataRecd.Rpm.ToString()

End Sub

Dave

From: DarthAffe [mailto:notifications@github.com] Sent: Tuesday, August 20, 2019 4:37 PM To: DarthAffe/OBD.NET OBD.NET@noreply.github.com Cc: dakriege dakrieger@ameritech.net; Author author@noreply.github.com Subject: Re: [DarthAffe/OBD.NET] WebService Issue (#12)

That's somehow weird. I see no reason why it should behave different just because it's called by a web service. How long is the timeout it hits? Some request (especially the first few after starting the car) can take quite a while to complete.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DarthAffe/OBD.NET/issues/12?email_source=notifications&email_token=AGDU3TB6GHAFMP3XCLPZH73QFRIYBA5CNFSM4INB5DIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XSTQA#issuecomment-523184576 , or mute the thread https://github.com/notifications/unsubscribe-auth/AGDU3THMBYI4CYO5NUFFFJDQFRIYBANCNFSM4INB5DIA . https://github.com/notifications/beacon/AGDU3TCGD5RJ6XXQUXNAXATQFRIYBA5CNFSM4INB5DIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XSTQA.gif

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

Virus-free. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient www.avg.com

dakriege commented 5 years ago

Converted the C# SubscribedDataReceived to the VB lambda equivalent.

Everything is working.

No need to research why the Async calls fail.

The triggered method is going to be more efficient delivering data to my HTML page.

Dave

From: DarthAffe [mailto:notifications@github.com] Sent: Tuesday, August 20, 2019 4:37 PM To: DarthAffe/OBD.NET OBD.NET@noreply.github.com Cc: dakriege dakrieger@ameritech.net; Author author@noreply.github.com Subject: Re: [DarthAffe/OBD.NET] WebService Issue (#12)

That's somehow weird. I see no reason why it should behave different just because it's called by a web service. How long is the timeout it hits? Some request (especially the first few after starting the car) can take quite a while to complete.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DarthAffe/OBD.NET/issues/12?email_source=notifications&email_token=AGDU3TB6GHAFMP3XCLPZH73QFRIYBA5CNFSM4INB5DIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XSTQA#issuecomment-523184576 , or mute the thread https://github.com/notifications/unsubscribe-auth/AGDU3THMBYI4CYO5NUFFFJDQFRIYBANCNFSM4INB5DIA . https://github.com/notifications/beacon/AGDU3TCGD5RJ6XXQUXNAXATQFRIYBA5CNFSM4INB5DIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XSTQA.gif

http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient

Virus-free. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient www.avg.com