PCAN-RS-232 message filtering

Programmable Converter for RS-232 to CAN
Post Reply
User avatar
socketwrench54
Posts: 3
Joined: Tue 16. Feb 2021, 14:31

PCAN-RS-232 message filtering

Post by socketwrench54 » Tue 16. Feb 2021, 14:32

I am wanting to use the PCAN-RS-232 device to transmit CAN messages to/from an RS-232 component. The PCAN-RS-232 device will be on a CAN bus with multiple other CAN devices. In the default flashed programme, how do we know which message identifiers are transmitted through from CAN to RS-232? For example can I define that only messages with identifiers 0x201, 0x202 etc. are passed on from the PCAN-RS-232 to the RS-232 device? If so, what would be the best method to go about setting this up?

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-RS-232 message filtering

Post by M.Heidemann » Tue 16. Feb 2021, 15:45

Hello,

You can set hardware filters in the delivery hardware via a serial command,
this is documented in the HELP-Filefor the example 06_CAN_TO_SER_COMMAND
provided with the Development Package.
RS-232 Filters.PNG
RS-232 Filters.PNG (139.86 KiB) Viewed 6744 times
The documentation also gives a brief insight on how these filters are used.

If you only want to send specific messages that are within a certain range, this is a valid approach.

However if you need more flexibility, you might want to handle this by adjusting the firmware-code.

I assume you want to stick with the example 06_CAN-TO_SER_COAMMND:

If you want to filter specific messages via code,
you'll have to modify the function "ProcessMsgFromCan" in the "pcan-rsr-232.c"-file to acommendate
the conditions that determine the CAN-messages being sent.

If you want examples for how these conditions can be defined, have a look at the example "04_CAN_TO_SER_ASCII",
as it shows how specific ID are written to RS-232 based on their ID:

Code: Select all

	
			// catch ID 00000650h to send on serial as ascii
			if ( RxMsg.Id == 0x650  &&  RxMsg.Type == CAN_MSG_EXTENDED)
			{
				b8_t  textbuff[30];
				u32_t  textlen;
				
				
				// convert a 15-bit signal to ASCII text
				textlen = snprintf ( &textbuff[0], 30, "RPM = %d\n", RxMsg.Data16[0] & 0x7FFF);
				
				// send on serial to terminal
				SER_Write ( SER_PORT1, &textbuff[0], textlen);
			}
If your conditions are met, you can convert the message as shown in "ProcessMsgFromCan" and write it to Rs-232 via "SER_Write".

For further questions feel free to contact me again.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

User avatar
socketwrench54
Posts: 3
Joined: Tue 16. Feb 2021, 14:31

Re: PCAN-RS-232 message filtering

Post by socketwrench54 » Thu 18. Feb 2021, 15:20

Hi Marvin,
This is great and something I think we can work with. Looks like combining the SER_TO_CAN and CAN_TO_SER examples will allow bi-directional communication. I'll keep you updated.
Thanks,
SW

User avatar
socketwrench54
Posts: 3
Joined: Tue 16. Feb 2021, 14:31

Re: PCAN-RS-232 message filtering

Post by socketwrench54 » Wed 24. Feb 2021, 09:39

Hello again Marvin,
Looking through the code for 09_SER-TO-CAN I see there's a function that is called every 25 ms (see below from main.c. Is this a limitation for the hardware that you cannot process messages any faster? What would happen if this function was not called and I went straight to ProcessMsgFromCan()?

Code: Select all

	// main loop
	while (1)
	{
		//-------------------------------------------------
		// call every 25msec (for doing cyclic things ...)
		if (SYSTIME_DIFF (TimeDiff25ms, SYSTIME_NOW) > 25000)
		{
			TimeDiff25ms=SYSTIME_NOW;
			ProcessTimer25msec(); // do cyclic stuff herein...
		}
		//-------------------------------------------------

		// 1Hz LED Blinker (500 msec on, 500 msec off)
		if (SYSTIME_DIFF (TimeDiffLed, SYSTIME_NOW) > 500000)
		{
			TimeDiffLed = SYSTIME_NOW;

			// toggle LED
			if (BlinkState != HW_LED_GREEN)
			{
				BlinkState = HW_LED_GREEN;
			}
			else
			{
				BlinkState = HW_LED_OFF;
			}
			HW_SetLED (HW_LED_CAN1, BlinkState);
		}//IF: SYSTIME_DIFF
		//-------------------------------------------------

		ProcessMsgFromCan(); 	// read messages coming in from CAN ***in ser_to_can.c***
		ProcessMsgFromSerial(); // read messages coming in from RS232 UART ***in ser_to_can.c***
	}
}

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-RS-232 message filtering

Post by M.Heidemann » Wed 24. Feb 2021, 14:57

Hi;
I think you misunderstand whats happening here,
both ProcessMsgFromCan() and ProcessMsgFromSerial() are called
with every cycle (one after another).

You CAN excute something inside of ProcessTimer25msec() but you do not need to,
you might as well get rid of the timer-diff comparison and the correpsonding function calls,
they are simply implemented as a showcase for timed function calls, not because of hardware limitations.

Best Regards

marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply