CanBus Filter

Hello All, here is what I have,

Arduino Uno running Receive_Check sketch,
SeeedStudio Canbus shield
Canbus master PLC.

I have the Canbus shield hooked up to the Canbus master PLC, I am reading data from the Canbus master, on the master I am transmitting two integer values over network variables. The data stream from the Master is listed below:

On the left hand column, 22 indicates the node address I am suppose to be transmitting too, 128 is the the heartbeat from the master.

From the left column, 5 rows down , "232 3" = 3*255+232+3=1000 This is the correct for the first integer variable.

3rd column from the left, 5 rows down, "230 1" = 1*255+230+1=486 This is correct for the second integer variable.

How can I construct a filter to pull these variables out of the data stream coming from the Can master? This pattern is constant, so there should be a way to set up a filter to pull these 8 bit numbers out of the data stream. Any help would be appreciated.

Thanks, Edmhydraulics

22 0 0 0 0 0 0 0
128 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
232 3 230 1
232 3 230 1
22 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
232 3 230 1
0 0 0 0 0 0 0 0
232 3 230 1
232 3 230 1
22 0 0 0 0 0 0 0
128 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
232 3 230 1
232 3 230 1
232 3 230 1
22 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
232 3 230 1
232 3 230 1
22 0 0 0 0 0 0 0
128 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

What you need to write is a some sort o finite state machine.

What would a finite state machine look like????

Okay, after fiddling around with things somewhat, what I am able to do is send out variables in bit format from my PLC. What I would like to be able to do is parse several bits together to and convert to an integer.

so for a data string such as:

1 25 64

to write an integer of 12564.

I can add commas to

Serial.print(buf*);Serial.print(",\t,");*
Which will act as a delimiter so my data string will be
,1, ,25, ,64,
So how do I parse and concat based on that?
Thanks for any help offered.

Okay, after playing with a few different programs I am able to print the messages coming from my PLC to the Arduino Can Channel, ID 44C is the proper ID from my PLC. What I would like to be able to do now is take this data from the Can channel and send it out to my computer via PLX-DAQ on the USB.

I have tried the PLX-DAQ examples and they work well, now I want to combine the two functions, Canbus and PLX-Daq so I can read the Canbus data in Microsoft Excel. Once in Excel I can parse the data and format it from 8 bit to Decimal.

Below is a screen shot from the serial output running the Canbus program. I have also included the code from the Canbus example.

Any help is appreciated.

Thanks,

// demo: CAN-BUS Shield, receive data
#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];

MCP_CAN CAN0(10);                               // Set CS to pin 10


void setup()
{
  Serial.begin(115200);
  CAN0.begin(CAN_250KBPS);                       // init can bus : baudrate = 500k 
  pinMode(2, INPUT);                            // Setting pin 2 for /INT input
  Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
    if(!digitalRead(2))                         // If pin 2 is low, read receive buffer
    {
      CAN0.readMsgBuf(&len, rxBuf);              // Read data: len = data length, buf = data byte(s)
      rxId = CAN0.getCanId();                    // Get message ID
      Serial.print("ID: ");
      Serial.print(rxId, HEX);
      Serial.print("  Data: ");
      for(int i = 0; i<len; i++)                // Print each byte of the data
      {
        if(rxBuf[i] < 0x10)                     // If data byte is less than 0x10, add a leading zero
        {
          Serial.print("0");
        }
        Serial.print(rxBuf[i], HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
}

/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

Hey folks, could really use some assistance on this one, I need this last bit of help before my project is complete. I really need help merging the Canbus Sketch to the PLX-DAQ sketch so I can read my Canbus Variables in Excel. Any help at all will be appreciated, getting desperate here, willing to pay if I need to.

Thanks in Advance. :o

Okay, problem solved, by myself.