sympthom / Valley.Net.Protocols.MeterBus

M-Bus (meter bus, meterbus, mbus) C# project for communicating and parsing M-Bus (EN 13757-2 and EN 13757-3)
MIT License
39 stars 21 forks source link

TCP Connection (Binding) - only one requestData call works #10

Open ebsevon opened 4 years ago

ebsevon commented 4 years ago

I am using the TcpBinding and interacting with a Moxa (TCP to Serial) converter to read one MBUS Device.

To intialisation of the MBusMaster I use following code: _var serializer = new MeterbusFrameSerializer(); endpoint = new IPEndPoint(IPAddress.Parse(“192.168.100.41”), 4001); binding = new TcpBinding(endpoint,serializer); binding.Error += Binding_Error; binding.IoCompleted += Binding_IoCompleted; master = new MBusMaster(binding); master.Meter += Master_Meter;_

Afterwards I am calling RequestData every five seconds: var response = master.RequestData((byte)MBusAdr, TimeSpan.FromSeconds(3)).Result as VariableDataPacket;

This works only for the first call. The second call rises following exception (Socket Exception):

AggregateException SocketException: A request to send or receive data was prevented because the socket is not connected and (when sending via a datagram socket with a sendto call) no address was specified

Is there anything wrong in my workflow or code?

RJvdBerg commented 1 year ago

Seems like a bug, but I implemented my own TcpClient, to send and receive the raw data.