private bool SetFreq(double freq, int gain) { String return_string; String cmd; Logbox.AppendText("Freq = [" + freq + "],gain = [" + gain + "].\r\n"); if (true != open_port(name)) { return(false); } cmd = "AT+SETFREQ=" + freq + "HZ,GAIN=" + gain + ".\r\n"; return_string = send_data(cmd, 1000); if (-1 == return_string.IndexOf("APT,Set freq done.")) { Logbox.AppendText("Err:" + return_string); dev_port.Close(); return(false); } else { Logbox.AppendText("Set freq done.\r\n"); } dev_port.Close(); return(true); }
public bool SetFreq(double freq, VvUI.FreqUnit_t freq_uint, double power, VvUI.PowerUnit_t power_unit) { if (name == null) { Logbox.AppendText("Device not open.\r\n"); return(false); } else { if (freq_uint == VvUI.FreqUnit_t.Hz) { } else if (freq_uint == VvUI.FreqUnit_t.KHz) { freq *= 1e3; } else if (freq_uint == VvUI.FreqUnit_t.MHz) { freq *= 1e6; } else if (freq_uint == VvUI.FreqUnit_t.GHz) { freq *= 1e9; } if (power_unit == VvUI.PowerUnit_t.mv) { power = 10 * Math.Log(power); return(SetFreq(freq, power)); } else if (power_unit == VvUI.PowerUnit_t.dbm) { return(SetFreq(freq, power)); } else //(power_unit == VvUI.PowerUnit_t.gain) { return(SetFreq(freq, (int)power)); } } }
//detect a vv device by pid and vid. public bool ScanDevice() { //device_scanned_flg = true; try { var searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSerial_PortName"); foreach (ManagementObject queryObj in searcher.Get()) { if ((queryObj["InstanceName"].ToString().Contains(vid)) && (queryObj["InstanceName"].ToString().Contains(pid))) { String port_name = queryObj["PortName"].ToString(); //Logbox.AppendText("Found : " + port_name + "\r\n"); if (true == verify_device(port_name)) { Logbox.AppendText("Found vv device at " + "[" + port_name + "]" + ".\r\n"); name = port_name; return(true); } else { Logbox.AppendText("Port [" + port_name + "]" + " open error or not response.\r\n"); } } else //not a vv device. { Logbox.AppendText("Not found a device."); } } } catch (ManagementException ex) { Logbox.AppendText("Scan device error, disable UAC or run as administrator.\r\n"); } return(false); }