Hi all, I’m trying to create a local simulation of several B&R PLCs connected over a network. This copies a device we have running in the field, but which I cannot access for the time being.
I’ve drawn up a schematic of the network I’m trying to simulate, see below. I’ve managed to get the simulation working of the communication over the switch, in the 192.168.1.x network, using the guide at B&R Online Help. This is all working fine, the PPC and PLCs can communicate over OpcUa and ANSL just fine.
Regarding the 10.11.x.x network, a custom UDP protocol is used here, over UDP ports 2200-2210, using the library AsUDP. I’ve tried changing the program so it also uses the 192.168.1.x network, since the use of these specific ports doesn’t interfere with anything else for as far as I know. UdpOpen gives no error, UdpIoCtl gives error 9999 when attemting to bind to the interface, after which UdpClose gives error 35000. I’m in AS4.12.6.106 using AR B4.92.
Now I guess my question is: is it possible to assign multiple IP addresses to ARSim, so I can also simulate the 10.11.x.x network? Or else, how would you simulate something like this?
Your simulated network setup is not totally clear. Which devices are ArSim and which devices are not.
You could try IP address 0.0.0.0 for ArSim; see following post.
ARsim - reachable from network with dynamic IP address - Share Info & Ideas - B&R Community
All the devices in the diagram are simulated: the PPC and X20 PLCs (including IF1082-2) are each running in a separate ARSim, making three simultaneous ARSim instances. The customer device is simulated with a local UDP sender/receiver program.
Changing the simulation IP address to 0.0.0.0 to bind to all interfaces does not fix my problem. Any UDP traffic i send to 10.11.1.1 is now sent to the X20 interface, and not the IF1082-2 interface where I am listening for it.
To reiterate: I’m looking to send UDP traffic to the (simulated) IF1082-2 Powerlink interface, on a different network address than that of the ARSim instance.
Hi @Tom_Veldman
As far as I know and based on this help page : B&R Online Help
ARSim didn’t simulate the additionnal interface and X20IF1082-2 is a powerlink interface so i’m pretty sure that ARSim didn’t simulate this.
As I understand you use the IF1082-2 as a ethernet interface and you use it to communicate via UDP. So if you are in simulation you need to replace ip address in your UDP Open from “10.11.1.1” to “192.168.1.2” and for the customer program don’t send to “10.11.1.1” but to “192.168.1.2” for the left part of your diagram.
For information the error 9999 is ERR_NOTIMPLEMENTED so you try to do something that is not implemented in ARSim. (B&R Online Help)
What is your usage of UdpIoCtl ?
Hope this help and don’t hesitate to correct me if I didn’t correctly understand your question.
Regards,
Florent
Automation Studio does not allow me to set both the CP3586 and the IF1082-2 IP address to 192.168.1.2, which makes sense to me.
Attempting to bypass the IF1082-2 interface and using IF2 of the CP3586 (that’s IP 192.168.1.2) in my program results in the same issue as before: a 9999 error. Perhaps someone can tell me what function exactly is not being implemented here?
I’m opening a UDP port for sending using UdpOpen()
, port 0, option udpOPT_REUSEADDR
. Then I attempt to bind this port to interface IF2 using UdpIoCtl()
, ident FbUdpOpen.ident
, ioctl udpSO_BINDTODEVICE
, pData ADR('IF2')
, datalen LEN(DeviceName)
. Calling the UdpIoCtl FB returns the 9999 error.
I’m not sure about the usage of UdpIoCtl() function block in your case. As UdpOpen() should automaticly detect which is the interface to bind (see comment in the pIfAddr input B&R Online Help).
Could you try to skip the UdpIoCtl function block ? Just do Open then Send/Recv
The function not implemented is the idpSO_BINDTODEVICE : B&R Online Help
That’s some crucial information that I missed. Thank you very much, this did the trick.
Perhaps unrelated, but is there some way I can detect whether I’m running in ARsim or on actual hardware? Then I can program it to skip the binding step when in simulation.
Perhaps unrelated, but is there some way I can detect whether I’m running in ARsim or on actual hardware? Then I can program it to skip the binding step when in simulation.
DiagCpuIsSimulated() or DiagCpuIsARsim ()
or
1 Like
Glad it resolved your problem.
To be honest I’m not sure you need to bind on real hardware too. UdpOpen should do it for you depending on the IP Address you set in parameter.
But as @job.franken answer you can use Diags function.
Here an little snippet to but in your program init.
IF DiagCpuIsSimulated() THEN
localIpAddress := '192.168.1.2';
ELSE
localIpAddress := '10.11.1.1';
END_IF;
Amazing, thank you very much. This thread can be closed.
You can mark a post to Solution it mark the thread as resolved 