This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

UDP SOCKET
#1
Hello:
We have several devices on the network that send packages continuously: energy meters.
We need to read these packages and we have tried using the following scritp:

if not server then
  require('socket')
  server = socket.udp()
  server:setsockname('*', 8891)
  server:settimeout(1)
end

data = server:receive()
if data then
  loghex(data)
end


If we log setsockename address already in use.
Is this method correct to receive that kind of data from network.
Thanks.
Reply
#2
This means that another script is already bound to this UDP port. You can find script PID like this:
Code:
res = io.readfile('netstat -puln | grep 8891')
log(res)
Or open print view for all scripts (Scripting > Tools > Print script listings) and search for 8891 there.
Reply
#3
(12.09.2019, 11:14)admin Wrote: This means that another script is already bound to this UDP port. You can find script PID like this:
Code:
res = io.readfile('netstat -puln | grep 8891')
log(res)
Or open print view for all scripts (Scripting > Tools > Print script listings) and search for 8891 there.

Hi again:

The system that I try to read is a energy meter concentrator. We manage to communicate with the device through the usr-vcom application and we receive data. The system was already installed when our clients hire us but anybody know how read the data and there is not any program.

We have test with protocol modbus, mbus and there is no response. The communication throught USR-TCP232-T2 -  (TTL - ETHERNET).

When a create a socket.tcp the connection is correct but receive is nil. What could be the problem.?

Thanks for your help
Best Regards.




Reply
#4
ModBus won't work like this as ModBus TCP is a different protocol.

If you are calling socket:receive() without any arguments it will try to read a whole line ending with \n character. For binary protocols this won't work correctly. You can read data by one byte at a time: byte, err = socket:receive(1)
Reply


Forum Jump: