Adventurer3 Control – 6.9

Changed the method of searching the IP address of Adventurer3.

Previously, it used a private MAC address.
After fixing the MAC address, I couldn’t handle it by the above method, so I wanted to improve it.

There was a function called device search from the middle of Ver4, and when I analyzed the protocol about it, it seemed that it could be incorporated, so I corresponded.

How to search for a 3D printer

The window that is displayed when connecting to a device from the “Tools” menu in FlashPrint.

  • Ver4.6
  • Ver5.1

A screen like the one above appears so that you can search.

At this time, when I analyzed the network protocol, the following information was flowing.

First of all, the information sent from the PC.

It seemed to be broadcasting on UDP from port 18001 to port 19000 on 225.0.0.9.

After the above transmission, the following reply came from the device side.

As far as I can see the returned information, the information that seems to be the device name and device type (this is imaginable) was sent.

In other words, will it be possible to search for devices by supporting the above?

Implementation.

Fixed for the one on Github.

Searching for the IP address is done with SearchIP () in Adventurer3.cs, and you only need to change this part.
The actual change code is as follows.

/// <summary>
/// Class to search the IP of Adventurer3
/// Search by UDP broadcast
/// </summary>
public static List<IPAddress> SearchIP() {
	var ips = new List<IPAddress>();
	byte[] sendBytes = { 0xc0, 0xa8, 0x0b, 0x03, 0x46, 0x51, 0x00, 0x00 };

	// IP list retrieval
	// Search for IPv4 host address from the network adapter list
	// Broadcast from port 18001 of the found IP address to port 19000 of 225.0.0.9 and obtain the IP of the device from the returned value.
	var interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
	foreach (var adapter in interfaces) {
		if (adapter.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up) {
			var properties = adapter.GetIPProperties();

			foreach (var unicast in properties.UnicastAddresses) {
				switch (unicast.Address.AddressFamily) {
				case AddressFamily.InterNetwork:
					if (unicast.IsDnsEligible) {
						var ip = unicast.Address;
						var localPort = new IPEndPoint(ip, 18001);
						var udp = new UdpClient(localPort);
						var targetPort = new IPEndPoint(IPAddress.Parse("225.0.0.9"), 19000);
						udp.EnableBroadcast = true;
						udp.Send(sendBytes, sendBytes.Length, targetPort);
						udp.Client.ReceiveTimeout = 1000;   // ms:Timeout settings

						for (; ; ) {
							try {
								IPEndPoint e = new IPEndPoint(IPAddress.Any, 19000);
								var receiveBytes = udp.Receive(ref e);
								ips.Add(e.Address);
							}
							catch (SocketException) {
								// Timeout
								break;
							}
						}
						//UdpClientを閉じる
						udp.Close();
					}
					break;
				}
			}
		}
	}
	return ips;
}

First, find out the address to which the IPv4 IP connected to the PC is assigned.
This is the part below GetAllNetworkInterfaces ().
This is necessary because when there are multiple network adapters, the device search of the 3D printer cannot be performed for each adapter unless the IP is specified properly.

Next, establish a UDP session and send data to the specified IP and port.
For the transmitted data, the numerical values analyzed by the protocol analyzer are used as they are.

Finally, I received a reply from the device via UDP.
For reception, I set a timeout of 1000ms so that I will not wait any longer.

Now you can get the same IP list in terms of API return value.

コメント

Copied title and URL