Главная страница
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.48 MB
Время: 0.027 c
4-1080683067
tux
2004-03-31 01:44
2004.05.16
Как получить информацию из консоли?


1-1083321302
Relaxxx
2004-04-30 14:35
2004.05.16
Нужно чтобы сумма преобразовывалась в определенную форму


6-1079982504
3APA3A
2004-03-22 22:08
2004.05.16
Несколько подключений к одному IP:Port...


6-1080403814
Ivolg
2004-03-27 19:10
2004.05.16
Разговор по микрофону


3-1082637652
iat
2004-04-22 16:40
2004.05.16
Как узнать номер столбца в DBGrid е при ДВОЙНОМ клике