Receive Buffer Always EMPTY

Pass-Thru API and connection of Pass-Thru software to PEAK CAN interfaces.
Post Reply
soner
Posts: 4
Joined: Tue 22. Dec 2020, 11:24

Receive Buffer Always EMPTY

Post by soner » Tue 22. Dec 2020, 12:07

Hi,

I search a topic for my issue. I found this topic.
I tried the methods in the topic.

But i still can't receive any message.

I tried no filter and filter ID : 0x12345678

There are debug files in the attachments.

I tried 250K and 500K Baudrates.
I tried PassThruConnect with CAN_ID_BOTH and CAN_29BIT_ID.

I am using PassThruReadMsgs with 100ms timeout in the while loop.
I can send a message to another PCAN connecting to another PC. (ID : 0x7DF DATA: [01 00 05 06])

I can see my messages on the trace file but my C# program can't receive.
Attachments
FILTER_20201222133830_00.csv
(2.26 KiB) Downloaded 5212 times
NO_FILTER_20201222134001_PCAN_USBBUS1_1.trc
(1.06 KiB) Downloaded 5203 times
NO_FILTER_20201222134001_00.csv
(2.31 KiB) Downloaded 5179 times
FILTER_20201222133830_PCAN_USBBUS1_1.trc
(1.06 KiB) Downloaded 5132 times

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: Receive Buffer Always EMPTY

Post by M.Heidemann » Tue 22. Dec 2020, 14:54

Hello,

Thank you for your request and
the provided information.

Can you share your code with us,
so we can investigate this issue further?


Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

soner
Posts: 4
Joined: Tue 22. Dec 2020, 11:24

Re: Receive Buffer Always EMPTY

Post by soner » Tue 22. Dec 2020, 15:12

Hi,
I am using link removed --> search github.com/mkelly/J2534DotNet] repository for C# application.

and my application code is here:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PCAN_PassThru
{
    class Program
    {
        public static bool is_run = true;

        public static J2534Err status;
        public static J2534Extended passThru = new J2534Extended();
        public static List<J2534Device> availableJ2534Devices = J2534Detect.ListDevices();
        public static J2534Device j2534Device;
        public static int deviceId = 0;
        public static int channelId = 0;
        public static int filterId = 0;


        static void Main(string[] args)
        {
            // Add CTRL+C signal event handler.
            Console.CancelKeyPress += new ConsoleCancelEventHandler(ExitHandler);

            // Kvaser
            //J2534Device j2534Device = availableJ2534Devices[0];

            // Peak-CAN
            j2534Device = availableJ2534Devices[1];


            Console.WriteLine("Load Library : {0}", j2534Device.FunctionLibrary);
            // We will always choose the first J2534 device in the list, if there are multiple devices
            //   installed, you should do something more intelligent.
            passThru.LoadLibrary(j2534Device);

            Console.WriteLine("Open Device");
            // Attempt to open a communication link with the pass thru device
            
            status = passThru.PassThruOpen(IntPtr.Zero, ref deviceId);

            Console.WriteLine("Open Channel");
            // Open a new channel configured for ISO15765 (CAN)
            status = passThru.PassThruConnect(deviceId, ProtocolID.CAN, ConnectFlag.CAN_ID_BOTH, BaudRate.CAN_250000, ref channelId);

            Console.WriteLine("Apply Filter");
            // Set up a message filter to watch for response messages
           
            PassThruMsg maskMsg = new PassThruMsg(
                ProtocolID.CAN,
                TxFlag.CAN_29BIT_ID,
                new byte[] { 0x00, 0x00, 0x00, 0x00 });

            PassThruMsg patternMsg = new PassThruMsg(
                ProtocolID.CAN,
                TxFlag.CAN_29BIT_ID,
                new byte[] { 0x00, 0x00, 0x00, 0x00 });

            IntPtr maskMsgPtr = maskMsg.ToIntPtr();
            IntPtr patternMsgPtr = patternMsg.ToIntPtr();
            status = passThru.PassThruStartMsgFilter(channelId, FilterType.PASS_FILTER, maskMsgPtr, patternMsgPtr, IntPtr.Zero, ref filterId);

            Console.WriteLine("Clear RX Buffer");
            // Clear out the response buffer so we know we're getting the freshest possible data
            status = passThru.ClearRxBuffer(channelId);

            Console.WriteLine("Send Message");
            // Finally we can send the message!
            PassThruMsg txMsg = new PassThruMsg(
                ProtocolID.CAN,
                TxFlag.NONE,
                new byte[] { 0x00, 0x00, 0x07, 0xDF, 0x01, 0x00, 0x05, 0x06 });

            var txMsgPtr = txMsg.ToIntPtr();
            int numMsgs = 1;
            status = passThru.PassThruWriteMsgs(channelId, txMsgPtr, ref numMsgs, 50);
            //status = passThru.PassThruStartPeriodicMsg(channelId, txMsgPtr, ref numMsgs, 100);


            ThreadStart threadDelegate = new ThreadStart(CANReadThreadFunc);
            Thread m_ReadThread = new Thread(threadDelegate);
            //m_ReadThread.IsBackground = true;
            m_ReadThread.Start();


#if DEBUG
            Console.WriteLine("\n\n\nPress enter to close...");
            Console.ReadLine();
#endif

        }

        static void CANReadThreadFunc()
        {
            Console.WriteLine("Read Messages");
            int numMsgs = 1;
            IntPtr rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)) * numMsgs);

            while (is_run)
            {
                status = passThru.PassThruReadMsgs(channelId, rxMsgs, ref numMsgs, 100);

                if (status != J2534Err.ERR_BUFFER_EMPTY && numMsgs > 0)
                {
                    foreach (PassThruMsg msg in rxMsgs.AsList<PassThruMsg>(numMsgs))
                    {
                        Console.WriteLine(msg.ToString());
                    }
                }

                // If we received data, we want to extract the data of interest.  I'm removing the reflection of the transmitted message.
                //if ((J2534Err.ERR_BUFFER_EMPTY == status || J2534Err.ERR_TIMEOUT == status) && numMsgs > 0)
                //{
                //    foreach (PassThruMsg msg in rxMsgs.AsList<PassThruMsg>(numMsgs))
                //    {
                //        Console.WriteLine(msg.ToString());
                //    }
                //}

            }

        }

        protected static void ExitHandler(object sender, ConsoleCancelEventArgs args)
        {
            Console.WriteLine("\n\rExit...", ConsoleColor.Red);
            is_run = false;

            Console.WriteLine("Disconnecting...");
            passThru.PassThruDisconnect(channelId);

            Console.WriteLine("Closing...");
            passThru.PassThruClose(deviceId);
        }
    }
}

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: Receive Buffer Always EMPTY

Post by M.Heidemann » Tue 22. Dec 2020, 16:18

Hello,

Please understand that we cannot support a third-party repository.

Have you tried to replicate this issue using our PCAN-PassThru API (AND DLL) without the use of the j2534-library? See
the existing issues on this Github, there is indication other users had similar issues using this library.

Can you confirm the same issue is present when only our API and Functions are used?

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

soner
Posts: 4
Joined: Tue 22. Dec 2020, 11:24

Re: Receive Buffer Always EMPTY

Post by soner » Wed 23. Dec 2020, 10:32

Thank you for your interest.

I already install PCAN-PassThru API but I have just a DLL file.
Could you provide any interface for C/C# so I can easily test PCAN functions.

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: Receive Buffer Always EMPTY

Post by M.Heidemann » Wed 23. Dec 2020, 11:18

Hello,

We do not provide header-files for the PCAN-PassThru API as its intended purpose
is to add support for software already using the J2534 standard.

The documentation contains an interface description, which you can refer to:

https://www.peak-system.com/produktcd/P ... an_eng.pdf

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

soner
Posts: 4
Joined: Tue 22. Dec 2020, 11:24

Re: Receive Buffer Always EMPTY

Post by soner » Fri 25. Dec 2020, 10:38

I solved my issue.
I was not set numMsgs before every ReadMsgs call.

If buffer empty, numMsgs is set to 0 by the api. I must re-set numMsgs for read another messages. (at least numMsgs = 1)
SS 1.jpg
SS 1.jpg (42.59 KiB) Viewed 7069 times
Now I can read 100ms repeated messages.
SS 2.jpg
SS 2.jpg (254.15 KiB) Viewed 7069 times

Post Reply