Hide Transcript
View Transcript
Using UDP messaging with the Do-more is easy. You just create a UDP device and then use
PACKETOUT and PACKETIN instructions to send and receive messages. That's it. For example, suppose we want to send a short
15 character ASCII message from a PC to the Do-more via UDP. Let's say the message looks like this. Each three character set would be a parameter
of some kind that the Do-more needs to respond to. The underscores aren't used, they were added
to make the data easier to see when we look at the message in the data view. To read that into the Do-more via UDP we just
create a UDP Port Device. Click on the Configure button, then click
on Device Configuration. Click on New Device and create a UDP Connection. Give it a name -- we'll call ours UDP_Demo
and let's listen on port 60001. The only port the DoMore uses is this 28784,
so you can use anything else from 1 to 65535, just make sure it is compatible with your
network. Be careful, most lower numbered UDP ports
have predefined uses, so I usually avoid lower numbered ports. When you write this project to the Do-more,
this device will listen to the Ethernet port and capture ANY message sent via UDP to the
port you put here. All you have to do is wait for the device
to say it has a new message, and then get it from the device. Since we just created a device, DoMore designer
automatically creates a structure for that device. Let's open a Dataview and take a look at it. Device structures begin with a dollar sign
and the name of our device was UDP_Demo. When I hit the DOT I see this device has 3
structure members available. One tells me packets have been captured and
are ready for me to use, one tells me how many packets are available and one tells me
a packet was sent. Let's use the PacketAvailable member as a
contact to tell us when the DoMore has received a UDP message to that sixty thousand and one
port. When this contact tells us that this device
has received a packet, we just a PACKETIN instruction to read the message from the UDP
Device. Here is the UDP device we created. When a packet is received, it has the senders
IP address and UDP port in the message. Those will get put in whatever variables we
put here. You can then use those in your ladder code
to filter out the messages -- maybe you need to respond to messages from one IP address
differently than messages from another IP address. Or maybe you need to respond differently to
messages from one port vs another port. Something like that. Here you can specify a timeout Now you may
ask, "What do I need a timeout for if I'm just reading data from a buffer -- especially
since the Packet Available structure member just told me it's ready to go?" We'll you really don't. For us, in this little example here, and probably
most of your projects too, it's not a big deal. Just take the default. However, if you are interested in how it might
be used, then checkout the Do-more help file. This is actually a really powerful feature
for large complex projects. Let's change the number of bytes to read to
64 so we can use a String Short right here as the place we want the message to end up. Keep in mind we could have created a special
string size just for this message -- the Do-more allows you to create ANY string size you want
- but we're gonna be lazy here and just use the built in string short. Well, that's it. Step 1: Create a device in configure and Step
2: use a PACKETIN to read the data when the device says it has a message for us. Easy. Let's add String Short 0, D0, and V0 to the
dataview so we can see what happens when a message is received. Accept Changes. Save the project and write it out to the DoMore. Now if I send my 15 byte message from the
PC to the DoMore, The UDP Device we created collects the message for us, it sets a flag
telling us a message is available and we read the message from the Device into SS0. We also see that D0 and V0 got populated with
the senders IP Address and UDP Port. Perfect. What if in addition to receiving messages
from the PC, you want to also SEND a message to the PC from the Do-more? Easy, just use a PACKETOUT instruction. It's needs the exact same information: the
device that is handling the messaging for you, the IP address and Port number you want
the message to go to, and the data you want to send. Done. What if you send a message from the PC and
the DoMore doesn't get it? What do you do now? I like to use a free open source program called
Wireshark. This guy shows you every packet being sent
across your network. That's usually a lot of data to sift through,
so you will want to add a filter. To filter on the Do-more's IP Address, I simply
type ip.addr double equals and the Do-more's IP address. Now I only see messages to or from the Do-more. I'll send a message from the PC and sure enough
I see that a message was sent from my PC's IP Address, to the Do-mores IP address, via
UDP using these ports. And down here you can even see that 15 characters
were sent and what they were in hex. So at a glance you can now tell that the message
actually left this IP Address, it went to this IP Address and which UDP Ports that were
used to send the message. Usually, if a message isn't received, the
destination IP address or the UDP port number don't match what the Do-more is expecting. You just need to make sure the DoMore project
matches these numbers. As a reminder, the Do-more's IP Address is
here under the Info Button. The UDP Port is here under the configure button. Please keep in mind that Wireshark is NOT
and Automation Direct product, so please don't call support asking for help with that. There are lots of excellent video tutorials
on YouTube and the Wireshark website at www.Wireshark.org. Of course, if you have any questions about
Automation Direct's products, don't hesitate to contact Automation Directs Award Winning,
Free, Technical support during regular business hours. Spend Less .. Do More. With Automation Direct.