Home » Developing U++ » UppHub » RS232 class
RS232 class [message #22519] |
Tue, 21 July 2009 17:02 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
I`m presenting second part from the latest software. It's RS232 and RS232Protocol classes. Currently they are Windows-only, but it should be simple to add POSIX support for those who has any experience with it.
RS232Protocol class proved itself convenient way organizing any real-life exchange with external devices. It uses U++ style of definitions.
So, let's look how to use it. Let's imagine situation where you have external device with protocol like:
(request) 00AACCDD##
(answer) AA00****##
where
AA = device address (1 byte)
CC = command number (1 BYTE)
DD = some command data
00 = 0x00
** = 1 byte of answer data
## = CRC, simple 8-bit bytes composition
The address of device is addr, command is cmd.
//byte addr;
//byte cmd;
//byte dataR;
//dword ANSWER_TIMEOUT = 500;
RS232 rs232;
RS232Protocol proto1R, proto1A;
proto1R(0x00)(addr)(cmd)(dataR).CRC();
proto1A(addr)(0x00).Word().CRC();
if (!rs232.Open(1)) //COM1
return;
proto1R.Send(rs232);
if (proto1A.Receive(rs232, ANSWER_TIMEOUT))
{
word answerData = proto1A[2];
//...
}
rs232.Close();
Of course it's the simplest example, just to understand the idea.
-
Attachment: RS232.h
(Size: 9.20KB, Downloaded 479 times)
[Updated on: Tue, 21 July 2009 17:03] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu May 01 15:57:51 CEST 2025
Total time taken to generate the page: 0.02366 seconds
|