/// <summary> /// 打开串口 /// </summary> /// <param name="comName"></param> /// <param name="er"></param> /// <param name="setting"></param> /// <returns></returns> public bool Open(string comName, out string er, string setting = "9600,n,8,1") { er = string.Empty; try { if (com != null) { com.Dispose(); com = null; } int boardNum = System.Convert.ToInt16(comName); byte primaryAddress = System.Convert.ToByte(setting); byte secondaryAddress = 0; com = new NationalInstruments.NI4882.Device(boardNum, primaryAddress, secondaryAddress); _conStatus = true; return(true); } catch (Exception ex) { er = ex.ToString(); return(false); } }
public static void CloseDevice() { if (bDeviceOpen) { device.Dispose(); bDeviceOpen = false; } }
public static void SetDAC(int n, double v) { Device device = new Device(0, 12, 0); device.SetEndOnEndOfString = true; device.SetEndOnWrite = true; device.Write(String.Format("DAC. {0} {1}", n.ToString(), v.ToString("F4"))); device.Dispose(); }
public static double AverageADC(int n, int samples) { Device device = new Device(0, 12, 0); device.SetEndOnEndOfString = true; device.SetEndOnWrite = true; var V = Vector<double>.Build; var data = V.Dense(samples); for (int i = 0; i < samples; i++) { device.Write("ADC.2"); string response = device.ReadString(); data[i] = Convert.ToDouble(response); } device.Dispose(); return data.Average(); }