<div dir="ltr"><span style="color:rgb(33,33,33)"><<16#14,16#50,16#00,16#00,16#</span><span style="color:rgb(33,33,33)">01>></span> and <span style="color:rgb(33,33,33)"><<20,80,0,0,1>></span> are identical. If you're experiencing any difference in behavior when using those expressions, your problem is really somewhere else. Perhaps the device is stateful and not getting properly reset from one call to the next, or the port P was closed because the process died with an exception.<br><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 19, 2018 at 9:53 AM Bob Cowdery <<a href="mailto:bob@bobcowdery.plus.com">bob@bobcowdery.plus.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <p>The first does nothing and the second hangs. It's not gen-serial
      that's having a problem with it. It's sending it and giving ok but
      when decoded in the radio which obviously I can't look at it isn't
      a valid command. The encoding of
      <<16#14,16#50,16#00,16#00,16#01>> and
      <<20,80,0,0,1>> is somehow different.<br>
    </p></div><div text="#000000" bgcolor="#FFFFFF">
    <br>
    <div class="m_5159304675516810196moz-cite-prefix">On 6/19/2018 5:37 PM, Danil Zagoskin
      wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="SFMono-Regular, Consolas, Liberation Mono, Menlo,
              Courier, monospace" color="#24292e"><span style="font-size:12px;white-space:pre-wrap">That's how erlang part communicates with C part.</span></font></span></div>
        <div><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="SFMono-Regular, Consolas, Liberation Mono, Menlo,
              Courier, monospace" color="#24292e"><span style="font-size:12px;white-space:pre-wrap"><a href="https://github.com/tomszilagyi/gen_serial/blob/master/src/gen_serial.erl" target="_blank">https://github.com/tomszilagyi/gen_serial/blob/master/src/gen_serial.erl</a></span></font></span><font face="SFMono-Regular, Consolas, Liberation Mono, Menlo,
            Courier, monospace" color="#24292e"><span style="font-size:12px;white-space:pre-wrap">#L622</span></font></div>
        <div><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">
</span></div>
        <font face="monospace, monospace">-define(PACKET_DATA, $d).</font>
        <div><font face="monospace, monospace"><br>
            send(#gen_serial{port = Port}, Data) -><br>
              true = port_command(Port, [<<?PACKET_DATA:8>>
            | Data]),<br>
              ok.</font><br>
        </div>
        <div><font face="monospace, monospace"><br>
          </font></div>
        <div><font face="arial, helvetica, sans-serif">Maybe
            port_command does not expect an improper list — try one of
            these:</font></div>
        <div><font face="arial, helvetica, sans-serif"><span style="font-family:sans-serif;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">*
              gen_serial:bsend(P,[<<20,80,0,0</span><span style="font-family:sans-serif;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">,1>>])
              % Your binary wrapped in a list</span></font></div>
        <div><font face="arial, helvetica, sans-serif"><span style="font-family:sans-serif;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">*
                gen_serial:bsend(P,[20,80,0,0</span><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">,1])
                % data as list instead of binary</span></span></font></div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">On Tue, Jun 19, 2018 at 7:22 PM Bob Cowdery <<a href="mailto:bob@bobcowdery.plus.com" target="_blank">bob@bobcowdery.plus.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for
          all the suggestions. Still a little confused. The number is <br>
          an integer, actually a frequency in Hz plus a command byte at
          the end <br>
          which is being sent over a serial connection in hex format
          using <br>
          gen_serial.<br>
          <br>
          This command works: gen_serial:bsend(P, <br>
          <<16#14,16#50,16#00,16#00,16#01>>). where P is the
          open Port.<br>
          <br>
          However, when I use any of the methods to create a hex version
          they all <br>
          end up with <<20,80,0,0,1>> which to my mind is
          the decimal equiv of above.<br>
          <br>
          If I fire that I get:<br>
          <br>
          5> gen_serial:bsend(P,<<20,80,0,0,1>>).<br>
          ** exception error: bad argument<br>
                in function  port_command/2<br>
                   called as
port_command(#Port<0.470>,[<<"d">>|<<20,80,0,0,1>>])<br>
                in call from gen_serial:send/2 (gen_serial.erl, line
          624)<br>
                in call from gen_serial:bsend/3 (gen_serial.erl, line
          706)<br>
          <br>
          What is <<"d">> doing in there?<br>
          <br>
          <br>
          On 6/19/2018 4:32 PM, Bob Cowdery wrote:<br>
          > If I have a number, say 1450000001 and I want to
          represent that as a <br>
          > binary in the form<br>
          ><br>
          >  <<16#14,16#50,16#00,16#00,16#01>> what's the
          best way.<br>
          ><br>
          > I'm not sure what
          list_to_binary(integer_to_list(1450000001)) which <br>
          > prints as <<"1450000001">> produces but I
          guess its 10 bytes not 5.<br>
          ><br>
          > BobC<br>
          ><br>
          > _______________________________________________<br>
          > erlang-questions mailing list<br>
          > <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
          > <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
          <br>
          _______________________________________________<br>
          erlang-questions mailing list<br>
          <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
          <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
        </blockquote>
      </div>
      <br clear="all">
      <div><br>
      </div>
      -- <br>
      <div dir="ltr" class="m_5159304675516810196gmail_signature" data-smartmail="gmail_signature">
        <div dir="ltr">
          <div><font face="'courier new', monospace">Danil Zagoskin | <a href="mailto:z@gosk.in" target="_blank">z@gosk.in</a></font></div>
        </div>
      </div>
    </blockquote>
    <br>
  </div>

_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>