private void SaveDA() { //sleep 500 ms, then reset configuration Thread.Sleep(600); DeviceMgr.Action("daoutput", new byte[] { 0x55, 0x64, 0xfc, 0x00, 0x00, 0x00, 0x04 }); //set control Thread.Sleep(100); }
public void ZeroON() { int i = 0; while (i++ < 5) { double va; if (CollectVoltage(out va)) { DeviceMgr.Action("navzero", 0); System.Threading.Thread.Sleep(1000); return; } System.Threading.Thread.Sleep(1000); } }
public void ZeroON() { int i = 0; while (i++ < 5) { double va; if (CollectVoltage(out va)) { if (Math.Abs(va) < 0.00001) // < 10uV { DeviceMgr.Action("navzero", 0); } break; } System.Threading.Thread.Sleep(1000); } }
private bool ToDAValue(double voltage) { // Vout = (Vrefp-Vrefn)*D/(2^20-1)+Vrefn => D= (Vout-Vrefn)*(2^20-1)/(Vrefp-Vrefn) // when BUF is enabled , Vrefp = 10V; Vrefn = -10V; D = (Vout+10)*(2^20-1)/(20) // D = Vout*(2^20-1)/10; byte[] tosend = new Byte[] { 0x55, 0x64, 0xff, 0x00, 0x00, 0x00, 0x01 }; byte[] tosend2 = new Byte[] { 0x55, 0x64, 0x55, 0xff, 0x00, 0x00, 0x00, 0x01 };//special case for 0x55 leading value bool changed = false; double volt = voltage - Convert.ToDouble(daoffset); if (Math.Abs(volt) > 2.5) //turn off output or invalid adreading { return(false); } Int32 d = Convert.ToInt32(Math.Round((volt + 10) * (1048576 - 1) / 20.0)); tosend[5] = Convert.ToByte(d % 256); d = d / 256; tosend2[6] = tosend[5]; if (tosend[5] != lasttosend[5]) { lasttosend[5] = tosend[5]; changed = true; } tosend[4] = Convert.ToByte(d % 256); tosend2[5] = tosend[4]; d = d / 256; if (tosend[4] != lasttosend[4]) { lasttosend[4] = tosend[4]; changed = true; } tosend[3] = Convert.ToByte(d % 256); tosend2[4] = tosend[3]; if (tosend[3] != lasttosend[3]) { lasttosend[3] = tosend[3]; changed = true; } tosend[2] = Convert.ToByte((256 * 3 - 1 - Convert.ToInt32(tosend[3] + tosend[4] + tosend[5])) % 256); tosend2[3] = tosend[2]; if (changed) { if (tosend[2] == 0x55) { DeviceMgr.Action("daoutput", tosend2); } else { DeviceMgr.Action("daoutput", tosend); } return(DeviceMgr.success); } else { return(true); } }
private bool CollectVoltage(out double reading) { int badcount = 0; //count of bad communication reading = 0; while (badcount < 3) { DeviceMgr.Action("navread", 0); if (DeviceMgr.reading < -999) { if (DeviceMgr.nav_range != "navto1v") { badcount++; if (badcount < 3) { Thread.Sleep(500); continue; } badcount = 0; DeviceMgr.Action("navto1v", ""); Thread.Sleep(3000); continue; } else { return(false); } } else { } //disable range change if (false && (DeviceMgr.nav_range == "navto1v") && (Math.Abs(DeviceMgr.reading) < 0.1) && bOn) { badcount++; if (badcount < 3) { Thread.Sleep(500); continue; } badcount = 0; DeviceMgr.Action("navto120mv", ""); Thread.Sleep(3000); continue; } if (DeviceMgr.nav_range == "navto120mv") { datafilter.Enqueue(DeviceMgr.reading / 1000); } else { datafilter.Enqueue(DeviceMgr.reading); } if (datafilter.Count < 5) { continue; } double sqr; sqr = GetSqrt3(10); datafilter.Dequeue(); if ((DeviceMgr.nav_range == "navto120mv") && (sqr > 0.05)) //1mV { badcount++; continue; } if ((DeviceMgr.nav_range == "navto1v") && (sqr > 0.05)) //10mv { badcount++; continue; } badcount = 0; reading = datafilter.Skip(2).Take(2).Average(); return(true); } return(false); }