private bool Read_All_Config_File() { try { if (!WaveForm.readFromFile()) { return(false); } if (!Attenuator.readFromFile()) { return(false); } if (!LimitTx.readFromFile()) { return(false); } if (!LimitRx.readFromFile()) { return(false); } if (!BIN.readFromFile()) { return(false); } return(true); } catch { return(false); } }
private void editOrCloneAtt(Attenuator att, bool isClone) { FormAddAtt formAdd; formAdd = new FormAddAtt(att); formAdd.ShowDialog(); if (formAdd.isInputOk && formAdd.DialogResult.Equals(DialogResult.OK)) { isSaved = false; if (!isClone) { att.releasePort(); attList.Remove(att); } if (!verifyNewAtt(formAdd.attenuator)) { editOrCloneAtt(formAdd.attenuator, isClone); return; } if (formAdd.attenuator.Init()) { attList.Add(formAdd.attenuator); } else if (!isClone) { att.Init(); attList.Add(att); } updateAttList(); } }
//Attenuator private void setAttenuatorValue(int deviceId, double attenuatorValue) { Attenuator.fnLDA_SetTestMode(false); Attenuator.fnLDA_InitDevice(deviceId); double value = attenuatorValue / 0.25; Attenuator.fnLDA_SetAttenuation(deviceId, (int)value); //MessageBox.Show(Attenuator.fnLDA_GetAttenuation(deviceId).ToString()); Attenuator.fnLDA_CloseDevice(deviceId); }
public FormAddAtt(Attenuator att) { InitializeComponent(); buttonAdd.Text = "Apply"; panelHttp.Visible = false; panelUsb.Visible = false; panelSerial.Visible = false; textBoxDescription.Text = att.description; comboBoxAttType.Text = att.GetType().Name.Equals("Rudat") ? "RUDAT" : "RCDAT"; comboBoxConType.Text = att.conType.ToString().ToUpper(); switch (att.conType) { case ConnectionTypes.Http: case ConnectionTypes.Telnet: panelHttp.Visible = true; textBoxHttpIp.Text = att.ipAddress; textBoxHttpPort.Text = att.port; break; case ConnectionTypes.Serial: foreach (string id in SerialPort.GetPortNames()) { comboBoxComPort.Items.Add(id); } comboBoxComPort.Text = att.comPortName; textBoxBaudRate.Text = att.baudRate.ToString(); comboBoxParity.Text = att.parity.ToString(); comboBoxDataBits.Text = att.dataBits.ToString(); comboBoxStopBits.Text = att.stopBits.ToString(); panelSerial.Visible = true; break; case ConnectionTypes.Usb: panelUsb.Visible = true; foreach (string id in UsbConnection.GetAvailableSNList()) { comboBoxDeviceId.Items.Add(id); } comboBoxDeviceId.Text = att.serialNumber; break; default: break; } }
private bool verifyNewAtt(Attenuator newAtt) { foreach (Attenuator att in AttenuatorList.attList) { if (att.description == newAtt.description) { MessageBox.Show("Couldn't add attenuator,\nAttenuator with the same description already exist.", "Wrong Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } switch (newAtt.conType) { case Enums.ConnectionTypes.Http: case Enums.ConnectionTypes.Telnet: if (att.ipAddress == newAtt.ipAddress && att.port == newAtt.port) { MessageBox.Show("Couldn't add attenuator,\nAttenuator with the same ipaddress & port already exist.", "Wrong Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } break; case Enums.ConnectionTypes.Serial: if (att.comPortName == newAtt.comPortName) { MessageBox.Show("Couldn't add attenuator,\nAttenuator with the same COM port already exist.", "Wrong Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } break; case Enums.ConnectionTypes.Usb: if (att.serialNumber == newAtt.serialNumber) { MessageBox.Show("Couldn't add attenuator,\nAttenuator with the same serial number already exist.", "Wrong Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } break; } } return(true); }
private void detectAttenuator() { attenuator1 = 0; label3.Text = "Attenuator(NA)"; label4.Text = "Attenuator(NA)"; label5.Text = "Attenuator(NA)"; label6.Text = "Attenuator(NA)"; Attenuator.fnLDA_SetTestMode(false); int device = Attenuator.fnLDA_GetNumDevices(); for (int i = 0; i < device; i++) { Attenuator.fnLDA_InitDevice(i + 1); int serialNumber = Attenuator.fnLDA_GetSerialNumber(i + 1); switch (i) { case 0: attenuator1 = i + 1; label3.Text = "Attenuator (" + attenuator1 + ")"; break; case 1: attenuator1 = i + 1; label4.Text = "Attenuator (" + attenuator1 + ")"; break; case 2: attenuator1 = i + 1; label5.Text = "Attenuator (" + attenuator1 + ")"; break; case 3: attenuator1 = i + 1; label6.Text = "Attenuator (" + attenuator1 + ")"; break; } Attenuator.fnLDA_CloseDevice(i + 1); } }
private void ProduceOneProp() { Random r = new Random((int)Environment.TickCount64); XYPosition newPropPos = new XYPosition(); while (true) { newPropPos.x = r.Next(0, gameMap.Rows * Map.Constant.numOfGridPerCell); newPropPos.y = r.Next(0, gameMap.Cols * Map.Constant.numOfGridPerCell); int cellX = Map.Constant.GridToCellX(newPropPos), cellY = Map.Constant.GridToCellY(newPropPos); bool canLayProp = true; gameMap.ObjListLock.EnterReadLock(); try { foreach (GameObject obj in gameMap.ObjList) { if (cellX == Map.Constant.GridToCellX(obj.Position) && cellY == Map.Constant.GridToCellY(obj.Position) && (obj is Wall || obj is BirthPoint)) { canLayProp = false; break; } } } finally { gameMap.ObjListLock.ExitReadLock(); } if (canLayProp) { newPropPos = Map.Constant.CellToGrid(cellX, cellY); break; } } PropType propType = (PropType)r.Next(Prop.MinPropTypeNum, Prop.MaxPropTypeNum + 1); Prop?newProp = null; switch (propType) { case PropType.Bike: newProp = new Bike(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Amplifier: newProp = new Amplifier(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.JinKeLa: newProp = new JinKeLa(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Rice: newProp = new Rice(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Shield: newProp = new Shield(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Totem: newProp = new Totem(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Spear: newProp = new Spear(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Dirt: newProp = new Dirt(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Attenuator: newProp = new Attenuator(newPropPos, Map.Constant.unpickedPropRadius); break; case PropType.Divider: newProp = new Divider(newPropPos, Map.Constant.unpickedPropRadius); break; } if (newProp != null) { unpickedPropListLock.EnterWriteLock(); try { unpickedPropList.AddLast(newProp); } finally { unpickedPropListLock.ExitWriteLock(); } newProp.CanMove = true; } }
private void buttonAdd_Click(object sender, EventArgs e) { isInputOk = true; if (!verifyInputs()) { return; } switch (comboBoxConType.SelectedItem.ToString()) { case "HTTP": if (comboBoxAttType.SelectedItem.ToString() == "RCDAT") { attenuator = new Rcdat(textBoxHttpIp.Text, textBoxHttpPort.Text, textBoxDescription.Text, ConnectionTypes.Http); } else { attenuator = new Rudat(textBoxHttpIp.Text, textBoxHttpPort.Text, textBoxDescription.Text, ConnectionTypes.Http); } break; case "TELNET": if (comboBoxAttType.SelectedItem.ToString() == "RCDAT") { attenuator = new Rcdat(textBoxHttpIp.Text, textBoxHttpPort.Text, textBoxDescription.Text, ConnectionTypes.Telnet); } else { attenuator = new Rudat(textBoxHttpIp.Text, textBoxHttpPort.Text, textBoxDescription.Text, ConnectionTypes.Telnet); } break; case "USB": if (comboBoxAttType.SelectedItem.ToString() == "RCDAT") { attenuator = new Rcdat(comboBoxDeviceId.SelectedItem.ToString(), textBoxDescription.Text); } else { attenuator = new Rudat(comboBoxDeviceId.SelectedItem.ToString(), textBoxDescription.Text); } break; case "SERIAL": if (comboBoxAttType.SelectedItem.ToString() == "RCDAT") { attenuator = new Rcdat(comboBoxComPort.SelectedItem.ToString(), textBoxBaudRate.Text, comboBoxParity.Text, comboBoxDataBits.Text, comboBoxStopBits.Text, textBoxDescription.Text, ConnectionTypes.Serial); } else { attenuator = new Rudat(comboBoxComPort.SelectedItem.ToString(), textBoxBaudRate.Text, comboBoxParity.Text, comboBoxDataBits.Text, comboBoxStopBits.Text, textBoxDescription.Text, ConnectionTypes.Serial); } break; default: break; } if (isInputOk) { this.DialogResult = DialogResult.OK; this.Close(); } }