Ejemplo n.º 1
0
        /// <summary>
        /// 从设备读取命令返回结果
        /// </summary>
        /// <returns>从设备读取到的返回字符串</returns>
        private Int32 _Device_Read_Bytes(byte[] buf, Int32 count)
        {
            Int32 retCount = 0;

            ClassVisa.viRead(g_i32VisaIO, buf, count, out retCount);
            return(retCount);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置串口的波特率
        /// </summary>
        /// <param name="baud">
        /// 串口波特率,
        /// </param>
        /// <returns>
        /// 返回值:0,配置成功,负数,配置失败
        /// </returns>
        public int ASLSetBAUD(int baud)
        {
            int state;

            state = ClassVisa.viSetAttribute(g_i32VisaIO, ClassVisa.VI_ATTR_ASRL_BAUD, baud);
            return(state);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置串口的timeOut时间
        /// </summary>
        /// <param name="T_timeOut">
        /// timeout的时间ms
        /// </param>
        /// <returns>
        /// 返回值:0,配置成功,负数,配置失败
        /// </returns>
        public int ASLSetTimerOut(int T_timeOut)
        {
            int state;

            state = ClassVisa.viSetAttribute(g_i32VisaIO, ClassVisa.VI_ATTR_TMO_VALUE, T_timeOut);
            return(state);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从设备读取命令返回结果
        /// </summary>
        /// <returns>从设备读取到的返回字符串</returns>
        private string _Device_Read(int Len = 1024)
        {
            string strReturn = "";         //返回值参数并初始化

            try
            {
                byte[] temp = new byte[Len];   //buffer

                int Error = ClassVisa.viScanf(g_i32VisaIO, "%t", temp);
                if (Error < 0)
                {
                    return(strReturn);
                }

                strReturn = Encoding.ASCII.GetString(temp); //将接收到的字节数组内容转化成为字符串

                //remove '\n'
                if (strReturn.IndexOf('\n') != -1)
                {
                    strReturn = strReturn.Substring(0, strReturn.IndexOf('\n'));
                }
            }
            catch (Exception err)
            {
                //统一错误处理    error handling
            }

            return(strReturn);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 配置串口通信的数据位数
        /// </summary>
        /// <param name="stopbits">
        /// ClassVisa.VI_ASRL_STOP_ONE   - 10 - 1 stop bit is used per frame,
        /// ClassVisa.VI_ASRL_STOP_ONE5  - 15 - 1.5 stop bits are used per frame,
        /// ClassVisa.VI_ASRL_STOP_TWO   - 20 - 2 stop bits are used per frame.
        /// </param>
        /// <returns>
        /// 返回值:0,配置成功,负数,配置失败
        /// </returns>
        public int ASLSetSTOPBITS(int stopbits)
        {
            int state;

            state = ClassVisa.viSetAttribute(g_i32VisaIO, ClassVisa.VI_ATTR_ASRL_STOP_BITS, stopbits);
            return(state);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 配置串口通信的数据位数
        /// </summary>
        /// <param name="databits">
        /// 串行通信数据位数,取值范围:5-8
        /// </param>
        /// <returns>
        ///  返回值:0,配置成功,负数,配置失败
        /// </returns>
        public int ASLSeDATAtBITS(int databits)
        {
            int state;

            state = ClassVisa.viSetAttribute(g_i32VisaIO, ClassVisa.VI_ATTR_ASRL_DATA_BITS, databits);
            return(state);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 配置串口的奇偶校验位
        /// </summary>
        /// <param name="parity">
        /// 输入变量:奇偶校验类型
        /// ClassVisa.VI_ASRL_PAR_NONE - 0  - No parity bit exists,
        /// ClassVisa.VI_ASRL_PAR_ODD  - 1  - Odd parity should be used,
        /// ClassVisa.VI_ASRL_PAR_EVEN - 2  - Even parity should be used,
        /// ClassVisa.VI_ASRL_PAR_MARK - 3  - MARK  Parity bit exists and is always 1,
        /// ClassVisa.VI_ASRL_PAR_SPACE - 4  - SPACE Parity bit exists and is always 0.
        /// </param>
        /// <returns>
        /// 返回值:0,配置成功,负数,配置失败
        /// </returns>
        public int ASLSetPARITY(int parity)
        {
            int state;

            state = ClassVisa.viSetAttribute(g_i32VisaIO, ClassVisa.VI_ATTR_ASRL_PARITY, parity);
            return(state);
        }
Ejemplo n.º 8
0
        /********************************************* 私有方法 *********************************************/


        /// <summary>
        /// 根据地址信息打开设备
        /// </summary>
        /// <param name="strAddr">设备地址字符串</param>
        /// <param name="TimeOut_ms">超时时间</param>
        /// <returns>错误码</returns>
        private int _Device_Open(string strAddr, int TimeOut_ms)
        {
            try
            {
                ClassVisa.viClose(g_i32VisaIO);
                //根据地址信息打开设备
                ClassVisa.viOpen(ClassVisa.g_i32RsrcManager, strAddr, 0, TimeOut_ms, ref g_i32VisaIO);
            }
            catch (Exception err)
            {
                //统一错误处理  error handling
            }
            return(0);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 向设备写入数据
        /// </summary>
        /// <param name="Cmd">命令字符串</param>
        /// <returns>错误码</returns>
        private int _Device_Write_Bytes(byte[] buf, Int32 count)
        {
            Int32 retCount = 0;

            try
            {
                return(ClassVisa.viWrite(g_i32VisaIO, buf, count, retCount)); //向visa接口发送命令符
            }
            catch (Exception err)
            {
                //统一错误处理 error handling
            }

            return(retCount);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 向设备写入命令字符串
        /// </summary>
        /// <param name="Cmd">命令字符串</param>
        /// <returns>错误码</returns>
        private int _Device_Write(string Cmd)
        {
            try
            {
                string strCmd = Cmd;                                 //命令字符串

                return(ClassVisa.viVPrintf(g_i32VisaIO, strCmd, 0)); //向visa接口发送命令符
            }
            catch (Exception err)
            {
                //统一错误处理  error handling
            }

            return(0);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 关闭当前打开的设备
 /// </summary>
 /// <returns>错误码</returns>
 private int _Device_Close()
 {
     return(ClassVisa.viClose(g_i32VisaIO));
 }