Example #1
0
        public static string ReadPn(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[]   buff1 = new byte[16];
            UInt16[] buff  = new UInt16[16];
            string   pn    = Algorithm.MyNaN.ToString();

            try
            {
                if (mdiomode == 1)
                {
                    buff = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 16);
                    for (int i = 0; i < 16; i++)
                    {
                        buff1[i] = (byte)(buff[i]);
                    }
                }
                else
                {
                    buff1 = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 16);
                }
                pn = Convert.ToChar(Convert.ToInt64(buff1[0])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[1])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[2])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[3])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[4])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[5])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[6])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[7])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[8])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[9])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[10])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[11])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[12])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[13])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[14])).ToString() + Convert.ToChar(Convert.ToInt64(buff1[15])).ToString();
                return(pn.Trim());
            }
            catch
            {
                //Log.SaveLogToTxt(ex.Message);
                return(Algorithm.MyNaN.ToString());
            }
        }
Example #2
0
        public static string ReadFWRev(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[] buff  = new byte[4];
            string fwrev = Algorithm.MyNaN.ToString();

            UInt16[] buff1 = new UInt16[1];
            try
            {
                if (mdiomode == 1)
                {
                    buff1   = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 4);
                    buff[0] = (byte)(buff1[0]);
                    buff[1] = (byte)(buff1[1]);
                    buff[2] = (byte)(buff1[2]);
                    buff[3] = (byte)(buff1[3]);
                }
                else
                {
                    buff = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 4);
                }
                fwrev = Convert.ToString((buff[0] << 24) | (buff[1] << 16) | (buff[2] << 8) | buff[3], 16).ToUpper();
                return(fwrev.Trim());
            }
            catch
            {
                //Log.SaveLogToTxt(ex.Message);
                return(Algorithm.MyNaN.ToString());
            }
        }
Example #3
0
        public static double readdmirxp(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[]   buff     = new byte[2];
            UInt16[] buffmdio = new UInt16[1];
            double   rxp      = 0.0;

            try
            {
                if (mdiomode == 1)
                {
                    buffmdio = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 1);
                    rxp      = 10 * (Math.Log10(buffmdio[0] * (1E-4)));
                }
                else
                {
                    buff = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 2);
                    int data = buff[0] * 256 + buff[1];
                    if (data == 0)
                    {
                        return(Algorithm.MyNaN);
                    }
                    rxp = 10 * (Math.Log10((data) * (1E-4)));
                }
                rxp = Math.Round(rxp, 4);
                return(rxp);
            }
            catch
            {
                //Log.SaveLogToTxt(ex.Message);
                return(Algorithm.MyNaN);
            }
        }
Example #4
0
        //read adc
        public static UInt16 readadc(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[] buff = new byte[2];
            UInt16 adc  = 0;

            UInt16[] buff1 = new UInt16[2];
            try
            {
                for (int i = 0; i < 4; i++)
                {
                    if (mdiomode == 1)
                    {
                        buff1   = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 2);
                        buff[0] = (byte)(buff1[0]);
                        buff[1] = (byte)(buff1[1]);
                    }
                    else
                    {
                        buff = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 2);
                    }
                    if (buff[0] != 0)
                    {
                        break;
                    }
                }

                adc = (UInt16)((buff[1]) * 256 + buff[0]);
                return(adc);
            }
            catch (Exception ex)
            {
                //Log.SaveLogToTxt(ex.Message);
                return(Algorithm.MyNaN);
            }
        }
Example #5
0
        public static double readdmibias(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[]   buff     = new byte[2];
            UInt16[] buffmdio = new UInt16[1];
            double   bias     = 0.0;

            try
            {
                if (mdiomode == 1)
                {
                    buffmdio = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 1);
                    bias     = buffmdio[0] / 500.0;
                }
                else
                {
                    buff = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 2);
                    bias = (buff[0] * 256 + buff[1]) / 500.0;
                }
                bias = Math.Round(bias, 4);
                return(bias);
            }
            catch
            {
                //Log.SaveLogToTxt(ex.Message);
                return(Algorithm.MyNaN);
            }
        }
Example #6
0
        public static UInt32 bytetou32(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[]   bcoef     = new byte[4];
            UInt16[] bcoefmdio = new UInt16[4];
            if (mdiomode == 1)
            {
                bcoefmdio = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 4);
                for (int i = 0; i < 4; i++)
                {
                    bcoef[i] = (byte)(bcoefmdio[i]);
                }
            }
            else
            {
                bcoef = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 4);
            }
            UInt32 U32coef = (UInt32)((bcoef[0] << 24) + (bcoef[1] << 16) + (bcoef[2] << 8) + bcoef[3]);

            System.Threading.Thread.Sleep(200);
            return(U32coef);
        }
Example #7
0
        public static Int16 bytetoi16(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[]   bcoef     = new byte[2];
            UInt16[] bcoefmdio = new UInt16[2];
            if (mdiomode == 1)
            {
                bcoefmdio = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 2);
                for (int i = 0; i < 2; i++)
                {
                    bcoef[i] = (byte)(bcoefmdio[i]);
                }
            }
            else
            {
                bcoef = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 2);
            }

            System.Threading.Thread.Sleep(200);

            Int16 i16coef = (Int16)((bcoef[1] << 8) + bcoef[0]);

            return(i16coef);
        }
Example #8
0
        public static float ieeetofloat(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            float fcoef;

            byte[] bcoef = new byte[4];

            UInt16[] bcoefmdio = new UInt16[4];
            if (mdiomode == 1)
            {
                bcoefmdio = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 4);
                for (int i = 0; i < 4; i++)
                {
                    bcoef[i] = (byte)(bcoefmdio[i]);
                }
            }
            else
            {
                bcoef = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 4);
            }
            System.Threading.Thread.Sleep(200);
            bcoef.Reverse();
            fcoef = BitConverter.ToSingle(bcoef, 0);
            return(fcoef);
        }
Example #9
0
        public static double readdmitemp(int deviceIndex, int deviceAddress, int regAddress, int phycialAdress = 0, int mdiomode = 0)
        {
            byte[]   buff        = new byte[2];
            UInt16[] buffmdio    = new UInt16[1];
            double   temperature = 0.0;

            try
            {
                if (mdiomode == 1)
                {
                    buffmdio = IOPort.ReadMDIO(deviceIndex, deviceAddress, phycialAdress, regAddress, IOPort.MDIOSoftHard.SOFTWARE, 1);

                    buff[0] = (byte)(buffmdio[0] / 256);
                    buff[1] = (byte)(buffmdio[0] & 0xFF);
                }
                else
                {
                    buff = IOPort.ReadReg(deviceIndex, deviceAddress, regAddress, softHard, 2);
                }
                if (buff[0] > Convert.ToByte(127))
                {
                    temperature = (buff[0] + (buff[1] / 256.0)) - 256;
                }
                else
                {
                    temperature = (buff[0] + (buff[1] / 256.0));
                }
                temperature = Math.Round(temperature, 4);
                return(temperature);
            }
            catch
            {
                //Log.SaveLogToTxt(ex.Message);
                return(Algorithm.MyNaN);
            }
        }