Example #1
0
        static void Main(string[] args)
        {
            var device = new Device(0, new Address(12, 96));
            device.Write("*IDN?");
            string data = device.ReadString();
            Console.WriteLine(data);
            Console.ReadLine();

            //device.Write("DAT:SOU CH1");
            //device.Write("DAT:ENC RIB;WID 1");
            //device.Write("HOR:RECORDL 500");
            //device.Write("DAT:STAR 1");
            //device.Write("DAT:STOP 500");
            //device.Write("HEAD OFF");
            //device.Write("ACQ:STATE RUN");

            //device.Write("WFMPRE:CH1:NR_PT?;YOFF?;YMULT?;XINCR?;PT_OFF?;XUNIT?;YUNIT?WFMPRE:CH1:NR_PT?;YOFF?;YMULT?;XINCR?;PT_OFF?;XUNIT?;YUNIT?");
            //data = device.ReadString();
            //Console.WriteLine(data);
            //Console.ReadLine();
            for (int i = 0; i < 100; i++)
            {
                device.Write("curv?");
                device.ReadByteArray(1);
                int length = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(device.ReadByteArray(1)));
                int count = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(device.ReadByteArray(length)));
                Byte[] curve = device.ReadByteArray(count);
                foreach(byte b in curve)
                {
                    int number = Convert.ToInt32( b);
                    Console.Write(number+",");
                }
                Console.WriteLine();

                device.Write("curv?");
                data = device.ReadString();
                Console.WriteLine(data.Length);
                length = Convert.ToInt32(data[1].ToString());
                for(int j= 2 + length; j < data.Length; j++)
                {
                    int number = (int)data[j] ;
                    Console.Write(number + ",");
                }
                Console.WriteLine();
                Console.WriteLine(data);
            }
            Console.ReadLine();
        }
Example #2
0
        public void Start()
        {
            logger.Trace("Starting collecting the waveform");

            device = new Device(0, new Address(12, 96));
            device.Write("*IDN?");
            string data = device.ReadString();
            logger.Trace(String.Format("the scope infomation:{0}",data));

            string channel = "CH1";
            device.Reset();
            device.Write(string.Format("DAT:SOU {0}",channel));
            device.Write("DAT:ENC RIB;WID 1");
            device.Write("DAT:STAR 1");
            device.Write("DAT:STOP 2500");
            device.Write("HEAD OFF");
            device.Write("ACQ:STATE RUN");

            logger.Trace(string.Format("Waveform from {0}", channel));
            ///get wave parameters

            CurveMetaData meta = new CurveMetaData();
            device.Write("WFMPre:WFId?");
            meta.CurveId = device.ReadString();
            device.Write("WFMPre:Xincr?");
            meta.Xincr = Convert.ToDouble(device.ReadString());
            device.Write("WFMPre:Xzero?");
            meta.Xzero = Convert.ToDouble(device.ReadString());
            device.Write("WFMPre:PT_Off?");
            meta.Ptoff = Convert.ToDouble(device.ReadString());
            device.Write("WFMPre:Ymult?");
            meta.YMult = Convert.ToDouble(device.ReadString());
            device.Write("WFMPre:Yoff?");
            meta.Yoff = Convert.ToDouble(device.ReadString());
            device.Write("WFMPre:YZero?");
            meta.Yzero = Convert.ToDouble(device.ReadString());

            logger.Trace(string.Format("Waveform metadata : {0}", JsonConvert.SerializeObject(meta)));

            cts = new CancellationTokenSource();
            ct = cts.Token;
            curveNumber = 0;
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (!ct.IsCancellationRequested)
                    {
                        try
                        {
                            device.Write("Curv?");

                            device.ReadByteArray(1);
                            int count = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(device.ReadByteArray(1)));
                            int npt = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(device.ReadByteArray(count)));
                            Byte[] waveform = device.ReadByteArray(npt);
                            data = device.ReadString();
                            CurveData curvedata = new CurveData()
                            {
                                MetaData = meta,
                                Points = new List<CurvePoint>(),
                                Orginal = new List<int>()
                            };
                           // int length = Convert.ToInt32(data[1].ToString());
                            for (int j = 0; j < npt; j++)
                            {
                                int pointData = (int)waveform[j];
                                curvedata.Orginal.Add(pointData);
                                CurvePoint point = new CurvePoint()
                                {
                                    X = meta.Xzero + meta.Xincr * (j-meta.Ptoff),
                                    Y = meta.Yzero + meta.YMult * (pointData - meta.Yoff)
                                };
                                curvedata.Points.Add(point);
                                //sum up
                                if (curveNumber == 0)
                                {
                                    sumDData.Add(point);
                                }
                                else
                                {
                                    sumDData[j].Y += point.Y;
                                }
                            }

                            logger.Trace(string.Format("raw:{0}", JsonConvert.SerializeObject(curvedata.Orginal)));
                            logger.Trace(string.Format("converted:{0}", JsonConvert.SerializeObject(curvedata.Points)));
                            Clients.All.getData(curvedata);
                            curveNumber++;

                        }
                        catch (Exception)
                        {

                        }
                        finally
                        {
                            device.Clear();
                            Thread.Sleep(1000);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("cancelled!");
                        break;

                    }
                }
            }, ct);
        }