I have ported our project from Delphi 7 to Delphi 2010. After adding some type casts now my project is running well and all the features work correctly except main functionality of the program which is bound to COM ports and the MSCOMM ActiveX component.
It can read and write from a COM port but it seems something is wrong with that because the device that connected to he port returns error code although it works correctly with same code in Delphi7. In the code you can see below after sending some bytes to the device a byte is sent as checksum. On the other side the device gets the bytes and calculates check sum with same formula if received check sum was equal with calculated check sum device returns "O" as OK else it returns "E" as Error. OutCom
is defined as Olevariant.
OutCom := chr(ord(Fbyte));
Mscomm1.Output := OutCom;
OutCom := chr(ord(Sbyte));
Mscomm1.Output := OutCom;
OutCom := chr(ord(DigitOne));
Mscomm1.Output := OutCom;
OutCom := chr(ord(DigitTwo));
Mscomm1.Output := OutCom;
OutCom := chr(ord(DigitThree));
Mscomm1.Output := OutCom;
SumOfBits := (System_No - 1) + Fbyte + Sbyte + DigitOne + DigitTwo + DigitThree;
CheckSum := ( (SumOfBits mod 256) xor 255 ) + 1;
OutCom := chr(ord(CheckSum));
Mscomm1.Output := OutCom;
OutCom := 'E';
Mscomm1.Output := OutCom;
OutCom := 'N';
Mscomm1.Output := OutCom;
Same code in Delphi 2010 returns different result. I guess that the chr() function returns a different result as Delphi7. If this is true then how can I get the Ascii char of a byte or is there a way to pass a byte to Mscomm without converting to char?