예제 #1
0
        public static byte[] WriteMDIO(int deviceIndex, int deviceAddress, int phycialAddress, int regAddress, MDIOSoftHard softHard, UInt16[] dataToWrite)
        {
            byte[] writedata = new byte[dataToWrite.Length * 2];
            int    j         = 0;

            for (int i = 0; i < dataToWrite.Length; i++)
            {
                writedata[j]     = (byte)(dataToWrite[i] / 256);
                writedata[j + 1] = (byte)(dataToWrite[i] & 0xFF);
                j = j + 2;
            }
            return(ReadWriteMDIO(deviceIndex, deviceAddress, phycialAddress, regAddress, false, softHard, ReadWrite.Write, (MDIOCFKType)2, writedata));
        }
예제 #2
0
        public static byte[] ReadWriteMDIO(int deviceIndex, int deviceAddress, int phycialAddress, int regAddress, bool regAddressWide, MDIOSoftHard softHard,
                                           ReadWrite operate, MDIOCFKType cfk, UInt32 buffer)
        {
            //semaphore.WaitOne();
            OpenDevice(deviceIndex);
            CH375SetTimeout((byte)deviceIndex, 100, 100);

            byte[] arr = new byte[2 + 10];
            arr[0] = 0;
            arr[1] = 0;
            arr[2] = (byte)softHard;
            arr[3] = (byte)operate;
            arr[4] = (byte)cfk;
            arr[5] = (byte)phycialAddress;
            arr[6] = (byte)deviceAddress;
            arr[7] = (byte)(regAddress / 256);
            arr[8] = (byte)(regAddress & 0xFF);
            arr[9] = (byte)(1);
            arr[8] = (byte)(regAddress & 0xFF);
            arr[9] = (byte)(1);

            bool b = CH375WriteData(deviceIndex, arr);

            System.Threading.Thread.Sleep(100);
            byte[] arrRead = CH375ReadData(deviceIndex, 1);
            CloseDevice(deviceIndex);
            semaphore.Release();
            System.Threading.Thread.Sleep(100);

            return(arrRead);
        }
예제 #3
0
        public static UInt16[] ReadMDIO(int deviceIndex, int deviceAddress, int phycialAddress, int regAddress, MDIOSoftHard softHard, int readLength)
        {
            UInt16[] returndata = new UInt16[readLength];

            byte[] readdata = new byte[readLength * 2];
            readdata = ReadWriteMDIO(deviceIndex, deviceAddress, phycialAddress, regAddress, false, softHard, ReadWrite.Read,
                                     (MDIOCFKType)2, new byte[readLength * 2]);

            int j = 0;

            for (int i = 0; i < readdata.Length; i = i + 2)
            {
                returndata[j] = (UInt16)((readdata[i] * 256) + readdata[i + 1]);
                j++;
            }

            return(returndata);
        }
예제 #4
0
        public static byte[] ReadWriteMDIO(int deviceIndex, int deviceAddress, int phycialAddress, int regAddress, bool regAddressWide, MDIOSoftHard softHard,
                                           ReadWrite operate, MDIOCFKType cfk, byte[] buffer)
        {
            //  log.AdapterLogString(3, ex.Message);
            semaphore.WaitOne();
            CH375ResetDevice((byte)deviceIndex);
            OpenDevice(deviceIndex);
            CH375SetTimeout((byte)deviceIndex, 100, 100);

            byte[] arr = new byte[buffer.Length + 10];
            arr[0] = 0;
            arr[1] = 0;
            arr[2] = (byte)softHard;
            arr[3] = (byte)operate;
            arr[4] = (byte)cfk;
            arr[5] = (byte)phycialAddress;
            arr[6] = (byte)deviceAddress;
            arr[7] = (byte)(regAddress / 256);
            arr[8] = (byte)(regAddress & 0xFF);
            arr[9] = (byte)(buffer.Length / 2);
            buffer.CopyTo(arr, 10);
            bool b = CH375WriteData(deviceIndex, arr);

            System.Threading.Thread.Sleep(50);
            if ((byte)operate == 1)
            {
                int k = 0;
                do
                {
                    System.Threading.Thread.Sleep(50);
                    byte[] ACK = CH375ReadData(deviceIndex, buffer.Length);
                    if (ACK[0] == 0xAA && ACK[1] == 0xAA)
                    {
                        break;
                    }
                    k++;
                } while (k < 6);
            }

            byte[] arrRead = CH375ReadData(deviceIndex, buffer.Length);
            System.Threading.Thread.Sleep(100);
            CloseDevice(deviceIndex);
            semaphore.Release();
            //System.Threading.Thread.Sleep(50);
            return(arrRead);
        }