SNAP-SCM-CAN2B for Vehicle use

I just wanted to open a thread on this device, and conglomerate with anyone else using it. I have been using it, learning it, but keeping it in its playpen. I use it for J1939 commercial vehicle standard.

My current snag is that it does not seem to except extended filters when using 29 bit IDs. It only sees the first 11 bits, like its stuck in standard, but it places them strangely. for example, my code that works:

nCPGNFilter0m1 = 0x1a1;// Filter 0:
nCPGNFilter1m1 = 0x0a1;// Filter 1:.
nCPGNFilter2m1 = 0xABB;// Filter 2:
nCPGNFilter3m1 = 0x1BB;// Filter 3:

nCPGNMask0m1 = 0x000FFF00; //mask for first 2
nCPGNMask1m1 = 0x000FFF00; // mask for remaining

With this I can filter the IDs: 0X1810A1A0, 0X1811A1A0 0X188ABBAB, 0x1881BBAB

If I try to use anything longer in “nCPGNFilterXm1”, it ignores the rest.

I would also like to know if anyone has used CAN data for processing in a strategy. I can’t figure out how to convert the HEX strings back into int32 so I can parse them for data. If I use the “HexStringTo___” actions, I always get 0.

Welcome to the forums!

Have you hooked into the ODB2 Port?

I thought about hooking this to the port in my Smart Car, but ended up using a Bluetooth adapter and the Torque app on Android.
That said, I am interested in what you are doing here.

Also, I think we need OptoMary for the Hex String thing… Let me go find her…

No, I have stuffed a lot of OBD ports over the years, and I’m sure it would work, but you probably wouldn’t understand any of the data unless you found some definitions. We are using Opto to monitor battery sets on electric transit buses. Since there isn’t yet really a set protocol, we’re kinda making one.

OptoMary here… I suspect that rather than HexStringTo… you’ll want the [B]Unpack[/B]String and[B] Pack[/B]… commands.
Can you tell me the exact variable values and types you’re trying to convert from and to, so I can give you a more specific example?

Also, I’m not familiar w/CAN in particular, but I notice that your nCPGNMask0m1 and 1m1 are identical, I’m not sure that’s what you meant?

Also, can you tell me more about the “ignores the rest” part? It’s likely that you need to use an int64 (vs. the int32s you’re showing above). The OptoScript syntax for assigning literals to variables would look something like this:

nnMyInt64Mask = 0x0011223344556677[B]i64[/B];

(The i64 there at the end tells the OptoScript compiler you want 64 bits rather than just 32.)

I hope that helps!

Mary: Im not sure how that works, I am just trying to manipulate the example code. I do notice that the “pgn” is always shorter than the ID, and matches the length of the non-zeros in the mask. for example, If I put in 0x12345678 as the filter (because I only want one ID) I would expect the mask to leave 0x00045600. Instead, i get 0x00012300.

There are 2 different filters assigned, they just happen to be the same.

There are no exact variables and values I am looking for. I am logging data and looking for changes. For example, If one of my CAN IDs has 8 bytes behind it, and in one of those bytes is a flag at bit 3, and 2 digit value at bits 6 and 7. then in 2 other bytes is a temperature reading. I want to be able to see all the data in binary, so I can set an alarm if the flag is 1, turn on a peripheral if the 2 digit value is above 0x0F, and if the temperature has changed since the last time i read it, record it to a log file. There is a wild variety of things that can be in those packets, so the easiest way for me to do that is bit wrangling whatever i get.

Just a note: I have already done all of this on a micro-controller. What i need the opto for is all the hardware, interfacing, and field readiness, so I have to make the Opto do what my MC did… However it would be kind of cool if you had an I/O module that had a user C++ programmable MC in it…
I don’t suppose there is a way to “pants” the brain box and program it with C?

…You could call it the Optduino…

1 Like

I figured out the “unpack string” and it works beautifully. I now have raw bits to sling. Filtering is still an issue.

Hi jglueck,

Can you tell me exactly how you’re using UnpackString? There was one issue w/it, KB coming soon (84757), the description is this: “UnpackString command, for 8- and 16- and 24-bit values into Int32, doesn’t work right”

Detail: “If the source string’s first two bytes consisted of 0xbd0xff and the unpack method was called to put the value into 32-bit int n, the value of n would be 0xffbd0000, rather than 0x0000ffbd, as it was supposed to be.”

I just want to make sure you’re not coding around this issue so that if/when you upgrade firmware with the fix your code then breaks. Know what I mean? Can you post your OptoScript?

I’ll see what I can find out about the filtering thing…


UnpackString(sPacketHeaderm1, 0, 4, bTempHead, 0, 0);
UnpackString(sPacketDatam1, 0, 8, bTempTail, 0, 0);

I may not have the above problem, because my lengths match. (bTempTail is a 64bit int)

New problem: Is there anything to consider when plucking a bit from a 64 bit integer? this method does not work:
bTempAlarm = (nSixtyfourBitInteger >> 8*6 bitAND 1);

I can fill that full of 1ns and still get 0.

Figured it out. BitRotate command != >> (or should i say <> >>). When you know more than one language, your not good at any of them. …

I have a suggestion for making the use of the CAN module easier.

Make a simple example for receiving CAN:

  1. N frills plug and play that reads all incoming CAN data. ( No filters )
  2. Displays data in HEX as default.
  3. Makes a table of received data that shows each header (ID) and its current data.

example string table would look something like this:

Time |Module(channel)| Type |#chr| ID | Data
00:00:00 0 std 3 250 00 01 02
00:00:00 0 std 5 251 00 01 02 03 04
00:00:00 0 err 3 200 00 00 01
00:00:00 0 ext 8 1820F4F5 00 01 02 FF 03 04 05 FF

  1. The table is indexed by its ID and overwrites itself when a new packet comes with of that ID.
  2. The ID becomes a tag for that data. Further strat can be written that pulls the data by its ID.

Ignore anything that implies that any data or ID has a definition ()until later in the strat.)

Transmission strategy can then use this to prevent transmitting an existing ID.
BTW, there is no “standard” or “extended” selection in the initial set-up of the PACCAN example?

Is there a way to determine CANbus errors? like the number of error messages, or percent, or is it just a matter of filtering the error header?

I am still anxiously awaiting a reply for this…(the time stamp idea) I have talked to James Davis too.

In the mean time, I have a new problem. I have found a behaviour with the verson 2.0 firmware, both beta and R2.0a, that cause my CAN line to crash. I will try to capture a sample on the scope today and load a photo or something, but as far as i can tell, this is what is happening:

version 1.0 is receive only, and everything works fine
when I upgrade to 2.0, and before I load a strategy (I can even have the brain removed from the panel and it still does this), some sort of “blip” comes out of the module, and crashes the HDK I am using to generate CAN traffic. I can observe the crash using busmaster, and can see a blip with a DVOM.

BTW, I cant find a 1.0 version for the CAN2B module in your archives…

Hi jglueck,
That 2.0 upgrade is relatively new, so probably not too many folks out in OptoLand using it yet. I’ve forwarded your info to our support team (support @ ) so they can get you sorted out.

any news on the time stamping example?

I am trying to cludge together a time stamp for this. I am rather disappointed that I am not getting a response here. The only thing that seems to work is if i run my own clock in a separate chart, and make a fake time stamp on the data as it comes out of the module. J Davis has been a big help, but there has to be a way to do this right.

Hi jglueck,
I’m not sure what you’re asking for here in terms of a time-stamp, but I did give some sample code in this post:
Is that close to what you’re looking for? If not, could you tell me more about what you mean by “run my own clock” and “fake time stamp”?