For the 3rd day I have been struggling with the problem of reading data from a device using the FTD2XX_NET library. The essence of the problem is that reading is performed only once. When you try to write, read the read buffer again is 0. How to perform cyclic read-write operations.

myFtdiDevice.Close(); // закрываем, ели друг забыли закрыть // Открываем порт ftStatus = myFtdiDevice.OpenBySerialNumber(SerialN); if (ftStatus != FTDI.FT_STATUS.FT_OK) { MessageBox.Show("Не могу открыть прибор (error " + ftStatus.ToString() + ")", "Соединение", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ftStatus = myFtdiDevice.SetTimeouts(100, 100); ftStatus = myFtdiDevice.SetBaudRate(250000); ftStatus = myFtdiDevice.SetDataCharacteristics(FTDI.FT_DATA_BITS.FT_BITS_8, FTDI.FT_STOP_BITS.FT_STOP_BITS_2, FTDI.FT_PARITY.FT_PARITY_NONE); //ftStatus = myFtdiDevice.Purge(FTDI.FT_PURGE.FT_PURGE_RX); myFtdiDevice.SetDTR(false); myFtdiDevice.SetRTS(false); const UInt32 numBytesToRead = 1; UInt32 numBytesAvailable = 0; UInt32 numBytesRead = 0; // MessageBox.Show("Соеденились с прибором: " + ftdiDeviceList[ind].SerialNumber.ToString(), "Соединение", MessageBoxButtons.OK, MessageBoxIcon.Information); // Чтение даты UInt32 NumBytesWriten = 8; // Читаем размер журнала writeFTDI[0] = 0x80; writeFTDI[1] = 0xD2; writeFTDI[2] = 0x00; writeFTDI[3] = 0x00; writeFTDI[4] = 0x00; writeFTDI[5] = 0x00; writeFTDI[6] = 0x00; writeFTDI[7] = (byte)(writeFTDI[1] ^ writeFTDI[2] ^ writeFTDI[3] ^ writeFTDI[4] ^ writeFTDI[5] ^ writeFTDI[6] ^ writeFTDI[7] ^ writeFTDI[0]); ftStatus = myFtdiDevice.Write(writeFTDI, 8,ref NumBytesWriten); System.Threading.Thread.Sleep(100); // Wait until the desired number of bytes have been received. numBytesAvailable = 0; while (numBytesAvailable < numBytesToRead) { ftStatus = myFtdiDevice.GetRxBytesAvailable(ref numBytesAvailable); } numBytesRead = 0; byte[] buffer = new byte[numBytesAvailable]; ftStatus = myFtdiDevice.Read(buffer, numBytesAvailable, ref numBytesRead); myFtdiDevice.Purge(FTDI.FT_PURGE.FT_PURGE_TX); System.Threading.Thread.Sleep(100); int timestamp = ret(buffer[3], buffer[4], buffer[5], buffer[6]) + 10800; string date = (new DateTime(2010, 1, 1, 0, 0, 0, 0)).AddSeconds(timestamp).ToString("dd/MM/yyyy HH:mm:ss"); label1.Text = "Текущая дата прибора " + date; System.Threading.Thread.Sleep(100); 

The following read-write no longer works. Data goes to port, but nothing comes

  // Читаем размер журнала writeFTDI[0] = 0x80; writeFTDI[1] = 0xD5; writeFTDI[2] = 0x00; writeFTDI[3] = 0x00; writeFTDI[4] = 0x00; writeFTDI[5] = 0x00; writeFTDI[6] = 0x00; writeFTDI[7] = (byte)(writeFTDI[1] ^ writeFTDI[2] ^ writeFTDI[3] ^ writeFTDI[4] ^ writeFTDI[5] ^ writeFTDI[6] ^ writeFTDI[7] ^ writeFTDI[0]); ftStatus = myFtdiDevice.Write(writeFTDI, 8, ref NumBytesWriten); myFtdiDevice.Purge(FTDI.FT_PURGE.FT_PURGE_RX); System.Threading.Thread.Sleep(100); // Wait until the desired number of bytes have been received. numBytesAvailable = 0; while (numBytesAvailable < numBytesToRead) { ftStatus = myFtdiDevice.GetRxBytesAvailable(ref numBytesAvailable); } buffer = new byte[numBytesAvailable]; numBytesRead = 0; buffer = new byte[numBytesAvailable]; // Note that the Read method is overloaded, so can read string or byte array data ftStatus = myFtdiDevice.Read(buffer, numBytesAvailable, ref numBytesRead); System.Threading.Thread.Sleep(100); int k = ret(buffer[3], buffer[4], buffer[5], buffer[6]); label2.Text = k.ToString("X"); myFtdiDevice.Close(); } 

    0