Filter Serial Data

Hi everyone, I originally posted this elsewhere on the forum, but I didnt get any meaningful help, I am hoping someone here can help. I am willing to pay for this.

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

Re: CanBus Filter
#3
Dec 02, 2014, 09:17 pm
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.

for the parsing you need something like this

int c = Serial.read();
long val = 0;

while (c != 13) // CR
{
   if ( ('0'<= c) && ( c <='9'))
   {
      val *= 10;
      val += c - '0';
   }
   // else skip other chars
}

You may donate your gift to Doctors without borders

Thank you Robtillaart, I will give that a try, and make a donation to DWB.

Cheers,

Great!

Okay after trying a few different programs, I have been able to print the variables from my PLC under ID 44C. You can see a screen shot of what it looks like in the attached file.

Now what I want to do is take this data that comes in from ID 44C and send out on the usb serial channel to Microsoft Excel using PLX-DAQ.

I have tried the PLX-DAQ examples and they work well, the Canbus example works well, but I need to put both of them together and I will be set. Once in Excel, I can convert the data from 8 Bit to Decimal and parse it how I need it.

Any thoughts on how to do this?

Below is the Canbus example program.

// 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
*********************************************************************************************************/

Here is the Serial Output Data Screen Shot.

Hey folks, doesn't anyone want to help, and get paid for it? In need of some assistance on this one.

Thanks in advance.

Sorry, I do have to little time to get another paid job (and I do not have the HW to mirror the system)

Have you solved your problem?
Do you receive your current data packets in PLX-DAQ? And only filtering is left to do? Or is there any other data manipulation needed?

Okay folks, I solved my problem myself.