LRC generation

Forums for specific tips, techniques and example code
concord
Posts: 47
Joined: Wed Mar 23, 2011 2:07 pm

LRC generation

Postby concord » Thu Aug 13, 2020 4:03 pm

Hi there,

Does anyone have any Jade code to generate a Longitudinal Redundancy Check?

concord
Posts: 47
Joined: Wed Mar 23, 2011 2:07 pm

Re: LRC generation

Postby concord » Thu Aug 20, 2020 3:11 pm

Oops, got tripped not realising ^ in Jade is different to almost all other languages.
The Binary primitive method was easy to put together...

Code: Select all

vars i : Integer; lrc : Integer; begin lrc := null; i := 1; while i <= self.length do lrc := lrc.bitXor (self[i]); i := i + 1; endwhile; return lrc.Character; end;

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: LRC generation

Postby BeeJay » Tue Aug 25, 2020 2:59 pm

Hi Concord,

Actually the ^ symbol was used as the 'power of' for quite a lot of languages until more recently when some languages started using it for the bitwise logical exclusive or operation instead of the 'power of'... I was used to using ^ as power of long before I started coding in JADE.

If you've tried to turn the following C# code into your LRC routine, I wonder if you should assign lrc := 255; instead of lrc := null; so that the sample binary 02 30 30 31 23 03 results in 0xEC for the LRC character instead of 0x13 as per your current routine?

// 2012.06.11 C# Code from Edwards TurboPump Controller SCU-1600: Serial Communication LRC Logic.
// eg: Data (6bytes hexa): 02 30 30 31 23 03 should result in LRC of 0xEC

public byte MakeLRC ( byte[] bytes )
 {
  byte LRC = 0xff;

  for ( int i = 0 ; i < bytes.Length ; i++ )
   {
    LRC ^= bytes[ i ];
   }

  return LRC;
 }
Cheers,
BeeJay.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 8 guests