Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.05.16;
Скачать: CL | DM;

Вниз

Проблема с записью в порт   Найти похожие ветки 

 
_san_   (2004-03-19 12:40) [0]

Добрый день!
Я записываю в Com-порт информацию функцией:
   if Not WriteFile( CommHandle, Transmit, dwWritten, written, @Ovr) then
   begin
     dwError := GetLastError;
    …
в win 98 все работает нормально, а вот когда пробую запись в win2000, то почему то функция WriteFile  говорит, что записано 0 байт (written = 0), хотя сами данные до устройства доходят.
В чем тут дело?


 
Reindeer Moss Eater ©   (2004-03-19 14:31) [1]

В том, что так и должно быть при асинхронных операциях.
Ты же асинхронный ввод/вывод используешь.


 
_san_   (2004-03-25 10:14) [2]

Асинхронный режим – это если я открыл файл (CreateFile) c флагом FILE_FLAG_OVERLAPPED.
А если я открою файл без этого флага – в каком режиме тогда я буду работать с Com-портом.


 
Digitman ©   (2004-03-25 10:20) [3]

If hFile was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the write operation starts at the offset specified in the OVERLAPPED structure and WriteFile may return before the write operation has been completed. In this case, WriteFile returns FALSE and the GetLastError function returns ERROR_IO_PENDING. This allows the calling process to continue processing while the write operation is being completed. The event specified in the OVERLAPPED structure is set to the signaled state upon completion of the write operation.

If hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the write operation starts at the current file position and WriteFile does not return until the operation has been completed.
If hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the write operation starts at the offset specified in the OVERLAPPED structure and WriteFile does not return until the write operation has been completed.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.


 
_san_   (2004-03-25 14:32) [4]

У меня еще вопрос.
Если у меня внешнее устройство по какой-либо причине перестает отвечать (зависло или даже просто выключено) то мое приложение намертво виснет на функции чтения или записи. Попробовал перенести их в отдельные потоки – вообще все перестало работать (и запись и чтение).
Как с этим бороться?


 
Reindeer Moss Eater ©   (2004-03-25 16:33) [5]

SetCommTimeouts



Страницы: 1 вся ветка

Текущий архив: 2004.05.16;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.07 c
14-1082613364
dreams
2004-04-22 09:56
2004.05.16
Как из delphi выцепить компилятор ?


1-1083017788
sensor
2004-04-27 02:16
2004.05.16
Проблема с PopupMenu.items.Delete


1-1083426724
student87
2004-05-01 19:52
2004.05.16
Как обоити в цикле несколько компанентов?


8-1076828761
Cash
2004-02-15 10:06
2004.05.16
? *.xm ?


7-1080732327
Fiend
2004-03-31 15:25
2004.05.16
Импорт функции из .exe