BrianHumlicek / J2534-Sharp

A .Net interface for J2534 vehicle communications.
Other
43 stars 14 forks source link

MessageFilter to Protocol.CAN #10

Closed autoprog closed 3 years ago

autoprog commented 3 years ago

hi, question 1: teste filter with Protocol.ISO15765 and UserFilterType.STANDARDISO15765 =ok now test Protocol.CAN and UserFilterType.NONE not run (to receiver others IDs) how to use public byte[] Mask; public byte[] Pattern; public byte[] FlowControl; public TxFlag TxFlags;

I need receiver others id example 123 or 432... (standard only 0x7E8)

question 2: how to Disconnecte Channel, to re-open new type or close.

thanks, Carlos.

autoprog commented 3 years ago

hi, soved filter example1, MessageFilter FlowControlFilter = new MessageFilter() { FilterType = Filter.FLOW_CONTROL_FILTER, Mask = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }, Pattern = new byte[] { 0x00, 0x00, 0x07, 0xE8 }, FlowControl = new byte[] { 0x00, 0x00, 0x07, 0xE0 } };

now, question 2: how to Disconnecte Channel, to re-open new type or close.

thanks, Carlos.

BrianHumlicek commented 3 years ago

To disconnect a channel, you can call dispose and it will release the resources and allow you to create a new channel. If you are implementing ‘using’ scopes like the example, this happens automatically.

Brian

On Wed, Nov 25, 2020 at 3:21 PM Carlos Candido notifications@github.com wrote:

hi, soved filter

example1,

MessageFilter FlowControlFilter = new MessageFilter()

{

FilterType = Filter.FLOW_CONTROL_FILTER,

Mask = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF },

Pattern = new byte[] { 0x00, 0x00, 0x07, 0xE8 },

FlowControl = new byte[] { 0x00, 0x00, 0x07, 0xE0 }

};

now,

question 2:

how to Disconnecte Channel, to re-open new type or close.

thanks,

Carlos.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BrianHumlicek/J2534-Sharp/issues/10#issuecomment-733928371, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGEAKQG37VULOYOGXYSP2HTSRVROBANCNFSM4UCINWBA .

autoprog commented 3 years ago

hi Brian, I tested Dispose

Channel canal; init_CAN( ); ok Thread.Sleep(50); canal.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xF2, 0xAA, 0xAA }); ok Thread.Sleep(50); canal.Dispose();

        **if (canal.IsDisposed)**
            {
               "canal.IsDisposed = conected ";    **is connected**
            }
            else
            {
                init_ISO15765();
            }

not close Channel.

thanks, Carlos.

BrianHumlicek commented 3 years ago

I must not understand what you are saying.

I’m guessing maybe you’re trying to open a CAN channel, close it, and then open an ISO15775 channel. If so, you need to create the CAN channel from the device, preferably within a using block, and then create the ISO channel from the device, also within a using block.

Brian

On Wed, Nov 25, 2020 at 4:52 PM Carlos Candido notifications@github.com wrote:

hi Brian,

I tested Dispose

Channel canal;

init_CAN( ); ok

Thread.Sleep(50);

canal.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xF2, 0xAA, 0xAA }); ok

Thread.Sleep(50);

canal.Dispose();

    **if (canal.IsDisposed)**

        {

           "canal.IsDisposed = conected ";    **is connected**

        }

        else

        {

            init_ISO15765();

        }

not close Channel.

thanks,

Carlos.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/BrianHumlicek/J2534-Sharp/issues/10#issuecomment-733962201, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGEAKQA77YNXIBB22EJ4UHTSRV4CZANCNFSM4UCINWBA .

autoprog commented 3 years ago

hi Brian, I tested Channel canal_can; Channel canal_iso; init_CAN( ); ... canal_can.= APIFactory.. ok ... init_ISO( ); ... canal_iso.= APIFactory.. failure

how to with ( block )

thanks, Carlos.

BrianHumlicek commented 3 years ago

Chances are, you can only have one channel connected at a time because they use the same physical pins on the J2534 device. You will need to dispose the can channel before you init the iso channel.

Brian

On Thu, Nov 26, 2020 at 8:16 AM Carlos Candido notifications@github.com wrote:

hi, I tested Channel canal_can; Channel canal_iso; init_CAN( ); ... canal_can.= APIFactory.. ok ... init_ISO( ); ... canal_iso.= APIFactory.. failure

how to with ( block )

thanks, Carlos.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/BrianHumlicek/J2534-Sharp/issues/10#issuecomment-734292390, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGEAKQDKCCR377ORI7QACITSRZIJJANCNFSM4UCINWBA .

autoprog commented 3 years ago

hi Brian, yes, and i tried to do that but it doesn't disconnect the channel. see in previous messages. canal.Dispose(); CAN if (canal.IsDisposed) { "canal.IsDisposed = conected "; is connected } else { init_ISO15765(); } I don’t use two canails at the same time, I need to use one or the other, so I need to close one and open another.

BrianHumlicek commented 3 years ago

Channel.Dispose() calls PTDisconnect, which, according to the v4.04 spec, will disconnect the channel. There isn't anything else to do.

Brian

On Fri, Nov 27, 2020 at 6:25 AM Carlos Candido notifications@github.com wrote:

hi Brian,

yes, and i tried to do that but it doesn't disconnect the channel. see in previous messages.

canal.Dispose(); CAN

if (canal.IsDisposed)

{

"canal.IsDisposed = conected "; is connected

}

else

{

init_ISO15765();

}

I don’t use two canails at the same time, I need to use one or the other, so I need to close one and open another.

  • project dll, can add new funtions and re-compiler ?

    thanks,

    Carlos.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/BrianHumlicek/J2534-Sharp/issues/10#issuecomment-734787997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGEAKQESK5QMIXKPHSHB7ULSR6EAXANCNFSM4UCINWBA .

autoprog commented 3 years ago

hi Brian, [ SOLVED ] my solution tested ok

public void open_channels(string DllFileName) <----creat channels { API API = APIFactory.GetAPI(DllFileName); Device Device = API.GetDevice();

            canal_iso = Device.GetChannel(Protocol.ISO15765, Baud.ISO15765, ConnectFlag.NONE);
                     canal_iso.StartMsgFilter(FlowControlFilter_iso);
            //-----------------
            canal = Device.GetChannel(Protocol.CAN, Baud.CAN_500000, ConnectFlag.NONE);
                    canal.StartMsgFilter(FlowControlFilter_can);
    }

//----------

while(true){

send_CAN(); send_ISO(); send_OTHERS();

} congratulations your work, tranks, Carlos.

tesla20000 commented 3 years ago

Hello, I have an initialized channel: string passThru = xx.Filename; API passThrueAPI = APIFactory.GetAPI(passThru); var bbb = APIFactory.GetAPI(passThru).GetDevice(); Channel channelx = bbb.GetChannel (Protocol.CAN, Baud.ISO15765, ConnectFlag.NONE);

then initializes a new filter: int gg = channelx.StartMsgFilter (new MessageFilter (UserFilterType.PASS, new byte [] {0x00, 0x00, 0x07, 0xE8}));

Unfortunately, in my example I need to change the filter from time to time to different ECUs. The problem starts with the exception - when the filter is created 10x. It's the limit. Unfortunately, the functions below do not work. after calling eg ClearMsgFilters, I still have my filter in FilterList, which I started with the StartMsgFilter function. I hit the exception every time after 10 filter starts. StopMsgFilter (index) also does not remove the filter from the filter list. What am I doing wrong ??

// var ListOfActiveFilters = channelx.FilterList; // channelx.FilterList.Clear (); // channelx.ClearMsgFilters (); // channelx.StopMsgFilter (0);

All my CAN communication works perfect, but this limit of filters that i can't clean , can't stop confusing me really. I will be so happy when somebody will explain me my fault. I can't believe that library have bug.

Thanks

PS , I use now version 1.0.0-CI00026 from Nuget. Last Update on nuget is 21.04.2019. On repo i see some new commits. Question to author ... can You please push to Nuget manager latest compilation ??

autoprog commented 3 years ago

hi, j2534 no running DEBUG...

test it MessageFilter FlowControlFilter_iso = new MessageFilter() { FilterType = Filter.FLOW_CONTROL_FILTER, Mask = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }, Pattern = new byte[] { 0x00, 0x00, 0x07, 0xE8 }, FlowControl = new byte[] { 0x00, 0x00, 0x07, 0xE0 } }; canal_iso.StartMsgFilter(FlowControlFilter_iso); others.....

thanks, Carlos.

tesla20000 commented 3 years ago

Thank you, of course I will try this version of the implementation. However, it is important for me to understand ...

  1. While the start of a new filter is allowed on an open channel, removing the filter from the list should also work.
  2. Your solution does not change anything, because finally, wanting to initiate a new filter, I have only one function at my disposal: StartMsgFilter (FlowControlFilter_CAN);
    • which adds the defined filter to the filter list. My problem is to overfill this list because the command doesn't work for me: .ClearMsgFilters (); or .StopMsgFilter (0);

So a correctly defined filter is inserted into the filter list. So how do you take it off, or clear the filter list for a channel completely? For example, if it builds a communication stack with polling of all drivers in the vehicle, then 100% of them are more than 10 (the maximum limit of defined open filters in the list).

Can You confirm if this ClearMsgFilters() really remove all defined filters from channel for You ?? Can You test this please ?

autoprog commented 3 years ago

hi, I not tested new filter or clear filter.

Carlos.

BrianHumlicek commented 3 years ago

The channel.FilterList was intended as an aid to the consumer to track what filters are active. Looking at the implementation now, I should have exposed it as IReadOnly... so it was clear that wasn't a control surface, but just for feedback. Also, the ClearMsgFilters doesn't appear to clear the channel.filterlist so that s a bug, or an argument for removing the channel.filterlist.

ClearMsgFilters() should clear your filters, unless your device isn't 100% J2534 compliant. In that case, I would expect StopMsgFilter(x) to work assuming x is the filter id you got when you started the filter.

tesla20000 commented 3 years ago

Hi. My hardware is like STIC SVCI (red). Looks OK, and lot of peoples use this for Ford with original software IDS. Additionally i know, some my friends use this also for Volvo without issues. This cost around 120 Euro, is not so cheaply.

x is index on this array of filters. In my opinion, even if i stop selected filter , still my array will increase size by start next new filter. Maybe this is incorrect logic, but this is what i think about.

Next ... when i use ClearMsgFilters() , and then i will do some tests , after 10 probes with StartMsgFilter() / ClearMsgFilters() , still is exception. I can try this with different J2534 of course. We see. But i know, some my friends use this also for Volvo without issues. Is it possible that my J2534 interface is incompatible with the official volvo, ford, forscan soft. Is there any other tricky way to bypass these troublesome accumulated filters? From what I have observed, closing the channel and re-initiation generates communication delays, which appear to be significant compared to the operation of the device without changing the channel to another.

By the way .. i have one more question ... How i should call function to switch multiplexer to pin example 3/11 example ?

Regards

BrianHumlicek commented 3 years ago

All the underlying J2534 API should be accessible through the library. I would expect the multiplex change would be an IOCTL call, but I don’t j is which. You will need to refer to you device specs for that.

If you all would read the code, you would know what is being called, and could troubleshoot this yourselves.

Brian

On Mon, Nov 30, 2020 at 5:10 PM kameleon0781 notifications@github.com wrote:

Hi.

My hardware is same as from this offer https://www.diagobd2.de/wholesale/fvdi-j2534-diagnostic-interface.html?gclid=EAIaIQobChMI3ZKarKGr7QIVAqSyCh3kYQAjEAQYASABEgJh6_D_BwE http://url

Looks OK, and lot of peoples use this for Ford with original software IDS. Additionally i know, some my friends use this also for Volvo without issues. This cost around 120 Euro, os not so cheaply.

x is index on this array of filters.

In my opinion, even if i stop selected filter , still my array will increase size by start next new filter. Maybe this is incorrect logic, but this is what i think about.

Next ... when i use ClearMsgFilters() , and then i will do some tests , after 10 probes with StartMsgFilter() / ClearMsgFilters() , still is exception. I can try this with different J2534 of course. We see. But i know, some my friends use this also for Volvo without issues. Is it possible that my J2534 interface is incompatible with the official volvo, ford, forscan soft.

Is there any other tricky way to bypass these troublesome accumulated filters? From what I have observed, closing the channel and re-initiation generates communication delays, which appear to be significant compared to the operation of the device without changing the channel to another.

By the way .. i have one more question ...

How i should call function to switch multiplexer to pin example 3/11 example ?

Regards

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/BrianHumlicek/J2534-Sharp/issues/10#issuecomment-736086257, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGEAKQFZC5YMM5YOY7ZFW2TSSQJ4FANCNFSM4UCINWBA .

tesla20000 commented 3 years ago

Hi Brian. I have some idea to solve the problem. After testing, he will inform those interested in this thread. Thank you for your help and best regards.

tesla20000 commented 3 years ago

Hello, another question, or rather a continuation of questions to the author of the library. It's not like no one reads the code, no one reads it. But maybe the library was used with a single driver, then the problem doesn't seem to exist. The nature of CAN communication is to set filters and remove them during the communication stack - depending on the needs. I still claim, and can prove it, that the library doesn't remove the defined filters. Command: channel.ClearMsgFilters (); does not work, and it does not matter that the table of assumed filters is read-only. We are not trying to remove the defined filters from this table. Tests show that the library is to blame, different J2534 devices behave the same. Exactly when the filter table is full of 10 elements (filters), further work results in the inability to add a filter to the CAN address, finally the program stops with an exception. I am asking the author of the library for an in-depth analysis of the problem and help. If you have a newer version of the library, please update in Nuggets. I need it very much, I will be grateful. I am also happy to perform tests that you might define to find the problem. Respects. Greetings.

BrianHumlicek commented 3 years ago

What device are you using? Can you enable logging from your 2534 driver? When you call channel.ClearMsgFilters(), is it commanding IOCtl 0x0A?

tesla20000 commented 3 years ago

What device are you using? Resp: STIC SVCI J2534 ( Red color ) - popular, fast and stable, used for volvo , ford by many peoples

Can you enable logging from your 2534 driver? Resp: I dont know how to do .... i'am not sure.

When you call channel.ClearMsgFilters(), is it commanding IOCtl 0x0A? Resp: The only thing I can say, after getting connected to the device, I tried to sniff the virtual com port that is created when the device is plugged into USB. A lot of data is flying, but the command itself: ClearMsgFilters (); Generates absolutely no traffic on the usb connector (zero data will give a virtual comm port). Everything else flies correctly, for other queries - e.g. send a frame, receive a frame, you can see the data correctly. Same for set filter. If you wish, it will send you a log file created for incoming and outgoing data for communication between the device and the computer.

Resp: One more piece of information, on the same device I tested a project of a console application supporting J2534 written by someone else and using different c # api. (https://github.com/LegacyNsfw/PcmHacks). In the case of this project and the library I can set any number of filters and also delete them multiple times. So this is not an issue with my J2534.

This STIC SVCI J2534 use dll : SVDIPT32.dll

Regards

BrianHumlicek commented 3 years ago

So, the fact that you don't see any traffic tells me that your device doesn't support IOCTL 0x0A, which DOES make it a problem with your device. That IOCTL is part of the J2534 standard. Fortunately, you have alternatives, such as stopping each message filter explicitly using StopMsgFilter().

For convenience, I created a method to stop all filters explicitly StopAllMsgFilters(). Update your nuget package to v30 and let me know if that works for you.

tesla20000 commented 3 years ago

What happened with function APIFactory.GetAPIList() in v30 then ?? Is missing. Can You add back this function please ? If no , then i need to completely refactor my project. Is some concrete reason that this function was removed ? Probably after update more users will have same problem with compilation (missing function) Thanks , regards.

BrianHumlicek commented 3 years ago

It was superseded by GetAPIInfo().

tesla20000 commented 3 years ago

So this information for You after tests: / tested version API v30 (from nugget packet manager) /

  1. The StopAllMsgFilters () function works in theory, but not in practice. Before calling this function, I check the number of objects using channel.FilterList.Count (); I have an example of one declared filter there. after calling StopAllMsgFilters (), I check again, debug, I see FilterList is empty. Apparently ok, but ....

  2. After a few runs of the program, I mean several calls of the communication stack, which contains some 3-4 filter settings per one program cycle - an error pops up: GeneralDescription: "The limit (ten) of filter / periodic messages has been exceed. For the protocol associated with the communications channel."

It looks as if this is not having an effect on the device side, only on the API / running program side.

Let me remind you that the StopMsgFilter (idx) function did not work in the earlier API version as well, I tested it as well.

Conclusion: it looks like the StopAllMsgFilters () function only resets the filters inside the program, resets them from the filter list -> channelx.FilterList.Count (); and not the J2534.

In the git repo link sent, the device allows you to reset the filter list correctly. This information if there was still a suspicion that something is wrong with the hardware itself.

It is possible for you to debug it yourself on my computer via teamViewer. However, I would need your email address to submit your login details. Everything is currently connected so you can test and debug.

attached screen capture :

https://user-images.githubusercontent.com/7130668/103071801-ac351a80-45c4-11eb-8b16-3b49720920ec.mov

BrianHumlicek commented 3 years ago

There was a bug in the StopMsgFilter (and periodic messages) logic that was corrected with the last commit. It should be working as intended now. Your usage of StopMsgFilter(0) is incorrect, which is why it doesn't affect the FilterList.Count(). The Id that you pass in needs to be one of the Id that you get when you start the filter (vs a hard coded 0). This is why I have the FilterList to help keep track of that.

At the end of your video you show a call to ClearMsgFilters(). Because it appears your device doesn't support this, you should probably not be using that and instead use StopAllMsgFilters().

I browsed the development branch of the code base you linked and I can't find anywhere where they are stopping or clearing a message filter. What are you calling in that code base to 'reset the filter list correctly'?

tesla20000 commented 3 years ago

I finally solved the problem. Either your API works asynchronously when sending the filter reset commands, or the function does not wait for the confirmation that return from the device at all. In the end, a program that uses api (any) while implementing the programmer's intentions leads to an attempt to execute another command after cleaning the filters, for example set a new filter - if that's what the api user thought of. which results in fishiness because it happens too quickly - after all, the device has not yet reset the filters. just add a delay after zeroing 50-100mS and everything will work. It would be correct to wait in the API function for the end of filter resetting (synchronously, for example). Please note that there are j2534 TriCore processors - super fast, but also those on STM that require a little more time - are slower. Perhaps the tests on a fast device can be correct. The problem here was the time to execute the next order after resetting the filters.

Thank you for all the help and best regards.

BrianHumlicek commented 3 years ago

More than likely, the issue is a third possibility, which is a problem with your device and has been all along.

My library is verifiably 100% synchronous and absolutely waits for a return result before continuing execution. Going a step further, my library will synchronize access from multiple threads to ensure a call completes before initiating another.

Brian

tesla20000 commented 3 years ago

There is a possibility, but such devices are on the market and I believe other users will encounter this problem sooner or later. That's why I have described the solution. Thank you for professional support and best regards

BrianHumlicek commented 3 years ago

I'm closing this, as I don't believe there are any further issues with J2534 Sharp. If anything else comes up, either open another issue, or start a thread at the following. https://github.com/BrianHumlicek/J2534-Sharp/discussions