Jump to content

How to 'broadcast' to ethernet network

Recommended Posts

I would be very grateful if someone could point me in the right direction to 'broadcast' a string thru an Ethernet connection.. I've attached a sample program that I've started if someone might have a couple minutes to take a quick look and perhaps directly add a couple net lines that would be required or maybe direct me to a similar example somewhere that would explain specific details.


Background... we have a Unitronics V1040 plc controlling a small machine we're providing and the customer has an existing software program (specifics of which is unknown to us) that apparently picks broadcasted data from various machines connected to there Ethernet network.  They have asked us to broadcast a couple of the variables from our plc to the network in the following format: <STX>(11<HT>1<HT>[VARIABLE1]<HT>2<HT>LB<HT>4<HT>1<HT>83<HT>[VARIABLE2]<HT>57<HT>[VARIABLE3]<ETX>, where the three variables are memory locations in the plc (2x MI & 1x ML locations).


Several questions hoping someone can confirm or provide better direction on where to start:

1) I believe this needs to be done with UDP since a "broadcast" (to ip address ?) is desired instead of direct communication with a specific pc/plc&port#.  Does this sound correct?

2) How would one assemble a single text string which combines the various string constants with program variables?  I'm quite inexperienced but from trying to research this before asking for help here, I think this is basically a tab delimited text string? Does that look to be the case?


What I've done so far:

1) SB2 power up bit... have a PLC NAME set, have a TCP/IP CARD INIT with valid IP's set, and have a TCP/IP SOCKET INIT set for (Socket 2, UDP-RAW, Port 20257).

2) We would also like to be able to remote into the plc from what best I can tell would be thru Socket1 which is already setup for this by default and doesn't need to have a SOCKET INIT included in the code.? Is this correct? or would it be better practice to go ahead and place it also in the code?

3) Even if above steps is close..  that is where I'm at as I can not figure out how to get the string assembled.  Looking at available command options, I'm thinking I need a vector of MI locations that could then be used with a UDP_RAW SEND FB.?


Anyways... thanks in advance to anyone who can take a couple minutes to look at this and help me out with some of the details or a specific example showing something similar.


text test.vlp

Link to comment
Share on other sites

  1. You are right about UDP RAW
  2. Encoding is easy, try to use 'Create Excel delimited line" under SD menu (see attachment)
  3. Socket 2 init is correct, Socket 1 init is not necessary, but I would add it as well for cases when backup battery is fails.

I did not test my suggestion, so if any questions, please reply

Good luck





Link to comment
Share on other sites

Wow... Thanks for taking the time and offering such a quick response.

I just learned another function that I can see useful for a couple other things...


But as one question often leads to another...


As I'm looking thru the example you provided and seeing various delimiter options when entering the function, I'm now thinking some of what I was thinking would be static text , might should be actually control characters instead of static text.  Such as

<STX> = control character "Start of Text"

<HT>   = control character "Horizontal Tab"

<ETX> = control character "End of Text"


So I'm thinking the first line to be a blank space with the <STX> delimiter

followed by the second line of static text with the <HT> delimiter

Followed by the third line of the variable data with the <HT> delimiter


until the last variable with the <ETX> delimiter


Does this make sense or any further thoughts or experience on this?


Unfortunately I not sure how I could test this in house (to were I can actually see the data put out on the network?) and want to be as knowledgeable as I can be before trying to get this to work at a customers site.. if you know what I mean.


Thanks again for you help..



Link to comment
Share on other sites

I was assuming that the output message is all ASCII.

If your string is ASCII with control characters in <>, and ASCII variables in [ ], then yes - you are right and your line should work.

The only concern is a blank space before <STX>. But you can remove it with vector "Shift Left" under vector menu:





For test you have 2 options:


1.  PLC info mode:

Go to Info Mode->Ethernet->Monitor. Select "Port 2" and you will see every incoming and outgoing packet in ASCII or binary.(In this case you will need to trigger transmission from visilogic debug mode since the display will be used as monitor)


2. "Wireshark" on your PC.

install your version and run the program

set the filter as "udp.port == 20257"

select network interface and click "Start"


You will see all packet broadcasting by PLC to port 20257
Link to comment
Share on other sites

Thank you very much for the lesson and additional info.

I'm not sure exactly what the expected message is either at this time, but when I saw the delimiter options it just made me think..

However, hopefully we'll be armed with the knowledge either way it needs to be.





I've gone thru countless forum posts here and the older forums and along with the program supplied examples during the past while learning what little it seams I still know about Unitronics plc specifics.  And while much of the system documentation seems lacking (at least to a beginner).. I can not express how much the efforts of all you members and moderators are (not just Linxchas for the above help), who CHOOSE to help others in this format...

A HUGE THANKS to all.  Hopefully one day, I'll be able to return the favor to someone else.

Link to comment
Share on other sites

One final comment on what I learned implementing the above...


Apparently when vector shifting, there must be an address immediately before the start vector which will allow the shifted bit a place to go. In the above example shown, the start vector was XI0.  When executing the program.. the attempted bit shift did nothing.


After it not working (and I not fully knowing what the XI registers are used for), I moved the vector start to an MI location and it suddenly started working as expected.  However while abserving the data while running, I happened to notice the address immediately before the start register was changing as the bit shift would occur.  So it occured there needed to be an empty address before the start vector.. I then moved the start vector to XI1 address sure enough it works and observed XI0 was changing as XI1 bit shifted.


Anyway, important to know for future use.  As I sometimes bunch addresses used all together.  just need to make sure an unused address is before the start vector that is to be bit shifted.  Otherwise that address would unknowingly be changing data due to the shift after it.


Seems to me it would be better for the shifted bit out to just disappear in space rather than affect an address above it, but I'm sure there's a reason for it.  Anyways good to know and another lesson learned.


Also with the wireshark program mentioned above.. I was able to see the actual output data being broadcast on the network and after doing a hex to ascii conversion could see without a doubt what exactly was being sent.  Very useful.


Anyway the program works perfect and I even understand what it's doing now.


Thx again. !!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...