コード例 #1
0
ファイル: VisaCom.cs プロジェクト: Eddie02582/C-Sharp
        public string DoQueryString(string strQuery)
        {
            // Send the query.
            m_IoObject.WriteString(strQuery, true);
            // Get the result string.
            string strResults;

            strResults = m_IoObject.ReadString();
            // Check for inst errors.
            CheckInstrumentErrors(strQuery);
            // Return results string.
            return(strResults);
        }
コード例 #2
0
        public bool Read(ref string instruRdCmd)
        {
            bool ret = true;

            try
            {
                instruRdCmd = IO_Obj.ReadString();
            }
            catch {
                instruRdCmd = "Device,Read Err,Connection,Fail";
                ret         = false;
            }
            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// 读取(字符串)
        /// </summary>
        /// <returns></returns>
        public string ReadString()
        {
            string m_Temp = string.Empty;

            try
            {
                if (m_IO488 != null)
                {
                    m_Temp = m_IO488.ReadString();
                }
            }
            catch (System.IO.IOException error)  //控制箱掉线
            {
                throw error;
            }
            catch (Exception ex)
            {
                if (ex.Message == "VI_ERROR_NCIC: Not the controller-in-charge") //掉线
                {
                    throw ex;
                }
            }
            return(m_Temp);
        }
コード例 #4
0
        /// <summary>
        /// 读取(字符串)
        /// </summary>
        /// <returns></returns>
        public string ReadString()
        {
            string m_Temp = string.Empty;

            try
            {
                if (m_IO488 != null)
                {
                    if (commMode == InstrumentCommunicationMode.TCP)
                    {
                        while (true)
                        {
                            string str = m_IO488.IO.ReadString(1);  //单字节获取
                            if (str == "\n")
                            {
                                break;
                            }
                            else
                            {
                                m_Temp += str;
                            }
                        }
                    }
                    else
                    {
                        if (m_IO488 != null)
                        {
                            m_Temp = m_IO488.ReadString();
                        }
                    }
                }
            }
            catch (System.IO.IOException error)  //控制箱掉线
            {
                throw error;
            }
            catch (Exception ex)
            {
                if (ex.Message == "VI_ERROR_NCIC: Not the controller-in-charge") //掉线
                {
                    throw ex;
                }
            }
            return(m_Temp);
        }
コード例 #5
0
ファイル: VISA_Driver.cs プロジェクト: marrob/CsharpCheats
        public void BK8600()
        {
            //EC7::0x8800::802197036737120008::INSTR
            string          srcAddress = "USB0::0x2EC7::0x8800::802197036737120008::INSTR";
            ResourceManager rMgr       = new ResourceManagerClass();
            FormattedIO488  src        = new FormattedIO488Class();
            var             addresses  = rMgr.FindRsrc("USB?*");

            var s = rMgr.Description;
            var x = rMgr.SpecVersion;

            src.IO         = (IMessage)rMgr.Open(srcAddress, AccessMode.NO_LOCK, 2000, "");
            src.IO.Timeout = 2000;
            src.IO.Clear();
            src.WriteString("*RST; *OPC ?", true);
            src.WriteString("*IDN?", true);
            string temp = src.ReadString();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var rm = new ResourceManagerClass();


            string addr   = "USB0::0x2A8D::0xB318::MY57330031::0::INSTR";
            var    myDmm2 = new FormattedIO488Class();

            myDmm2.IO = (IMessage)rm.Open(addr, AccessMode.NO_LOCK, 2000, "");



            while (true)
            {
                myDmm2.IO.WriteString("READ?");
                var result = myDmm2.ReadString();
                Console.WriteLine(result);
            }



            while (true)
            {
                Write("Press ENTER to start read/write");
                var key = Console.ReadKey();
                if (key.Key != ConsoleKey.Enter)
                {
                    return;
                }

                Write("Reading from device");

                var myDmm = new FormattedIO488Class();
                try
                {
                    myDmm.IO = (IMessage)rm.Open(addr, AccessMode.NO_LOCK, 2000, "");

                    myDmm.IO.WriteString("DATA:DATA? NVMEM");
                    var result = myDmm.ReadString();

                    var rawNumbers = result.Split(',');

                    Write($"found {rawNumbers.Length} measurements");

                    var formatProvider = new CultureInfo("en-us");

                    var chart = new Chart();

                    chart.AmpereValues = rawNumbers
                                         .Select(x => double.Parse(x, formatProvider))
                                         .ToList();

                    chart.Count              = chart.AmpereValues.Count;
                    chart.Mittelwert         = chart.AmpereValues.Average();
                    chart.Min                = chart.AmpereValues.Min();
                    chart.Max                = chart.AmpereValues.Max();
                    chart.Standardabweichung = chart.AmpereValues
                                               .Select(x =>
                    {
                        var minusMittel = x - chart.Mittelwert;
                        return((double)Math.Sqrt((double)(minusMittel * minusMittel)));
                    })
                                               .Average();

                    Console.WriteLine(chart);

                    Write("Input Title (Default: " + chart.Title + "):");

                    var title = Console.ReadLine();
                    if (!string.IsNullOrWhiteSpace(title))
                    {
                        chart.Title = title + "-" + chart.Title;
                    }

                    Write("Creating file: " + chart.Title);

                    var json = JsonConvert.SerializeObject(chart);
                    File.WriteAllText(@"D:\GoogleDrive\FH Joanneum\Master\graphs\logs\" + chart.Title + ".json", json,
                                      Encoding.UTF8);

                    Write("Done creating file");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    myDmm.IO.Close();
                }
            }

            Console.Read();
        }
コード例 #7
0
ファイル: IO.cs プロジェクト: lihuangroove/SG-PXA
        public static void ScanIOStatus(ref string[] m_IOAddress, ref string[] m_Description)
        {
            string empty = string.Empty;
            string str   = string.Empty;

            try
            {
                ResourceManagerClass resourceManagerClass = new ResourceManagerClass();
                string[]             portNames            = new string[1];
                FormattedIO488Class  formattedIO488Class  = new FormattedIO488Class();
                portNames = resourceManagerClass.FindRsrc("GPIB?*");
                for (int i = 1; i < (int)portNames.Length; i++)
                {
                    try
                    {
                        string empty1 = string.Empty;
                        formattedIO488Class = new FormattedIO488Class()
                        {
                            IO = (IMessage)resourceManagerClass.Open(portNames[i], AccessMode.NO_LOCK, 20000, "")
                        };
                        formattedIO488Class.IO.Clear();
                        try
                        {
                            formattedIO488Class.WriteString("*IDN?", true);
                            Thread.Sleep(100);
                            empty1 = formattedIO488Class.ReadString();
                        }
                        catch
                        {
                        }
                        if (!(empty1 != string.Empty) || !(empty1 != "\r\n"))
                        {
                            try
                            {
                                formattedIO488Class.WriteString("ID?", true);
                                Thread.Sleep(100);
                                empty1 = formattedIO488Class.ReadString();
                            }
                            catch
                            {
                            }
                            if (empty1 != string.Empty)
                            {
                                if (empty != string.Empty)
                                {
                                    empty = string.Concat(empty, ";");
                                    str   = string.Concat(str, ";");
                                }
                                empty = string.Concat(empty, portNames[i]);
                                str   = string.Concat(str, empty1);
                            }
                        }
                        else
                        {
                            if (empty != string.Empty)
                            {
                                empty = string.Concat(empty, ";");
                                str   = string.Concat(str, ";");
                            }
                            empty = string.Concat(empty, portNames[i]);
                            str   = string.Concat(str, empty1);
                        }
                        formattedIO488Class.IO.Close();
                    }
                    catch
                    {
                    }
                }
                try
                {
                    portNames = resourceManagerClass.FindRsrc("TCPIP0::?*");
                }
                catch
                {
                    portNames = new string[0];
                }
                for (int j = 0; j < (int)portNames.Length; j++)
                {
                    try
                    {
                        formattedIO488Class = new FormattedIO488Class()
                        {
                            IO = (IMessage)resourceManagerClass.Open(portNames[j], AccessMode.NO_LOCK, 20000, "")
                        };
                        formattedIO488Class.IO.Timeout = 2000;
                        formattedIO488Class.WriteString("*IDN?", true);
                        Thread.Sleep(100);
                        string str1 = formattedIO488Class.ReadString();
                        if (str1 != string.Empty)
                        {
                            if (empty != string.Empty)
                            {
                                empty = string.Concat(empty, ";");
                                str   = string.Concat(str, ";");
                            }
                            empty = string.Concat(empty, portNames[j]);
                            str   = string.Concat(str, str1);
                        }
                    }
                    catch
                    {
                    }
                }
                try
                {
                    portNames = resourceManagerClass.FindRsrc("ASRL?*");
                }
                catch
                {
                    portNames = new string[0];
                }
                for (int k = 0; k < (int)portNames.Length; k++)
                {
                    try
                    {
                        formattedIO488Class = new FormattedIO488Class()
                        {
                            IO = (IMessage)resourceManagerClass.Open(portNames[k], AccessMode.NO_LOCK, 20000, "")
                        };
                        formattedIO488Class.WriteString("*IDN?", true);
                        Thread.Sleep(100);
                        string str2 = formattedIO488Class.ReadString();
                        if (str2 != string.Empty)
                        {
                            if (empty != string.Empty)
                            {
                                empty = string.Concat(empty, ";");
                                str   = string.Concat(str, ";");
                            }
                            empty = string.Concat(empty, portNames[k]);
                            str   = string.Concat(str, str2);
                        }
                        formattedIO488Class.IO.Close();
                    }
                    catch
                    {
                    }
                }
                try
                {
                    portNames = resourceManagerClass.FindRsrc("USB?*");
                }
                catch
                {
                    portNames = new string[0];
                }
                for (int l = 0; l < (int)portNames.Length; l++)
                {
                    try
                    {
                        formattedIO488Class = new FormattedIO488Class()
                        {
                            IO = (IMessage)resourceManagerClass.Open(portNames[l], AccessMode.NO_LOCK, 20000, "")
                        };
                        formattedIO488Class.WriteString("*IDN?", true);
                        Thread.Sleep(100);
                        string str3 = formattedIO488Class.ReadString();
                        if (str3 != string.Empty)
                        {
                            if (empty != string.Empty)
                            {
                                empty = string.Concat(empty, ";");
                                str   = string.Concat(str, ";");
                            }
                            empty = string.Concat(empty, portNames[l]);
                            str   = string.Concat(str, str3);
                        }
                        formattedIO488Class.IO.Close();
                    }
                    catch
                    {
                    }
                }
                portNames = SerialPort.GetPortNames();
                for (int m = 0; m < (int)portNames.Length; m++)
                {
                    try
                    {
                        int num = 0;
                        while (true)
                        {
                            string     str4       = "*IDN?";
                            SerialPort serialPort = new SerialPort(portNames[m])
                            {
                                BaudRate = 9600,
                                DataBits = 8,
                                Parity   = Parity.None
                            };
                            serialPort.Open();
                            Thread.Sleep(300);
                            serialPort.Write("\r\n");
                            for (int n = 0; n < str4.Length; n++)
                            {
                                serialPort.Write(str4.Substring(n, 1));
                                Thread.Sleep(20);
                                if (n == str4.Length - 1)
                                {
                                    serialPort.Write("\r");
                                }
                            }
                            Thread.Sleep(300);
                            string str5 = serialPort.ReadExisting();
                            serialPort.Close();
                            if (!(str5 != string.Empty) || str5.IndexOf("*IDN?") >= 0)
                            {
                                if (num >= 1)
                                {
                                    break;
                                }
                                num++;
                            }
                            else
                            {
                                if (empty != string.Empty)
                                {
                                    empty = string.Concat(empty, ";");
                                    str   = string.Concat(str, ";");
                                }
                                empty = string.Concat(empty, portNames[m]);
                                str   = string.Concat(str, str5);
                                break;
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                    }
                }
            }
            catch
            {
            }
            char[] chrArray = new char[] { ';' };
            m_IOAddress = empty.Split(chrArray);
            char[] chrArray1 = new char[] { ';' };
            m_Description = str.Split(chrArray1);
        }