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

Thanks. Like some of the approaches I've tried, it works for values that are not assigned to printable ASCII characters. If the value is assigned to a printable character in the ASCII set, then Perl will send the character from the ASCII set. So:
syswrite( $SERIALPORT, pack 'C', 44 ); #writes 0x2C onto the wire, so Perl evidently sees ASCII character 0d4 +4 in this case, not number 0d44
I have studied the pack, unpack, and packtut extensively, and conclude that they do not get the chance to come into play: Perl is tinkering with the write.

Replies are listed 'Best First'.
Re^3: syswrite numbers, not strings
by salva (Canon) on Dec 18, 2014 at 06:16 UTC
    0x2c and 0d44 are just different representations of the same number.
      I think my head has been in this too long, quite right. I do know the difference between numbers and radixes.
Re^3: syswrite numbers, not strings
by BrowserUk (Patriarch) on Dec 18, 2014 at 06:18 UTC
    I have studied the pack, unpack, and packtut extensively, and conclude that they do not get the chance to come into play: Perl is tinkering with the write.

    Sorry, but you are wrong. Your problem is one of your perception. Perl doesn't "tinker with the write".

    A byte with the numeric value of 44 is simply the bit pattern 00101100. It will only be interpreted as an ascii character by whatever you are using to look at it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      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.

        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.)

Re^3: syswrite numbers, not strings
by RonW (Parson) on Dec 18, 2014 at 18:48 UTC

    Since I have a logic analyzer available to me, I connected it to my PC's serial port, ran your code and captured a trace, which I put as the image on my profile node.

    (I thought the monks might be curious to see what a byte on a serial port "looks" like.)