Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a frame to a device: first CAN steps

Hello,

is it possible to help me getting started with writing a frame to a CAN device.

At a baudrate of 100Kb, I need to write the following to a CAN-device:
id 0xcff2217 (extended CAN)
data bytes: 0x71 0x00 0x00 0x00 0x00 0x00 0x00 0x00

I'm trying to use (change) the NI Visual Basic software example Single Sample Output.vbp (PXI-8460 CAN)for this task (functions nctInitStart, nctWrite).

How will these functions look like to write this.
How many channels do I need to write this data ?
A (Visual Basic) code sample would be very useful.

With thanks,

best regards,

Geert
0 Kudos
Message 1 of 8
(5,620 Views)
Hi Geert,

1. For setting the baudrate:

You can do that with the ncConfigCANNet function.
Check the manual that comes with the CAN driver.

2. Using Extended CAN:

When you use extended CAN you need to OR your arbitration ID with 0x20000000 before you send it. Setting that bit true tells the NI-CAN you are using extended(29bit) ID's.

Check the links below about this issue:

http://digital.ni.com/public.nsf/websearch/3C2EBAAD7C278EF186256F19005FA41C?OpenDocument

http://digital.ni.com/public.nsf/websearch/E834440265FD497986256968005DF85F?OpenDocument

Check chapter 8 in the NI-CAN Hardware and Software manual.

http://digital.ni.com/public.nsf/websearch/2FA120A37EDBC51D86256854004FB0C7?OpenDocument

You need only 1 CAN Channel to do this.

I'
m afraid that I don't have an example for VB but you just have to make some changes to the ncWriteNet function. Everything should be explained in the NI-CAN manual.

Kind Regards.

JV
AE NIBE
0 Kudos
Message 2 of 8
(5,617 Views)
Hello Joris,

thank you for your answer.

I'm going to learn how to use these functions and try them out.

Sample code in C++ is also welcome. Or an active X component (ocx) able to handle the CAN bus communication.

Best regards,

Geert
0 Kudos
Message 3 of 8
(5,617 Views)
Hello,

does somebody knows where to find information (if possible with examples) about f.i. nctPropMsgArbitrationId = 100010
in the attachted file.

All I can find in the NI-CAN Hardware and Software Manual pdf about nctPropMsgArbitrationId
"u32 nctPropMsgArbitrationId
Returns the arbitration ID of the channel�s message.
To determine whether the ID is standard (11-bit) or extended (29-bit), get the
nctPropMsgIsExtended property.
The value of this property is originally set within MAX or the CAN database and cannot
be changed using nctSetProperty.

My CAN message and CAN channel is set in MAX (and saved in a ncd-file). The program using this module1 is using this ncd-file.

Why the nctPropMsgArbitrationId is set to 100010 in
the module ?

And how to set (when needed when using a ncd-file ?) nctPropMsgArbitrationId = when the sending ID is 0xCFF2217 (extended can) and the receiving device has ID 0xCFF2403 (extended can) ?

With thanks,

best regards,

Geert
0 Kudos
Message 4 of 8
(5,617 Views)
Hi Geert,

don't get confused by those numbers. The attached file looks like a part of a *.bas file (a header file for Visual Basic) to me. So this file makes 'nctPropMsgArbitrationId' equivalent to '100010'.
Those declarations are just there to make the usage of the properties easier, so instead of calling
status = nctGetProperty(TaskRef, ChannelName, 100010, sizeof(Value), &Value);
you can get the same result by calling
status = nctGetProperty(TaskRef, ChannelName, nctPropMsgArbitrationId, sizeof(Value), &Value);
which results in more readable code.

This has nothing to do with the actual value of the Arbitration ID, it's just a nicer way of asking the driver: "could you give me the currrent value of the 100010 property for t
his task?"

I hope I didn't misunderstand your problem.

-B2k
0 Kudos
Message 5 of 8
(5,617 Views)
Hello B2k,

thank you for your answer. My problem is that the Visual Basic NI-software example Single Sample Output.vbp gives values to variables for properties already configured by using MAX (see attached Gif-files) en saved in the example.ncd (attached and renamed to txt to make readable) for usage by the nican.dll.

Now it looks like the sample program doesn't use the MAX-properties but sets its own values ('nctPropMsgArbitrationId' equivalent to '100010',....)

How is it possible to make the program using the MAX properties from the ncd file ?

When I have to use for the sending ID(extended can)0xcff2217 , what should I use as value for nctPropMsgArbitrationId = ? 0xcff2217 isn't the right format,
so convert this hex to dec ?
218046999 ?

What value do I have to use to transmit the data bytes 0x71 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ?

With thanks,

best regards,

Geert
0 Kudos
Message 6 of 8
(5,617 Views)
Hi Geert,

those are not values of the property but the property ID. As there are mutiple different properties you can query from the driver (nctPropMsgName, nctPropMsgIsExtended, etc.), you need to tell the driver which property you are intereseted in. This is what the 'PropertyId' field in the nctGetProperty() function is for:

Status = nctGetProperty(TaskRef, "Channel0", PropertyId, sizeof(Value), *Value)

So, as you want to get the a particular property, in this case "Arbitration ID", you need to pass this information to the driver. This is done through the PropertyID field. The driver just knows that when you query ID # 100010, you want to get the "Arbitration ID". As this number (and all the other numbe
rs/IDs for the other properties) is pretty confusing to remember, the NI-CAN Channel API.bas file associates the numbers of the property IDs with an easier to understand text (constants). You called that file: Module1.txt. In this particular case:
nctPropMsgArbitrationId = 100010
This is just the identifier of that property, not the value!

So, both of the following function calls will do the exacte same thing:
Status = nctGetProperty(TaskRef, "Channel0", nctPropMsgArbitrationId , sizeof(Value), *Value)
Status = nctGetProperty(TaskRef, "Channel0", 100010, sizeof(Value), *Value)

In your case, 'Value' will be set to 0xCFF2217.

I hope this clarifies this a little bit,
-B2k
0 Kudos
Message 7 of 8
(5,617 Views)
Hello B2k,

thank you again for your answer.

Best regards,

Geert
0 Kudos
Message 8 of 8
(5,617 Views)