0

I'm trying to calculate the LRC value (Longitudinal Redundancy Check) in order to send a message to a pinpad.

All I know about LRC is: "It is calculated by performing an XOR of all the characters in the message, excluding the STX in the calculation."

I'm using this function to generate the LRC:

 Public Shared Function calculateLRC(bytes As Byte()) As Byte
    Dim LRC As Byte = 0
    For i As Integer = 0 To bytes.Length - 1
        LRC = LRC Xor bytes(i)
    Next
    Return CByte(LRC)
End Function

But I can't make that the pinpad answers me.

Now, I know that I have to send the message in HEX but I can't make that the pinpad answers me and I can't figure out if I have a problem calculating the LRC or i am making something else wrong.

The format is asked this way: < STX > < type of msg> < param>< ETX>< LRC>.

I already tried to calculate the LRC first and then convert everything to hex AND convert everything to hexa and then calculate the LRC but nohing works.

Any help is appreciated.

Edit: Ok, the LRC is ok. The issue is with the way i'm sending the data (mostly because I have so little documentation and I'm just trying everthing I can think of)

I'm gonna try to think how to explain the issues here cause, like I say, I have a very poor documentation and it is in spanish.

DenLun
  • 194
  • 2
  • 16
  • http://stackoverflow.com/questions/891664/calculate-block-check-character-bcc-for-serial-communication ? – Rubens Farias Dec 07 '13 at 02:14
  • It is *highly unlikely* that any "hex" is involved at all. "Hex" is not a word or term equivalent to *binary*, which is probably what is meant. I'd guess the troubles here begin with Unicode/ANSI conversion errors, but we've been shown far too little code to know what is going on. – Bob77 Dec 07 '13 at 13:16
  • Your calculateLRC function is correct so I suspect the problem is with how you are sending to the pinpad. Can you edit your question to show that code, and the documentation for what the pinpad expects? Also the code you have posted is not VB6. – jac Dec 07 '13 at 23:47
  • It was indeed a conversion error. I'm sorry for the poor code that I show, I just don't know much about this yet. Right now I know that my issue is not about STX, ETX or LRC. The issue is with the way I'm sending the data. – DenLun Dec 09 '13 at 23:27

0 Answers0