Главная страница
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.028 c
7-1080883044
СержК
2004-04-02 09:17
2004.05.16
Как програмно поменять системное время


14-1082743778
able
2004-04-23 22:09
2004.05.16
Вопросы по сетям...


6-1080640211
Ozone
2004-03-30 13:50
2004.05.16
ping


14-1082697943
SergP
2004-04-23 09:25
2004.05.16
Посоветуйте прогу для создания патчей.


1-1083071073
Alexus12
2004-04-27 17:04
2004.05.16
класс и динамический массив