in reply to Re^3: syswrite numbers, not strings
in thread syswrite numbers, not strings

I'm using interceptty to watch the serial port, so I am confident about what is really happening, and understand why you pointed out that trap.
syswrite(FH, 45); #puts 0x34 0x35 onto the wire, as if I said '45'
and I do call that tinkering. I'm probably wrong in here somewhere, though, usually am.

I'm not sure what I've done, but now syswrite(FH, pack('C', $packet)) is working. Will test more.

Replies are listed 'Best First'.
Re^5: syswrite numbers, not strings
by Anonymous Monk on Dec 18, 2014 at 08:02 UTC

    Remember this is Perl, where conversion between strings and numbers is almost always automatic and transparent, so "tinkering" might be too strong a word. Although one could argue the documentation isn't perfectly clear on this, it's at least strongly implied that syswrite writes a byte array / string, not individual numbers as bytes, so the 45 gets converted to "45", which is 0x34 0x35. (That's one of the reasons pack exists.)

      Indeed, and I think that sums up the situation very well. I have said tinkering, because in this case it bit me, though I have almost certainly had beneficial use of the 'tinkering' at other times.