public MasterEmulatorController() { masterEmulator = new MasterEmulator(); masterEmulator.DeviceDiscovered += onDeviceDiscovered; masterEmulator.Connected += onDeviceConnected; masterEmulator.Disconnected += onDeviceDisconnected; masterEmulator.DataReceived += onDataReceived; masterEmulator.LogMessage += onLogMessage; }
//PPP , PipeSetup pipe) public void CtrlEngine_Setup(Nordicsemi.MasterEmulator master) { masterEmulator = master; //PPP pipeSetup = pipe; pipeSetup = new PipeSetup_Ctrl(master); }
public bool scan_and_connect(String emulator_filter="") { System.Collections.ObjectModel.Collection<string> emulator_devices; //""" Function for doing discovery of the peer device, connect and //discover pipes. The function will also open the Master Emulator. """ try { this.master = new Nordicsemi.MasterEmulator(); this.master.LogMessage += this.log_message_handler; this.master.DataReceived += this.data_received_handler; this.master.Connected += this.connected_handler; this.master.Disconnected += this.disconnected_handler; this.master.PipeError += this.pipe_error_handler; this.master.ConnectionUpdateRequest += this.connection_update_handler; emulator_devices = this.master.EnumerateUsb(Nordicsemi.UsbDeviceType.AnyDevice); String emulator_device = this.filter_emulator_device(emulator_devices, emulator_filter); if( emulator_device == null ) { //raise Exception("Could not find emulator device"); throw new System.Exception("Could not find emulator device"); } this.master.SerialPortBaudRate = this.baud_rate; this.master.Open(emulator_device); //void Open(string usbSerialNumber); this.setup_service(); //# Start Master Emulator this.master.Run(); this.set_local_data(); if( this.own_address != "" ) { String byte_endianess_transformed_address = this.change_byte_endianess(this.own_address); BtDeviceAddress bt_device_address = new Nordicsemi.BtDeviceAddress(byte_endianess_transformed_address); this.master.SetBDAddress(bt_device_address); } this.restore_bond_info(); //# Run discovery procedure this.myPeerDevice = this._discover_peer_device(); logger.log("Found peer device"); //# Connect and bond to peer device Nordicsemi.BtConnectionParameters conn_params = new Nordicsemi.BtConnectionParameters(); conn_params.ConnectionIntervalMs = 15; if( this.master.Connect(this.myPeerDevice.DeviceAddress) ) { logger.log("--- Connected ---"); } else { //raise(Exception("Connection failed")); throw new System.Exception("Connection failed"); } if( this.service_setup_done == true ) { //# Service discovery bool found_pipes = this.master.DiscoverPipes(); //print "PIPES RETURN VALUE: %s" % found_pipes if( !found_pipes ) { return false; } logger.log("--- Pipes discovered ---"); } } catch( Exception ex) { logger.log(String.Format("[EXCEPTION] {0}", ex)); logger.log("Call stack:"); //tb = traceback.extract_tb(sys.exc_info()[2]) //for f in reversed(tb): //logger.log(String.Format(" File {0}, line {1}",os.path.basename(f[0]), f[1])); this.num_of_errors += 1; logger.log(String.Format("number of errors: {0}", this.num_of_errors)); return false; } return true; /* """ Function for doing discovery of the peer device, connect and discover pipes. The function will also open the Master Emulator. """ try: this.master = None this.master = Nordicsemi.MasterEmulator() this.master.LogMessage += this.log_message_handler this.master.DataReceived += this.data_received_handler this.master.Connected += this.connected_handler this.master.Disconnected += this.disconnected_handler this.master.PipeError += this.pipe_error_handler this.master.ConnectionUpdateRequest += this.connection_update_handler emulator_devices = this.master.EnumerateUsb(Nordicsemi.UsbDeviceType.AnyDevice) emulator_device = this.filter_emulator_device(emulator_devices, emulator_filter) if emulator_device is None: raise Exception("Could not find emulator device") this.master.SerialPortBaudRate = this.baud_rate this.master.Open(emulator_device) this.setup_service() # Start Master Emulator this.master.Run() this.set_local_data() if this.own_address: byte_endianess_transformed_address = this.change_byte_endianess(this.own_address) bt_device_address = Nordicsemi.BtDeviceAddress(byte_endianess_transformed_address) this.master.SetBDAddress(bt_device_address) this.restore_bond_info() # Run discovery procedure this.myPeerDevice = this._discover_peer_device() logger.log("Found peer device") # Connect and bond to peer device conn_params = Nordicsemi.BtConnectionParameters() conn_params.ConnectionIntervalMs = 15 if this.master.Connect(this.myPeerDevice.DeviceAddress): logger.log("--- Connected ---") else: raise(Exception("Connection failed")) if this.service_setup_done: # Service discovery found_pipes = this.master.DiscoverPipes() print "PIPES RETURN VALUE: %s" % found_pipes if not found_pipes: return false logger.log("--- Pipes discovered ---") except Exception, ex: logger.log("[EXCEPTION] %s" % ex) logger.log("Call stack:") tb = traceback.extract_tb(sys.exc_info()[2]) for f in reversed(tb): logger.log(" File {0}, line {1}".format(os.path.basename(f[0]), f[1])) this.num_of_errors += 1 logger.log("number of errors: %i" % this.num_of_errors) return false return true */ }
public void UpDnEngine_Setup(Nordicsemi.MasterEmulator master)//PPP , PipeSetup pipe) { masterEmulator = master; pipeSetup = new PipeSetup_UpDn(master); }