Exemple #1
0
        internal override void Refresh()
        {
            if (IsConnected())
            {
                try
                {
                    while (true)
                    {
                        int ret   = li.ibrd(Dev, Response);
                        int asize = li.ibcnt;
                        int size  = li.ibcntl;


                        if (Response[0] != 0x00)
                        {
                            string t = "";
                            for (int i = 0; i < Response.Length; i++)
                            {
                                if (Response[i] == 0x00)
                                {
                                    break;
                                }
                                try
                                {
                                    char l = Convert.ToChar(Response[i]);
                                    if (i == 0)
                                    {
                                        Response[0] = 0x00; //clear flag
                                    }
                                    t = t + l;
                                    if (l.ToString().IndexOfAny(filter) < 0)
                                    {
                                        Util.SysLog("invalid char" + l.ToString());
                                        throw new Exception("invalid char" + l.ToString());
                                    }
                                    DataRecieved(this, l.ToString());
                                }catch {
                                    Util.SysLog("ECHO");
                                    Thread.Sleep(200);
                                    Send("ECHO\r\n", true);
                                    break;
                                }
                            }
                            Util.SysLog("Rcv:" + t);
                            ResetResponse();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Util.SysLog("GPIB Refresh:" + ex.Message + ex.StackTrace);
                    ResetResponse();
                }
            }
        }
Exemple #2
0
        internal string Read()
        {
            if (IsConnected())
            {
                try
                {
                    string ret  = "";
                    int    size = li.ibrd(Dev, out ret, 2000);
                    if (ret.Length > 1)
                    {
                        Logger.Log(ret);
                    }
                    return(ret);
                }
                catch
                {
                    return("");
                }

                /*
                 * int ret = li.ibrd(Dev, Response);
                 * int asize = li.ibcnt;
                 * int size = li.ibcntl;
                 *
                 * if (Response[0] != 0x00)
                 * {
                 *  string t = "";
                 *  for (int i = 0; i < Response.Length; i++)
                 *  {
                 *      if (Response[i] == 0x00)
                 *          break;
                 *      char l = Convert.ToChar(Response[i]);
                 *      if (i == 0)
                 *          Response[0] = 0x00; //clear flag
                 *
                 *      t = t + l;
                 *      if (l.ToString().IndexOfAny(filter) < 0)
                 *      {
                 *          Util.SysLog("invalid char" + l.ToString());
                 *          throw new Exception("invalid char" + l.ToString());
                 *      }
                 *  }
                 *  Util.SysLog("Rcv:" + t);
                 *  ResetResponse();
                 *  return t;
                 * }
                 *
                 * }
                 * catch (Exception ex)
                 * {
                 * Util.SysLog("GPIB Refresh:" + ex.Message + ex.StackTrace);
                 * ResetResponse();
                 * }*/
            }
            return("");
        }
Exemple #3
0
 //read data form device
 public string GPIBrd(int buffersize)
 {
     try
     {
         li.ibrd(Dev, out ValueStr, buffersize);
         li.ibclr(Dev);
         return(ValueStr);
     }
     catch (System.Exception Ex)
     {
         throw new Exception("Error: " + Ex.Message +          //error Name
                             "ibsta = " + li.ibsta +           //ibsta
                             "iberr = " + li.iberr +           //iberr
                             ErrorMnemonic[li.iberr]);         //error code
     }
 }