• Post Reply Bookmark Topic Watch Topic
  • New Topic

Translate to java?  RSS feed

 
Niklas Karlsson
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Translate to java?
Hi
W hava a rs232-communication protocol script that I don't understand, and it is not shown what language the example is) do you have any idea what itshould doing?

Example :


I think is as a XOR for check if it is the end of messages or so..
But how do I use it and translate this to Java?
And get the real data out. ..
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For 'unsigned char' use 'byte'. For 'char*' use 'byte[]'.
See if that helps.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niklas Karlsson wrote:W hava a rs232-communication protocol script that I don't understand, and it is not shown what language the example is)

Looks like C to me.

do you have any idea what it should doing?

No, but I have an idea what it IS doing: It's returning a 7-bit checksum for a string (or possibly stream) of characters - which are equivalent to a byte in Java.

Basically, it's an error-checking method.

HIH

Winston
 
Niklas Karlsson
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so if it is a checker, what can be the whanted return value?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niklas Karlsson wrote:Ok so if it is a checker, what can be the wanted return value?

The checksum. That's how they work.

The normal thing is that something, somewhere sends (or reads) the checksum first, and then compares the result with what it expects it to be.

Not knowing the RS232 protocol in detail, I can't tell you how that's done, but that's the general principle.

Winston
 
Niklas Karlsson
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:For 'unsigned char' use 'byte'. For 'char*' use 'byte[]'.
See if that helps.

So:

?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The latter code is probably better, since Java has a way of finding the size of an array but C doesn't. So it would be preferable to use the latter code IF, IF... the value of Len is actually the length of the array in the first parameter. I would assume that's the case, why would you want the checksum of part of an array, but it would be worth checking the code which calls this method to confirm.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!