The function is used to search for the access control panel in the LAN.
[in]: If the communication type is set to UDP (or Ethernet), all devices of the specified communication type will be searched.
[in]: Broadcast address; the system searches for the devices in the LAN within the specified IP address range;
the default value is 255.255.255.255, known as network broadcasting.
[in]: The buffer is used to save the detected devices. Users should determine the requested memory according
to the number of devices in the corresponding network. For example, if the network has not more than 50 devices,
it is recommended that users should request the memory of 32K; if the network has not more than 100 devices,
it is recommended that users should request the memory of 64K.
[in]: The default value is null; it is used for extension.
When the returned value is 0 or a positive value, it indicates that the operation is successful
(the returned value indicates the number of records). When the returned value is a negative value,
it indicates that the operation fails. Attached table 5 lists the information about the error codes.
This approach is intended to search for access controllers on a LAN in UDP broadcast mode. UDP packets cannot traverse routers,
so an access controller must not be separated from a server by routers. If by this means you find a device that resides on a different
network segment as a server but fail to ping the IP address of an access controller, you may set the controller and server addresses
to be on the same subnet (not necessarily on the same network segment). For details on network setting, consult related administrator
to obtain correct IP addresses, subnet masks and gateways.
None
[DllImport("plcommpro.dll", EntryPoint = "SearchDevice")] //public static extern int SearchDevice( ref byte commtype, ref byte address, ref byte buffer); public static extern int SearchDevice(string commtype, string address, ref byte buffer); private void SearchDevice_Pull() { Connect_Pull(); int ret = 0, j = 0; byte[] buffer = new byte[64 * 1024]; string str = ""; string[] tmp = null; string udp = "UDP"; string adr = "10.0.0.44"; MessageBox.Show("Start to SearchDevice!"); ret = SearchDevice(udp, adr, ref buffer[0]); MessageBox.Show("ret searchdevice=" + ret); if (ret >= 0) { str = Encoding.Default.GetString(buffer); str = str.Replace("\r\n", "\t"); tmp = str.Split('\t'); while (j < tmp.Length - 1) { string[] sub_str = tmp[j].Split(','); MessageBox.Show(tmp[0]); } } else { MessageBox.Show("SearchDevice operation is failed!"); return; } Disconnect_pull(); }
'public static extern int SearchDevice( ref byte commtype, ref byte address, ref byte buffer); <DllImport("plcommpro.dll", EntryPoint:="SearchDevice")> Public Shared Function SearchDevice(commtype As String, address As String, ByRef buffer As Byte) As Integer End Function Private Sub SearchDevice_Pull() Connect_Pull() Dim ret As Integer = 0, j As Integer = 0 Dim buffer As Byte() = New Byte(64 * 1024 - 1) {} Dim str As String = "" Dim tmp As String() = Nothing Dim udp As String = "UDP" Dim adr As String = "10.0.0.44" MessageBox.Show("Start to SearchDevice!") ret = SearchDevice(udp, adr, buffer(0)) MessageBox.Show("ret searchdevice=" + ret) If ret >= 0 Then str = Encoding.[Default].GetString(buffer) str = str.Replace(vbCr & vbLf, vbTab) tmp = str.Split(ControlChars.Tab) While j < tmp.Length - 1 Dim sub_str As String() = tmp(j).Split(","c) MessageBox.Show(tmp(0)) End While Else MessageBox.Show("SearchDevice operation is failed!") Return End If Disconnect_pull() End Sub