救救我!操作串口怎么这样不行,那位能帮忙看一下,代码如下,谢谢!出现的错误为error handle! (200分)

  • 主题发起人 主题发起人 shangxuan
  • 开始时间 开始时间
S

shangxuan

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;hNewCommFile,hCommFile: &nbsp; THandle;<br>&nbsp; &nbsp;commtimeouts: &nbsp; TCommTimeouts;<br>&nbsp; &nbsp;dcb: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Tdcb;<br>&nbsp; &nbsp;commprop: &nbsp; &nbsp; &nbsp; TCommProp;<br>&nbsp; &nbsp;fdwEvtMask: &nbsp; &nbsp; DWORD;<br>&nbsp; &nbsp;pDataToWrite: &nbsp; PChar;<br>&nbsp; &nbsp;dwNumberOfBytesWritten,dwNumberOfBytesToWrite:Dword;<br>&nbsp; &nbsp;lpOverlappedWrite: POverlapped;<br>begin<br>&nbsp; &nbsp; &nbsp;hNewCommFile := CreateFile( 'com1',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ or GENERIC_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp;);<br><br>&nbsp; &nbsp; &nbsp;if hNewCommFile = INVALID_HANDLE_VALUE then<br>&nbsp; &nbsp; &nbsp; &nbsp; raise ECommsError.Create( 'Error opening serial port' );<br><br>&nbsp; &nbsp; &nbsp;// Is this a valid comm handle?<br>&nbsp; &nbsp; &nbsp;if GetFileType( hNewCommFile ) &lt;&gt; FILE_TYPE_CHAR then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle( hNewCommFile );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise ECommsError.Create( 'File handle is not a comm handle ' )<br>&nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp; &nbsp;if not SetupComm( hNewCommFile, 4096, 4096 ) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle( hNewCommFile );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise ECommsError.Create( 'Cannot setup comm buffer' )<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;// purge any information in the buffer<br><br>&nbsp; &nbsp; &nbsp;PurgeComm( hNewCommFile, PURGE_TXABORT or PURGE_RXABORT or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PURGE_TXCLEAR or PURGE_RXCLEAR ) ;<br><br><br><br>&nbsp; &nbsp; GetCommTimeouts( hNewCommFile, commtimeouts );<br><br>&nbsp; &nbsp; &nbsp;// The CommTimeout numbers will very likely change if you are<br>&nbsp; &nbsp; &nbsp;// coding to meet some kind of specification where<br>&nbsp; &nbsp; &nbsp;// you need to reply within a certain amount of time after<br>&nbsp; &nbsp; &nbsp;// recieving the last byte. &nbsp;However, &nbsp;If 1/4th of a second<br>&nbsp; &nbsp; &nbsp;// goes by between recieving two characters, its a good<br>&nbsp; &nbsp; &nbsp;// indication that the transmitting end has finished, even<br>&nbsp; &nbsp; &nbsp;// assuming a 1200 baud modem.<br><br>&nbsp; &nbsp; &nbsp;commtimeouts.ReadIntervalTimeout &nbsp; &nbsp; &nbsp; &nbsp; := 100;<br>&nbsp; &nbsp; &nbsp;commtimeouts.ReadTotalTimeoutMultiplier &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp;commtimeouts.ReadTotalTimeoutConstant &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp;commtimeouts.WriteTotalTimeoutMultiplier := 0;<br>&nbsp; &nbsp; &nbsp;commtimeouts.WriteTotalTimeoutConstant &nbsp; := 0;<br><br>&nbsp; &nbsp; &nbsp;SetCommTimeouts( hNewCommFile, commtimeouts );<br><br>&nbsp; &nbsp; GetCommState( hNewCommFile, dcb );<br>&nbsp; &nbsp; GetCommProperties(hNewCommFile, commprop );<br>&nbsp; &nbsp; GetCommMask(hNewCommFile, fdwEvtMask );<br>&nbsp;dcb.BaudRate := 9600;<br>&nbsp;dcb.Flags := 1;<br>&nbsp;dcb.Parity :=NOPARITY;<br>&nbsp;Dcb.ByteSize :=8;<br>&nbsp;dcb.StopBits :=ONESTOPBIT;<br>&nbsp;SetCommMask(hNewCommFile,EV_ERR or EV_RXCHAR);<br>&nbsp;SetCommState(hNewCommFile,Dcb);<br>&nbsp;hCommFile:=hNewCommFile;<br><br><br>&nbsp;pDataToWrite:='dsfasf';<br>&nbsp;dwNumberOfBytesToWrite:=strlen(pDataToWrite);<br>&nbsp;dwNumberOfBytesWritten:=5;<br>&nbsp;//出现错误,查询到的错误是error handle;<br>&nbsp;if not WriteFile(hCommFile,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pDataToWrite,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwNumberOfBytesToWrite, dwNumberOfBytesWritten,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpOverlappedWrite ) then<br>&nbsp;showMessage(inttostr(getlasterror()));<br>//下面我要查询事件有数据收到<br>//然后再读串口<br>//然后再写串口......<br><br>end;<br>
 
我这有一个资料,你参看一下??<br>unit frmComm;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, ComCtrls, shellapi;<br><br>const MAXBLOCK = 160;<br><br>type<br>&nbsp; TComm = record<br>&nbsp; &nbsp; idComDev: THandle;<br>&nbsp; &nbsp; fConnected: Boolean;<br>&nbsp; end;<br><br>&nbsp; TCommForm = class(TForm)<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; StatusBar1: TStatusBar;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>&nbsp; TCommThread = class(TThread)<br>&nbsp; protected<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create;<br>&nbsp; end;<br><br>var<br>&nbsp; CommForm: TCommForm;<br>&nbsp; CommHandle: THandle;<br>&nbsp; Connected: Boolean;<br>&nbsp; CommThread: TCommThread;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TCommThread.Execute;<br>var<br>&nbsp; dwErrorFlags, dwLength: DWORD;<br>&nbsp; ComStat: PComStat;<br>&nbsp; fReadStat: Boolean;<br>&nbsp; InChar: Char;<br>&nbsp; AbIn: string;<br>&nbsp; XX, YY: double; //file; //经度、纬度<br>&nbsp; VID: string; //file: //车号<br>begin<br>&nbsp; while Connected do<br>&nbsp; begin<br>&nbsp; &nbsp; GetMem(ComStat, SizeOf(TComStat));<br>&nbsp; &nbsp; ClearCommError(CommHandle, dwErrorFlags, ComStat);<br>&nbsp; &nbsp; if (dwErrorFlags &gt; 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; PurgeComm(CommHandle, (PURGE_RXABORT and PURGE_RXCLEAR));<br>&nbsp; &nbsp; &nbsp; // return 0;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; dwLength := ComStat.cbInQue;<br>&nbsp; &nbsp; if (dwLength &gt; 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; fReadStat := ReadFile(CommHandle, InChar, 1, dwLength, nil);<br>&nbsp; &nbsp; &nbsp; if (fReadStat) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if (InChar &lt;&gt; Chr(13)) and (Length(abIn) &lt; MAXBLOCK + 5) then AbIn := AbIn + InChar<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //...{接收完毕,}<br>&nbsp; &nbsp; &nbsp; &nbsp; end; //if (fReadStat&gt;0){<br>&nbsp; &nbsp; &nbsp; end; //file: //if (dwLength&gt;0){<br>&nbsp; &nbsp; &nbsp; FreeMem(ComStat);<br>&nbsp; &nbsp; end; {while}<br>&nbsp; end;<br>end;<br><br>constructor TCommThread.Create;<br>begin<br>&nbsp; FreeOnTerminate := TRUE;<br>&nbsp; inherited Create(FALSE); //file: //Createsuspended = false<br>end;<br><br>procedure TCommForm.Button1Click(Sender: TObject);<br>var<br>&nbsp; CommTimeOut: TCOMMTIMEOUTS;<br>&nbsp; DCB: TDCB;<br>&nbsp; fRetVal: Boolean;<br>begin<br>&nbsp; StatusBar1.SimpleText := '连接中...';<br>&nbsp; CommHandle := CreateFile(PChar(ComboBox1.Text), GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL<br>&nbsp; &nbsp; , 0);<br>&nbsp; if CommHandle = INVALID_HANDLE_VALUE then begin<br>&nbsp; &nbsp; StatusBar1.SimpleText := '连接失败';<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; StatusBar1.SimpleText := '已同端口' + ComboBox1.Text + '连接!';<br>&nbsp; CommTimeOut.ReadIntervalTimeout := MAXDWORD;<br>&nbsp; CommTimeOut.ReadTotalTimeoutMultiplier := 0;<br>&nbsp; CommTimeOut.ReadTotalTimeoutConstant := 0;<br>&nbsp; SetCommTimeouts(CommHandle, CommTimeOut);<br>&nbsp; GetCommState(CommHandle, DCB);<br>&nbsp; DCB.BaudRate := 9600;<br>&nbsp; DCB.ByteSize := 8;<br>&nbsp; DCB.Parity := NOPARITY;<br>&nbsp; DCB.StopBits := ONESTOPBIT;<br>&nbsp; fRetVal := SetCommState(CommHandle, DCB);<br>&nbsp; if (fRetVal) then<br>&nbsp; begin<br>&nbsp; &nbsp; Connected := TRUE;<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; CommThread := TCommThread.Create;<br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; Connected := FALSE;<br>&nbsp; &nbsp; &nbsp; CloseHandle(CommHandle);<br>&nbsp; &nbsp; &nbsp; fRetVal := FALSE;<br>&nbsp; &nbsp; &nbsp; StatusBar1.SimpleText := '线程建立失败';<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; Connected := FALSE;<br>&nbsp; &nbsp; CloseHandle(CommHandle);<br>&nbsp; end;<br>end;<br><br>procedure TCommForm.Button2Click(Sender: TObject);<br>begin<br>&nbsp; if Connected then<br>&nbsp; begin<br>&nbsp; &nbsp; Connected := FALSE;<br>&nbsp; &nbsp; CloseHandle(CommHandle); {终止线程}<br>&nbsp; &nbsp; CommThread.Terminate;<br>&nbsp; &nbsp; StatusBar1.SimpleText := '关闭端口' + ComboBox1.Text;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; StatusBar1.SimpleText := '已关闭端口' + ComboBox1.Text;<br>end;<br><br>procedure TCommForm.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; if Connected then<br>&nbsp; begin<br>&nbsp; &nbsp; Connected := FALSE;<br>&nbsp; &nbsp; CloseHandle(CommHandle);<br>&nbsp; &nbsp; CommThread.Terminate;<br>&nbsp; &nbsp; StatusBar1.SimpleText := '关闭端口' + ComboBox1.Text;<br>&nbsp; end;<br>end;<br><br>end.<br>
 
唉!<br>activeX中的mscomm就可以简单搞定!<br>
 
SPCOMM是有这样的问题,会出现File Hanlde is not COM Handle,你将com1大写试试<br>或者干脆改成:MSCOMM 或 TApdComPort 吧<br>TApdComport不错,功能比SPCOMM强大<br>
 
//现在出现的问题是当没有数据发回串口时会出现程序死锁,请帮忙看看!<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;hNewCommFile,hCommFile: &nbsp; THandle;<br>&nbsp; &nbsp;commtimeouts: &nbsp; TCommTimeouts;<br>&nbsp; &nbsp;dcb: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Tdcb;<br>&nbsp; &nbsp;commprop: &nbsp; &nbsp; &nbsp; TCommProp;<br>&nbsp; &nbsp;fdwEvtMask: &nbsp; &nbsp; DWORD;<br>&nbsp; &nbsp;pDataToWrite: &nbsp; PChar;<br>&nbsp; &nbsp;dwNumberOfBytesWritten,dwNumberOfBytesToWrite,lpnNumberOfBytesRead:Dword;<br>&nbsp; &nbsp;lpOverlappedWrite: POverlapped;<br>&nbsp; &nbsp; buffer:array[0..20] of byte;<br>begin<br>&nbsp; &nbsp; &nbsp;hNewCommFile := CreateFile( 'com1',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ or GENERIC_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp;);<br><br>&nbsp; &nbsp; &nbsp;if hNewCommFile = INVALID_HANDLE_VALUE then<br>&nbsp; &nbsp; &nbsp; &nbsp; raise ECommsError.Create( 'Error opening serial port' );<br><br>&nbsp; &nbsp; &nbsp;// Is this a valid comm handle?<br>&nbsp; &nbsp; &nbsp;if GetFileType( hNewCommFile ) &lt;&gt; FILE_TYPE_CHAR then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle( hNewCommFile );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise ECommsError.Create( 'File handle is not a comm handle ' )<br>&nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp; &nbsp;if not SetupComm( hNewCommFile, 4096, 4096 ) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle( hNewCommFile );<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise ECommsError.Create( 'Cannot setup comm buffer' )<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;// purge any information in the buffer<br><br>&nbsp; &nbsp; &nbsp;PurgeComm( hNewCommFile, PURGE_TXABORT or PURGE_RXABORT or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PURGE_TXCLEAR or PURGE_RXCLEAR ) ;<br><br><br><br>&nbsp; &nbsp; GetCommTimeouts( hNewCommFile, commtimeouts );<br><br>&nbsp; &nbsp; &nbsp;// The CommTimeout numbers will very likely change if you are<br>&nbsp; &nbsp; &nbsp;// coding to meet some kind of specification where<br>&nbsp; &nbsp; &nbsp;// you need to reply within a certain amount of time after<br>&nbsp; &nbsp; &nbsp;// recieving the last byte. &nbsp;However, &nbsp;If 1/4th of a second<br>&nbsp; &nbsp; &nbsp;// goes by between recieving two characters, its a good<br>&nbsp; &nbsp; &nbsp;// indication that the transmitting end has finished, even<br>&nbsp; &nbsp; &nbsp;// assuming a 1200 baud modem.<br><br>&nbsp; &nbsp; &nbsp;commtimeouts.ReadIntervalTimeout &nbsp; &nbsp; &nbsp; &nbsp; := 100;<br>&nbsp; &nbsp; &nbsp;commtimeouts.ReadTotalTimeoutMultiplier &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp;commtimeouts.ReadTotalTimeoutConstant &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp;commtimeouts.WriteTotalTimeoutMultiplier := 0;<br>&nbsp; &nbsp; &nbsp;commtimeouts.WriteTotalTimeoutConstant &nbsp; := 0;<br><br>&nbsp; &nbsp; &nbsp;SetCommTimeouts( hNewCommFile, commtimeouts );<br><br>&nbsp; &nbsp; GetCommState( hNewCommFile, dcb );<br>&nbsp; &nbsp; GetCommProperties(hNewCommFile, commprop );<br>&nbsp; &nbsp; GetCommMask(hNewCommFile, fdwEvtMask );<br>&nbsp;dcb.BaudRate := 9600;<br>&nbsp;dcb.Flags := 1;<br>&nbsp;dcb.Parity :=NOPARITY;<br>&nbsp;Dcb.ByteSize :=8;<br>&nbsp;dcb.StopBits :=ONESTOPBIT;<br>&nbsp;SetCommMask(hNewCommFile,EV_ERR or EV_RXCHAR);<br>&nbsp;SetCommState(hNewCommFile,Dcb);<br>&nbsp;hCommFile:=hNewCommFile;<br><br><br>&nbsp;pDataToWrite:='dsfasf';<br>&nbsp;dwNumberOfBytesToWrite:=strlen(pDataToWrite);<br>&nbsp;dwNumberOfBytesWritten:=5;<br>&nbsp;//出现错误,查询到的错误是error handle;<br>&nbsp;if not WriteFile(hCommFile,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pDataToWrite,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dwNumberOfBytesToWrite, dwNumberOfBytesWritten,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 ) then<br>&nbsp;showMessage(inttostr(getlasterror()));<br><br>//然后再读串口<br>&nbsp; ReadFile( hCommFile,buffer<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , 20,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpnNumberOfBytesRead, 0 );<br>//现在出现的问题是当没有数据发回串口时会出现程序死锁,请帮忙看看!<br>//然后再写串口......<br><br>end;<br><br>
 
不知在 &nbsp; &nbsp;<br>&nbsp; &nbsp; commtimeouts.ReadIntervalTimeout &nbsp; &nbsp; &nbsp; &nbsp; := 100;<br>&nbsp; &nbsp; commtimeouts.ReadTotalTimeoutMultiplier &nbsp;:= 0;<br>&nbsp; &nbsp; commtimeouts.ReadTotalTimeoutConstant &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; commtimeouts.WriteTotalTimeoutMultiplier := 0;<br>&nbsp; &nbsp; commtimeouts.WriteTotalTimeoutConstant &nbsp; := 0;<br><br>改成<br>&nbsp; &nbsp; commtimeouts.ReadIntervalTimeout &nbsp; &nbsp; &nbsp; &nbsp; := 100;<br>&nbsp; &nbsp; commtimeouts.ReadTotalTimeoutMultiplier &nbsp;:= 0;<br>&nbsp; &nbsp; commtimeouts.ReadTotalTimeoutConstant &nbsp; &nbsp;:= 20;<br>&nbsp; &nbsp; commtimeouts.WriteTotalTimeoutMultiplier := 0;<br>&nbsp; &nbsp; commtimeouts.WriteTotalTimeoutConstant &nbsp; := 0;<br>还会不会出现死锁!<br>
 
后退
顶部