Arduino Delphi Serial Communication With Arduino
BOOL retVal = WriteFile(SP->hSerial, &value, sizeof(value), &bytesSend, NULL); You're writing sizeof(value) bytes to the Arduino. Since value is an int, which is typically 4 bytes in size for PC compilers/processors, when you send 20, what actually gets to the Arduino is 0x00000014. Your processor is apparently little-endian so the order of bytes sent is 0x14, 0x00, 0x00, 0x00. You're reading a single byte in every loop() iteration. Dr Zhivago Ost Download there. Your first sketch worked because you didn't provide any else clause for unrecognized bytes.
The Arduino merely ignored those leading zeros. However, your second sketch handled unknown bytes (such as 0x00) by printing gggg.
Arduino Delphi Serial Communication Tutorial. Modbus Technical Resources. Modbus Technical Resources. Modbus Specifications. Download the current versions of Modbus specifications and implementation guides. The linked sites are. Modbus Organization and we are not responsible for the contents. Battle your friends with these Intelpowered battle bots. These little bots blast each other with squirts of water and detect hits with water sensors lined along. Wire Wikipedia. A Java Ring with embedded i. 1 Wire is a device communications bus system designed by Dallas Semiconductor Corp.
So what you get for every value you send to the Arduino is exactly what you'd expect and what you see in your shell -- the result you want ( openn == 0x14), followed by 3 gibberish results (because of the leading zero bytes). You can fix it by either declaring value as a uint8_t in your CPP code (after including stdint.h) or only reading chunks of 4 bytes on the Arduino and then parsing what you get. The former solution seems more reasonable/reliable.