Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2004.05.16;
Скачать: [xml.tar.bz2];

Вниз

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

 
_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 вся ветка

Форум: "WinAPI";
Текущий архив: 2004.05.16;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.037 c
3-1082058087
mur
2004-04-15 23:41
2004.05.16
вместо букв - закорючки


3-1082543669
avgur
2004-04-21 14:34
2004.05.16
Вопрос о истории значеий


8-1076917402
Petro
2004-02-16 10:43
2004.05.16
Как нанести условн.знаки на полигон?Векторная карта на DC, ...


1-1083409196
Lexius
2004-05-01 14:59
2004.05.16
Запись иконок в файл


7-1081362670
_newver_
2004-04-07 22:31
2004.05.16
как програмно узнать какие программы запущены ....





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский