2.10 - Annexe: RS232 protocole with Sentinel
Opening port
Opening COM port is done by configuring port at 115200 bauds, 8 bits, 0 stop bits and no parity.
Here is the delphi code:
Const
TimeOutReadMs = 1000; // Msec
TimeOutWriteMs = 50;
TimeOutWriteMsBlueTooth = 500;
Function CreateCharCOM(NumCom:Byte):String;
begin
if (NumCom<10) then
result:='COM'+IntToStr(NumCom)
else
result:='\\.\COM'+IntToStr(NumCom);
end;
procedure TComObjRs232.OpenCom(NumCom:Integer;OverBlueTooth:Boolean);
Var
ComRequested :String;
DCB :TDCB;
CommTimeouts :TCommTimeouts;
begin
ComNum := NumCom;
ComRequested := CreateCharCOM(NumCom);
Hcom := 0;
// Avec un COM sur BlueTooth, cela peut prendre un peu plus de temps : qq secondes
HCom:=CreateFile(PChar(ComRequested),GENERIC_READ or GENERIC_WRITE,0,Nil,OPEN_EXISTING,0,0);
If (hCom=INVALID_HANDLE_VALUE) then
Raise Exception.create(Format(R_UnableToOpenCOM,[ComNum]));
GetCommState(hCom,DCB);
DCB.baudRate :=115200 ;
DCB.ByteSize :=8 ;
DCB.Parity :=0 ;
DCB.StopBits :=0 ;
SetCommState(hCom,DCB);
SetCommMask (hCom,EV_RXCHAR);
With CommTimeouts do
begin
ReadIntervalTimeout :=0;
ReadTotalTimeoutMultiplier :=0;
ReadTotalTimeoutConstant :=TimeOutReadMs;
WriteTotalTimeoutMultiplier:=0;
If OverBlueTooth then
WriteTotalTimeoutConstant :=TimeOutWriteMsBlueTooth
// Plus lent c'est plus sage...
else
WriteTotalTimeoutConstant :=TimeOutWriteMs;
end;
SetCommTimeouts(hCom,CommTimeouts);
If OverBlueTooth then Sleep(1000);
// laisse un peu de temps, sinon, la prochaine commande
// rs232 retournera une erreur.
end;
Sentinel – User Guide (Français / English) – DC0011C
52 / 61