pub fn enumerate_devices_with_host_and_port(
        serialosc_addr: IpAddr,
        serialosc_port: u16,
    ) -> Result<Vec<MonomeDevice>, String> {
        let socket = new_bound_socket();
        let mut devices = Vec::<MonomeDevice>::new();
        let server_port = socket.local_addr().unwrap().port();
        let server_ip = socket.local_addr().unwrap().ip().to_string();

        let packet = build_osc_message(
            "/serialosc/list",
            vec![
                OscType::String(server_ip),
                OscType::Int(i32::from(server_port)),
            ],
        );

        let bytes: Vec<u8> = encode(&packet).unwrap();

        let addr = SocketAddr::new(serialosc_addr, serialosc_port);
        let (mut socket, _) = socket.send_dgram(bytes, &addr).wait().unwrap();
        // loop until we find the device list message. It can be that some other messages are
        // received in the meantime, for example, tilt messages, or keypresses. Ignore them
        // here. If no message have been received for 500ms, consider we have all the messages and
        // carry on.
        loop {
            let fut = socket.recv_dgram(vec![0u8; 1024]).select2(Delay::new(
                Instant::now() + Duration::from_millis(DEVICE_ENUMERATION_TIMEOUT_MS),
            ));
            let task = tokio::runtime::current_thread::block_on_all(fut);
            socket = match task {
                Ok(Either::A(((s, data, _, _), _))) => {
                    socket = s;
                    let packet = decode(&data).unwrap();

                    match packet {
                        OscPacket::Message(message) => {
                            if message.addr == "/serialosc/device" {
                                let args = message.args;
                                if let [OscType::String(ref name), OscType::String(ref device_type), OscType::Int(port)] =
                                    args.as_slice()
                                {
                                    devices.push(MonomeDevice::new(
                                        name,
                                        device_type,
                                        serialosc_addr,
                                        (*port) as u16,
                                    ));
                                }
                            }
                        }
                        OscPacket::Bundle(_bundle) => {
                            eprintln!("Unexpected bundle received during setup");
                        }
                    };

                    socket
                }
                Ok(Either::B(_)) => {
                    // timeout
                    break;
                }
                Err(e) => {
                    panic!("{:?}", e);
                }
            };
        }

        Ok(devices)
    }
/// Enumerate all monome devices on a non-standard serialosc port, on a specific host.
///
/// If successful, this returns a list of MonomeDevice, which contain basic informations about
/// the device: type, serial number, port allocated by serialosc.
///
/// # Arguments
///
/// * `serialosc_addr: the address of the host on which serialosc runs
/// * `serialosc_port`: the port on which serialosc is running
///
/// # Example
///
/// Enumerate and display all monome device on port 1234:
///
/// ```no_run
/// # use monome::Monome;
/// let enumeration = Monome::enumerate_devices_with_host_and_port("192.168.1.12".parse().unwrap(), 1234);
/// match enumeration {
///     Ok(devices) => {
///         for device in &devices {
///            println!("{}", device);
///         }
///     }
///     Err(e) => {
///         eprintln!("Error: {}", e);
///     }
/// }
/// ```
Enumerate all monome devices on a non-standard serialosc port, on a specific host.
If successful, this returns a list of MonomeDevice, which contain basic informations about
the device: type, serial number, port allocated by serialosc.
Enumerate all monome devices on a non - standard serialosc port on a specific host . If successful this returns a list of MonomeDevice which contain basic informations about the device : type serial number port allocated by serialosc .
pub fn enumerate_devices_with_host_and_port(
        serialosc_addr: IpAddr,
        serialosc_port: u16,
    ) -> Result<Vec<MonomeDevice>, String> {
        let socket = new_bound_socket();
        let mut devices = Vec::<MonomeDevice>::new();
        let server_port = socket.local_addr().unwrap().port();
        let server_ip = socket.local_addr().unwrap().ip().to_string();
        let packet = build_osc_message(
            "/serialosc/list",
            vec![
                OscType::String(server_ip),
                OscType::Int(i32::from(server_port)),
            ],
        );
        let bytes: Vec<u8> = encode(&packet).unwrap();
        let addr = SocketAddr::new(serialosc_addr, serialosc_port);
        let (mut socket, _) = socket.send_dgram(bytes, &addr).wait().unwrap();
        // loop until we find the device list message. It can be that some other messages are
        // received in the meantime, for example, tilt messages, or keypresses. Ignore them
        // here. If no message have been received for 500ms, consider we have all the messages and
        // carry on.
        loop {
            let fut = socket.recv_dgram(vec![0u8; 1024]).select2(Delay::new(
                Instant::now() + Duration::from_millis(DEVICE_ENUMERATION_TIMEOUT_MS),
            ));
            let task = tokio::runtime::current_thread::block_on_all(fut);
            socket = match task {
                Ok(Either::A(((s, data, _, _), _))) => {
                    socket = s;
                    let packet = decode(&data).unwrap();
                    match packet {
                        OscPacket::Message(message) => {
                            if message.addr == "/serialosc/device" {
                                let args = message.args;
                                if let [OscType::String(ref name), OscType::String(ref device_type), OscType::Int(port)] =
                                    args.as_slice()
                                {
                                    devices.push(MonomeDevice::new(
                                        name,
                                        device_type,
                                        serialosc_addr,
                                        (*port) as u16,
                                    ));
                                }
                            }
                        }
                        OscPacket::Bundle(_bundle) => {
                            eprintln!("Unexpected bundle received during setup");
                        }
                    };
                    socket
                }
                Ok(Either::B(_)) => {
                    // timeout
                    break;
                }
                Err(e) => {
                    panic!("{:?}", e);
                }
            };
        }
        Ok(devices)
    }
pub fn enumerate_devices_with_host_and_port ( serialosc_addr : IpAddr , serialosc_port : u16 , ) -> Result < Vec < MonomeDevice > , String > { let socket = new_bound_socket ( ) ; let mut devices = Vec :: < MonomeDevice > :: new ( ) ; let server_port = socket . local_addr ( ) . unwrap ( ) . port ( ) ; let server_ip = socket . local_addr ( ) . unwrap ( ) . ip ( ) . to_string ( ) ; let packet = build_osc_message ( " " , vec ! [ OscType String ( server_ip ) OscType Int ( i32 from ( server_port ) ) ] , ) ; let bytes : Vec < u8 > = encode ( & packet ) . unwrap ( ) ; let addr = SocketAddr :: new ( serialosc_addr , serialosc_port ) ; let ( mut socket , _ ) = socket . send_dgram ( bytes , & addr ) . wait ( ) . unwrap ( ) ; // loop until we find the device list message. It can be that some other messages are // received in the meantime, for example, tilt messages, or keypresses. Ignore them // here. If no message have been received for 500ms, consider we have all the messages and // carry on. loop { let fut = socket . recv_dgram ( vec ! [ 0u8 1024 ] ) . select2 ( Delay :: new ( Instant :: now ( ) + Duration :: from_millis ( DEVICE_ENUMERATION_TIMEOUT_MS ) , ) ) ; let task = tokio :: runtime :: current_thread :: block_on_all ( fut ) ; socket = match task { Ok ( Either :: A ( ( ( s , data , _ , _ ) , _ ) ) ) => { socket = s ; let packet = decode ( & data ) . unwrap ( ) ; match packet { OscPacket :: Message ( message ) => { if message . addr == " " { let args = message . args ; if let [ OscType :: String ( ref name ) , OscType :: String ( ref device_type ) , OscType :: Int ( port ) ] = args . as_slice ( ) { devices . push ( MonomeDevice :: new ( name , device_type , serialosc_addr , ( * port ) as u16 , ) ) ; } } } OscPacket :: Bundle ( _bundle ) => { eprintln ! ( " " ) ; } } ; socket } Ok ( Either :: B ( _ ) ) => { // timeout break ; } Err ( e ) => { panic ! ( " " e ) ; } } ; } Ok ( devices ) }
Enumerate all monome devices on a non-standard serialosc port, on a specific host.
Enumerate all monome devices on a non - standard serialosc port on a specific host .
serialosc_addr
IpAddr
serialosc_port
u16
serialosc_addr
IpAddr
serialosc_port
u16
example
Enumerate and display all monome device on port 1234.


Enumerate and display all monome device on port 1234 .
use monome::monome;
None