[erlang-questions] Binaries

Bob Cowdery bob@REDACTED
Tue Jun 19 18:35:57 CEST 2018


I think something got messed up. It's not failing now but just does 
nothing. So the encoding on the wire is different for the two versions 
that are numerically the same.


On 6/19/2018 5:22 PM, Bob Cowdery wrote:
> Thanks for all the suggestions. Still a little confused. The number is 
> an integer, actually a frequency in Hz plus a command byte at the end 
> which is being sent over a serial connection in hex format using 
> gen_serial.
>
> This command works: gen_serial:bsend(P, 
> <<16#14,16#50,16#00,16#00,16#01>>). where P is the open Port.
>
> However, when I use any of the methods to create a hex version they 
> all end up with <<20,80,0,0,1>> which to my mind is the decimal equiv 
> of above.
>
> If I fire that I get:
>
> 5> gen_serial:bsend(P,<<20,80,0,0,1>>).
> ** exception error: bad argument
>      in function  port_command/2
>         called as port_command(#Port<0.470>,[<<"d">>|<<20,80,0,0,1>>])
>      in call from gen_serial:send/2 (gen_serial.erl, line 624)
>      in call from gen_serial:bsend/3 (gen_serial.erl, line 706)
>
> What is <<"d">> doing in there?
>
>
> On 6/19/2018 4:32 PM, Bob Cowdery wrote:
>> If I have a number, say 1450000001 and I want to represent that as a 
>> binary in the form
>>
>>  <<16#14,16#50,16#00,16#00,16#01>> what's the best way.
>>
>> I'm not sure what list_to_binary(integer_to_list(1450000001)) which 
>> prints as <<"1450000001">> produces but I guess its 10 bytes not 5.
>>
>> BobC
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list