VCL
(i) How to use TnrComm component on delphi
Think Hub
2019. 8. 20. 15:52
-----------------------------------------------------------------
// COM 열기 참고 코드
-----------------------------------------------------------------
nrComm: TnrComm;
nrComm.Active := False;
nrComm.ComPortNo := m_cs.nPort;
nrComm.BaudRate := m_cs.nBaud; //110 ~ 256000
nrComm.ByteSize := m_cs.nDataBit;
nrComm.Parity := TParity( m_cs.nParity );
nrComm.StopBits := TStopBits( m_cs.nStopBit );
nrComm.StreamProtocol := spNone;
nrComm.SetStateDTR( True );
nrComm.SetStateRTS( True );
nrComm.Active := True;
-----------------------------------------------------------------
// 쓰기 참고 코드
-----------------------------------------------------------------
var
nLen : Integer;
sendBuf : Array Of AnsiChar;
begin
nLen := 6;
Setlength( sendBuf, nLen );
sendBuf[0] := 'R';
sendBuf[1] := 'E';
sendBuf[2] := 'A';
sendBuf[3] := 'D';
sendBuf[4] := #$0D;
sendBuf[5] := #$0A;
nrComm.SendData( @sendBuf[0], nLen );
end;
-----------------------------------------------------------------
// 읽기 참고 코드
-----------------------------------------------------------------
procedure TfrmComm.nrCommAfterReceive( Com: TObject;
Buffer: Pointer;
Received: Cardinal );
var
I : Integer;
nLen : Integer;
sendBuf : Array Of AnsiChar;
begin
if( Received < 1 ) then
begin
Exit;
end;
for i := 0 to Received-1 do
begin
m_asBuf := m_asBuf + PAnsiChar(Buffer)[i];
nLen := Length( m_asBuf );
if( (m_asBuf[nLen-1] = #13 ) and
(m_asBuf[nLen-0] = #10 ) ) then
begin
// To Do Something..
//m_dicIndicator.Add( GetKeyCount(), m_asBuf );
mmoCOMM.Lines.Add( m_asBuf );
m_asBuf := '';
end;
end;
end;