Monday, April 25, 2011

serialport.Write() - how to format bytes properly

I am required to talk back to the scale by making it PRINT programmatically.

The manual states that the print command is simply P ended with carriage return. I use the following code:

Byte[] bytes = {80, 13};
_sp.Write(bytes,0,bytes.Length);

But every other time I get ES code back from the scale which means error but it still prints. I just want to find out why even though it works, I am getting ES back.

Any ideas? Is the format of bytes[] correct?

From stackoverflow
  • The bytes are correct, according to what you say that the manual states.

    Perhaps the manual is unclear (or has this specified elsewhere), and by "carriage return" actually means the CR+LF newline sequence that is used in some systems (e.g. MS-DOS). The bytes would then be:

    Byte[] bytes = { 80, 13, 10 };
    
    gnomixa : thanks I will try that.
    gnomixa : I am getting ES code back on this every time...if I don't append 10, I get it once in awhile. Not sure why the damn balance not liking the format that's clearly specfied
    gnomixa : as i mentioned, i do get the weight sent back to the balance. But I would like to either swallow ES or understand WHY I am getting it back.

0 comments:

Post a Comment