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); }
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); //System.Threading.Thread.Sleep(100); 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); } //System.Threading.Thread.Sleep(100); byte[] arrRead = CH375ReadData(deviceIndex, buffer.Length); System.Threading.Thread.Sleep(100); CloseDevice(deviceIndex); semaphore.Release(); //System.Threading.Thread.Sleep(50); return(arrRead); }