After 2 hours of headache, i checked with the Ethernet_CCM program provided with the library... it seems that the following will NEVER have a RC different than 0... (i tried getting an error with the original EtherCCM by pinging a specific not connected address, but it seems that the program always thinks the PLC is connected)
Rc = PASCAL_HEIOpenDevice(TP, aDevices(tDevice), HEIAPIVersion, DefDevTimeout, DefDevRetrys, False)
If Rc <> 0 Then
DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "] " + "Error " + Hex(Rc) + " trying to open the device..."
DisplayText.Text = DisplayText.Text & vbCrLf & ""
Reading_PLC_Error = 1
DisplayText.Refresh
DisplayText.SelStart = Len(DisplayText.Text)
Else
DeviceOpen = True
Anyways, i found out that all the others RC could return something else than 0... so i used :
Rc = PASCAL_HEIReadSetupData(aDevices(tDevice), DT_NODE_NUMBER, tBuffer(0), RSize)
and this one returns me an error.
To make sure, i kept the first part anyways ( i needed the OpenDevice = true anyways...) So my program looks like this:
aDevices(tDevice).Address(0) = 2 ' Family= AF_INET
aDevices(tDevice).Address(1) = 0
aDevices(tDevice).Address(2) = &H70 ' ECOMs use Port number 7070(Hex)
aDevices(tDevice).Address(3) = &H70
aDevices(tDevice).Address(4) = 192 ' IP Address of the ECOM is 192.168.15.B
aDevices(tDevice).Address(5) = 168
aDevices(tDevice).Address(6) = 15
aDevices(tDevice).Address(7) = B
' Open the device
DisplayText.Text = DisplayText.Text & vbCrLf & "------------------------------------------------------------------------------------------------"
DisplayText.Text = DisplayText.Text & vbCrLf & ""
DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "] " + "Connecting to device ECOMBOX0" + CStr(B) + " . IP : 192.168.10." + CStr(B)
DisplayText.Text = DisplayText.Text & vbCrLf & ""
DisplayText.Refresh
DisplayText.SelStart = Len(DisplayText.Text)
Rc = PASCAL_HEIOpenDevice(TP, aDevices(tDevice), HEIAPIVersion, DefDevTimeout, DefDevRetrys, False)
If Rc <> 0 Then
DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "] " + "Error " + Hex(Rc) + " trying to open the device..."
DisplayText.Text = DisplayText.Text & vbCrLf & ""
Reading_PLC_Error = 1
DisplayText.Refresh
DisplayText.SelStart = Len(DisplayText.Text)
Else
DeviceOpen = True
Dim tBuffer(255) As Byte
Dim RSize As Integer
Dim tstring As String
Erase tBuffer
RSize = 4
Rc = PASCAL_HEIReadSetupData(aDevices(tDevice), DT_NODE_NUMBER, tBuffer(0), RSize)
If Rc <> 0 Then
DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "] " + "ERROR : Connection to the PLC was lost..."
DisplayText.Text = DisplayText.Text & vbCrLf & ""
Reading_PLC_Error = 1
DeviceOpen = False
Else
PROGRAM[...]
Feel free to comment / suggest anything else
Have a nice day