UDP packet over Ethernet

Edmhydraulics

Member
Join Date
Apr 2014
Location
Beaumont
Posts
173
Good evening folks, I am working with a platform (Codesys) that is sending out a UDP Packet over Ethernet. I would to be able to view and manipulate this data on a computer, ultimately in Microsoft Excel.


I have set up the Codesys program and am able to see the data on the LAN with a packet sniffer program (Wireshark). Is there an easy way to parse the UDP packet and get the data I need or will I have to write a program in Python or something similar to pull out what I need?

I am simply broadcasting the data on 255.255.255.255 port 1202. I can see the broadcast message, and also see the STRING message I sent.

Anyone done anything similar with UDP packets?

Thanks in advance for any help.

Cheers,
 
I just finished writing an Ethernet driver for our motion controller

It was for a Mitsubishi PLC. I/We used UPD packets using sockets. What I had to do is build a header or use the return header to know what to do with the data.

This header is called the application layer.

I didn't broadcast the data. I had to specify the IP address of the motion controller the PLC was trying to command.

There must be a method to open an connection. A connection specifies an IP address and port used to communicate with the slave device.

I will need to ask my Ethernet guru about your broadcasting.
 
Using the mswinsock ocx you could receive UDP package directly in Excel. I did a quick test and this shows the udp package received on port 1202 in a messagebox in excel

Excel vba code

Code:
Public WithEvents UDPClient As Winsock

Private Sub UDPClient_DataArrival(ByVal bytesTotal As Long)
    Dim str As String

    UDPClient.GetData str, vbString

    MsgBox (str)

    
    
End Sub

Private Sub UDPClient_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

End Sub

Public Sub Connect()
    
    Set UDPClient = New Winsock
     UDPClient.Close

     UDPClient.Protocol = sckUDPProtocol

     UDPClient.Bind 1202

End Sub
 
Last edited:
I think you are using the Network Variables capability of Codesys. It's been a couple of years, but I believe you can put in other IP addresses into the destination address field and it will use them. I want to say all three packet types work: broadcast, multicast, and unicast, (please verify as my only Codesys controller is in moth balls). Anyway, I would suggest not using broadcast, which is either 255.255.255.255 or the local subnet broadcast. Most of the time, we try to limit broadcast traffic so would prefer not to actually use it to send data. Multicast is better (224.0.0.0/4 address), but still likely requires some management (plenty of posts on here where this is discussed using IGMP, and sometimes maybe GMRP).

Unicast is best, so if you only have one PC that needs the data, just put the IP address of the target PC and do it this way. If several devices need the data, try multicast. If that doesn't work for whatever reason, then broadcast can still work but I would isolate the network segment so it does not leak.

Also it can be tricky to get the network stack to send up data that arrived via broadcast. The Excel technique looks pretty neat in a previous post, but it may have some trouble with different types of traffic - as in unicast may work, multicast may require special handling, and broadcast may or may not work at all. Viewing in Wireshark is a great first step, but since this sits somewhat lower in the stack than our user applications actually listening on the UDP port, it's not a guarantee that just because we see it in Wireshark it will be available to a user application.

I am interested in how you solve this - please share once you have it working.
 
You are probably missing a reference to the mswinsock ocx in the spreadsheet.
The MSWINSCK.OCX must be present and registered in the system and thereafter referenced in the spreadsheet.
Look in the windows/system32 folder for the file MSWINSCK.OCX


I have sent you a message with the spreadsheet i used and also a tiny program that can be used to generate telegrams
 
Last edited:
Error "Only Valid in Object Module"

Hi chaps,

This is exactly what I have been trying to achieve, I have got the MSwinSCK.OCX attached in the references, but the 1st line of that code is red, objecting with a compile error "Only valid in Object Module".

I am attempting this with Excel 2010 VBA, and as Bratts' simple approach is so much what I want, I thought I'd just ask for help :)
 

Similar Topics

For an application I have the following setup: - S7 400 PLC with CP card - 1 PC with ethernet card sending data via UDP to the...
Replies
12
Views
6,452
Hello all, I am working on a project utilizing an s7-1200 cpu and Tia Portal v17. I currently have an external PCB with some sensors on it (and...
Replies
1
Views
730
Hi PLCTalk Family, I am currently using S71200 for UDP communication in one of our projects. Recently due to the chip shortage looking out to...
Replies
3
Views
1,285
Hi all, I was trying to communicate FX3GE PLC with KEPServer / Kepware via UDP protocol but did not succeed. Does anybody has any solution or...
Replies
2
Views
1,060
Hello, I am using a 1756-EN2T and tryin to communicate with a device that accepts ASCII string over ehternet usin UDP. Do packets sent using CIP...
Replies
8
Views
1,794
Back
Top Bottom