We help IT Professionals succeed at work.
Get Started

Vb.net calculate checksum

rfl
rfl asked
on
4,142 Views
Last Modified: 2014-08-21
I'm trying to communicate in vb.net with a scale, through the serial port. I can already communicate with the example provided by the manufacturer. However I do not know how to calculate the checksum of data sent to the scale.

Example supplied by the manufacturer:


1.1      Protocol
PC                                      Scale

                        98PPPPPCCRLF

            
Where

      98:       0x39h y 0x38h
PPPPP: 5 dígit for price
C:      Checksum, logical sum (XOR) of all preceding characters
CR:      0x0Dh                  LF: 0x0Ah

The scale expects the computer to send a message:
(Caracteres in ASCII)

      98PPPPPCCRLF
Where:
      9:      0x39h
      8:      0x38h
      PPPPP:      5 caracteres para el precio.
      C: Checksum.
      CR       0x13h
LF       0x10h

Checksum is an XOR, exclusive OR of all characters sent earlier, which is calculated as follows:
      0      XOR      0      0
      0      XOR      1      1
      1      XOR      0      1
      1      XOR      1      0


Will be doing XOR of all characters sent in hexadecimal, one by one:

Were sent 9 8 1 2 3 4 5 C CR LF
The value of C would:

      9:      0 0 1 1 1 0 0 1            (0x39h)
      8:      0 0 1 1 1 0 0 0            (0x38h)
            0 0 0 0 0 0 0 1
      1:      0 0 1 1 0 0 0 1            (0x31h)
            0 0 1 1 0 0 0 0
      2:      0 0 1 1 0 0 1 0            (0x32h)
            0 0 0 0 0 0 1 0
      3:      0 0 1 1 0 0 1 1            (0x33h)
            0 0 1 1 0 0 0 1
      4:      0 0 1 1 0 1 0 0            (0x34h)
            0 0 0 0 0 1 0 1
      5:      0 0 1 1 0 1 0 1            (0x35h)
            0 0 1 1 0 0 0 0            (0x30h)
The value of C would be 0 (0x30h), then the frame should be sent: 9 8 1 2 3 4 5 0 CR LF.
Comment
Watch Question
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE