Jump to content

UDP communication between USC-B5-T24 & C++ program (.exe console)


Recommended Posts

Hello guys&girls,

 

I'm new to Unitronics PLC programming and I'm facing some problems. I'm working with a USC-B5-T24 which needs to receive through UDP protocol some datas from a C++ program.

I hadn't find in the unitronics examples programs doing this. Can someone give me the guidelines to set my PLC to receive datas from my C++ program ?

 

Thanks in advance !

Link to comment
Share on other sites

  • MVP 2023

You are correct - there is very little in UniStream documentation regarding UDP.  It's not common in our world.  I'm guessing you have a reason for choosing this.  I could not find a UniStream example either and UDP Tx and Rx are mentioned in the Help but not further documented.

You'll be rolling your own protocol here in your C++ program.  UDP is just the carrier.  I've used it in the Unitronics Vision series on local networks as it is very fast.  Unfortunately with no handshaking, you don't know that the message was received.

First you set up a UDP socket and assign a port under the PLC Communications tree-

image.png.877df70ec1ba1578f6e18432df70d335.png

 

The UDP function blocks are very logically located (not!) in the COM: CPU TCP/IP group:

image.png.1b01e7ce4d5501543460bb80888a61d1.png

 

After that it's pretty simple.  You just drop a UDP Rx block and wait for your blob of data to land in the Buffer array you define.  What you do with it from there is up to you.

If you create a program an upload it we can have a look.  You can also contact Official Unitronics Support at support@unitronics.com.

 

You may want to consider including a Modbus TCP library in your C++ code and go that route instead.  What sort of "datas" are you transferring?  

There is quite of bit of Modbus experience on the forum.

 

Joe T.

Link to comment
Share on other sites

Hi guys&girls,

 

Thanks to Joe's advices, I achieve to make my PLC and my C++ code exchanging data's through UDP protocol.

So I've written my C++ program on VScode through an Ubuntu20.03 VMWare. For those who wanna do it, follow Joe's advices to set your UDP socket on PLC. After this, I write my C++ code that open a socket  and can send and receive data (I've follow this tutorial on UDP C++ programming : https://bousk.developpez.com/cours/reseau-c++/UDP/01-introduction-premiers-pas/).

On VMWare, I've set my network adaptater on "Bridged" with the option "Replicate physical network connection state" (users on forums say this option should be activate for those who work on a laptop like me) and in Ubuntu I've set my ethernet connection manual in the network settings>>IPV4>>manual>>xxx.xxx.xxx.xxx. When I execute my code, I've just to write my local port, the IP of the UDP on PLC and the port defined in and it works !

 

Best regards !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.