// private helper for magic property private void setprop_logicalName(string newval) { if (!(YAPI.CheckLogicalName(newval))) { throw new YoctoApiProxyException("Invalid logical name"); } if (_func == null) { return; } if (!(_online)) { return; } if (newval == _LogicalName_INVALID) { return; } if (newval == _logicalName) { return; } _func.set_logicalName(newval); _logicalName = newval; }
public override async Task <int> Run() { try { YModule m; await YAPI.RegisterHub(HubURL); m = YModule.FindModule(Target); // use serial or logical name if (await m.isOnline()) { if (!YAPI.CheckLogicalName(LogicalName)) { WriteLine("Invalid name (" + LogicalName + ")"); return(-1); } await m.set_logicalName(LogicalName); await m.saveToFlash(); // do not forget this Write("Module: serial= " + await m.get_serialNumber()); WriteLine(" / name= " + await m.get_logicalName()); } else { Write("not connected (check identification and USB cable"); } } catch (YAPI_Exception ex) { WriteLine("RegisterHub error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
private void btnSave_Click(object sender, EventArgs e) { if (Selected == null) { return; } if (string.IsNullOrEmpty(txtName.Text)) { throw new UserException("[Yocto_EmptyName]"); } // All and numbers have a special meaning when identifying a relay in a script command if (txtName.Text.Equals(CmdYocto.ALLID, StringComparison.InvariantCultureIgnoreCase) || int.TryParse(txtName.Text, out _)) { throw new UserException("[Yocto_BadName]"); } if (!YAPI.CheckLogicalName(txtName.Text)) { throw new UserException("[Yocto_BadName]"); } try { Selected.set_logicalName(txtName.Text); Selected.module().saveToFlash(); btnSave.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { YModule m; string errmsg = ""; string newname; if (args.Length != 2) { usage(); } if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } m = YModule.FindModule(args[0]); // use serial or logical name if (m.isOnline()) { newname = args[1]; if (!YAPI.CheckLogicalName(newname)) { Console.WriteLine("Invalid name (" + newname + ")"); Environment.Exit(0); } m.set_logicalName(newname); m.saveToFlash(); // do not forget this Console.Write("Module: serial= " + m.get_serialNumber()); Console.WriteLine(" / name= " + m.get_logicalName()); } else { Console.Write("not connected (check identification and USB cable"); } YAPI.FreeAPI(); }