• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Detect reply from scale (pos) [nrDataProcessor component, C++Builder]

Started by Roman Novgorodov, December 02, 2011, 10:28:05 am

Previous topic - Next topic

Roman Novgorodov

User asks:
Quote
If I communicate through serial port with our scales, the message has a defined form:  <STX>m<ETX>l

<STX> : 0x02
m: letter m
<ETX> : 0x03
l: letter l, which is a checksum (XOR over all previous characters)

    The answer from the scale has a similar structure, but the content and the length of the message  may be  different each time: <STX> data<ETX>[cs]

data: number of kilograms
[cs]: checksum
 
    Here's a question: if I use DataProcessor and there a Packet, how can I set the conditions to get a complete message into a packet (including checksum). In Async Professional I could use a question mark '?' for a wild card. Do you have a solution for this case? In your documentation I could only find the cases for setting packet header and packet end for variable length. In this case I could do the same, but I wouldn't get a checksum in a packet?


Hello

We have modified standard sample project Demos\DataProcBCB for your
conditions.

You can see sources in attachment or try compiled demo here:
http://deepsoftware.com/download/dataproc_exe_STX.zip

You can see some comments in sources I hope it helps.
TnrDataProcessor does not support '?' char (like APro), but it
provides OnPacketLength event for variable length packets.

Most important part of code is following:


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// overwrite design time settings of packet:
nrDataProcessor1->DataPackets->Items[0]->PacketBegin = "\x02"; // STX
}

void __fastcall TForm1::nrDataProcessor1DataPackets0PacketLength(TnrDataPacket *Packet,
  BYTE chData, bool &IsHandled)
{
// this handler can be used for detect real length of current packet
if(IsHandled = (chData == 0x03))
Packet->PacketLength = Packet->DataLength + 1;
}


Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.