Skip to content

Modbux.Tcp.Client terminates when TCP response contains 2 payloads #14

@pojiro

Description

@pojiro

Hi, thanks for your modbus library. I found an issue when I use this library. So I report.

What happens

Modbux.Tcp.Client terminates when TCP response contains 2 payloads.
Following is the log,

07:10:12.450 [error] (Elixir.Modbux.Tcp) size = 5, payload_size = 17, msg = <<0x7, 0x8E, 0x0, 0x0, 0x0, 0x5, 0x0, 0x2, 0x2, 0x1, 0x80, 0x7, 0x8F, 0x0, 0x0, 0x0, 0x6, 0x0, 0x5, 0x0, 0x10, 0xFF, 0x0>>

07:10:12.450 [error] GenServer #PID<0.17883.0> terminating
** (FunctionClauseError) no function clause matching in Modbux.Response.parse/2
    (modbux 0.3.13) lib/helpers/response.ex:64: Modbux.Response.parse({:ri, 0, 0, 16}, nil)
    (modbux 0.3.13) lib/tcp/client.ex:330: Modbux.Tcp.Client.handle_info/2
    (stdlib 6.0) gen_server.erl:2173: :gen_server.try_handle_info/3
    (stdlib 6.0) gen_server.erl:2261: :gen_server.handle_msg/6
    (stdlib 6.0) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: {:tcp, #Port<0.10199>, <<7, 142, 0, 0, 0, 5, 0, 2, 2, 1, 128, 7, 143, 0, 0, 0, 6, 0, 5, 0, 16, 255, 0>>}
** (EXIT from #PID<0.17850.0>) shell process exited with reason: an exception was raised:
    ** (FunctionClauseError) no function clause matching in Modbux.Response.parse/2
        (modbux 0.3.13) lib/helpers/response.ex:64: Modbux.Response.parse({:ri, 0, 0, 16}, nil)
        (modbux 0.3.13) lib/tcp/client.ex:330: Modbux.Tcp.Client.handle_info/2
        (stdlib 6.0) gen_server.erl:2173: :gen_server.try_handle_info/3
        (stdlib 6.0) gen_server.erl:2261: :gen_server.handle_msg/6
        (stdlib 6.0) proc_lib.erl:329: :proc_lib.init_p_do_apply/3

There are two payloads in the response.

  1. <<0x7, 0x8E, 0x0, 0x0, 0x0, 0x5, 0x0, 0x2, 0x2, 0x1, 0x80>>
  2. <<0x7, 0x8F, 0x0, 0x0, 0x0, 0x6, 0x0, 0x5, 0x0, 0x10, 0xFF, 0x0>>

But following code try to handle this response as one payload, so it fails.

def handle_info({:tcp, _port, response}, state) do


If you need any info, let me know. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions