[erlang-questions] Binaries

Bob Ippolito bob@REDACTED
Tue Jun 19 19:08:02 CEST 2018


<<16#14,16#50,16#00,16#00,16#01>> and <<20,80,0,0,1>> 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.


On Tue, Jun 19, 2018 at 9:53 AM Bob Cowdery <bob@REDACTED> wrote:

> 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.
>
> On 6/19/2018 5:37 PM, Danil Zagoskin wrote:
>
> That's how erlang part communicates with C part.
> https://github.com/tomszilagyi/gen_serial/blob/master/src/gen_serial.erl
> #L622
> -define(PACKET_DATA, $d).
>
> send(#gen_serial{port = Port}, Data) ->
>   true = port_command(Port, [<<?PACKET_DATA:8>> | Data]),
>   ok.
>
> Maybe port_command does not expect an improper list — try one of these:
> * gen_serial:bsend(P,[<<20,80,0,0,1>>]) % Your binary wrapped in a list
> * gen_serial:bsend(P,[20,80,0,0,1]) % data as list instead of binary
>
> On Tue, Jun 19, 2018 at 7:22 PM Bob Cowdery <bob@REDACTED>
> 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
>>
>
>
> --
> Danil Zagoskin | z@REDACTED
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180619/1cc416d2/attachment.htm>


More information about the erlang-questions mailing list