BrianHumlicek / J2534-Sharp

A .Net interface for J2534 vehicle communications.
Other
41 stars 13 forks source link

29 bit send #20

Closed SergeySergeevitch closed 1 year ago

SergeySergeevitch commented 3 years ago

using (Channel Channel = Device.GetChannel(Protocol.CAN, Baud.CAN_500000, ConnectFlag.CAN_29BIT_ID)) { Channel.StartMsgFilter(FlowControlFilter); Channel.SendMessage(new byte[] { 0x1f, 0xff, 0xff, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}); GetMessageResults Response = Channel.GetMessage(); }

receive ID = 701

BrianHumlicek commented 3 years ago

What exactly is the issue? I’m guessing you are expecting a longer receive address back?

SergeySergeevitch commented 3 years ago

The 11-bit header goes to the bus, not 29.

BrianHumlicek commented 3 years ago

You need to use the 29bit flag on the tx flags with the message.

BrianHumlicek commented 3 years ago

The easiest thing to do is probably set the defaulttxflags on the channel before you call sendmessage

SergeySergeevitch commented 3 years ago

ConnectFlag.CAN_29BIT_ID - i use. There is a suspicion that this flag is not being processed.

BrianHumlicek commented 3 years ago

The txflags are separate from the connect flags. You need to use both to make 29bit work.

SergeySergeevitch commented 3 years ago

can I have an example?

SergeySergeevitch commented 3 years ago

This does not work:

    private void button1_Click(object sender, EventArgs e)
    {
        MessageFilter PassControlFilter = new MessageFilter()
        {
            FilterType = Filter.PASS_FILTER,
            Mask = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF },
            Pattern = new byte[] { 0x1F, 0xFF, 0xFF, 0x01 },
            FlowControl = new byte[] { 0x1F, 0xFF, 0xFF, 0x01 },
            TxFlags = TxFlag.CAN_29BIT_ID
        };

        String DllFileName = "C:\\Windows\\SysWOW64\\op20pt32.dll";// string DllFileName = APIFactory.GetAPIinfo().First().Filename;

        using (API API = APIFactory.GetAPI(DllFileName))
        using (Device Device = API.GetDevice())
        using (Channel Channel = Device.GetChannel(Protocol.CAN, Baud.CAN_500000, ConnectFlag.CAN_29BIT_ID))
        {
            Channel.StartMsgFilter(PassControlFilter);
            richTextBox1.AppendText($"Voltage is {Channel.MeasureBatteryVoltage() / 1000}");
            Channel.SendMessage(new byte[] { 0x1f, 0xff, 0xff, 0x02, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08});
            GetMessageResults Response = Channel.GetMessage();
        }

    }
BrianHumlicek commented 2 years ago

Sorry I didn't follow up.

You need to set Channel.DefaultTxFlags |= TxFlag.CAN_29BIT_ID;

In looking at this, it would probably make sense to make that the default flags when a 29bit connection is made. I will look at comitting this soon.

Brian

    private void button1_Click(object sender, EventArgs e)
    {
        MessageFilter PassControlFilter = new MessageFilter()
        {
            FilterType = Filter.PASS_FILTER,
            Mask = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF },
            Pattern = new byte[] { 0x1F, 0xFF, 0xFF, 0x01 },
            FlowControl = new byte[] { 0x1F, 0xFF, 0xFF, 0x01 },
            TxFlags = TxFlag.CAN_29BIT_ID
        };

        String DllFileName = "C:\\Windows\\SysWOW64\\op20pt32.dll";// string DllFileName = APIFactory.GetAPIinfo().First().Filename;

        using (API API = APIFactory.GetAPI(DllFileName))
        using (Device Device = API.GetDevice())
        using (Channel Channel = Device.GetChannel(Protocol.CAN, Baud.CAN_500000, ConnectFlag.CAN_29BIT_ID))
        {
            Channel.DefaultTxFlags |= TxFlag.CAN_29BIT_ID;
            Channel.StartMsgFilter(PassControlFilter);
            richTextBox1.AppendText($"Voltage is {Channel.MeasureBatteryVoltage() / 1000}");
            Channel.SendMessage(new byte[] { 0x1f, 0xff, 0xff, 0x02, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08});
            GetMessageResults Response = Channel.GetMessage();
        }

    }