Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending Byte List
#8
Geez, every time I think I've got it...something doesn't behave like I thought. Indy Sockets so far have already made my life so much cleaner but the closer I get, the further away I seem.

I'm starting with the MicroClient example in Delphi 10.2 Tokyo.
// File : UClient.pas
// Project : MicroServer.dpr
// Easy example of TCP Client with indy component : TidTCPSever
//
// see indy doc: http://www.indyproject.org/sockets/docs/index.en.aspx

I've relegated my receive code to the thread onRun event TFClient.IdThreadComponentRun, otherwise I could use it to receive one series at a time, but they prefer firing them at me so I need to receive full buffers of bytes containing strain gauge data in quick intervals. There will be ~175 gauges, currently I'm testing with 11 copies of the same one. If I read 49 bytes at once for my test case it works fine. When I stopped to read the header first last night I found it triggers the onRun event if there is any more data in the buffer, so then I did an experiment reading one byte at a time and displaying it in the TFClient.IdThreadComponentRun onRun event when it fires and sure enough, this will read the entire buffer perfectly.

That's cool and could maybe be the way to go, but if I do that I don't know when it's finished and I can process the data.

Any way to really know how many bytes have been received in the IOHandler?

When I use SizeOf(RxBuffer) it's always 4 so it does a series of 4 till it's exhausted the incoming buffer. So then I thought OK, I just need to read it all. I'm getting garbage in my Uint16's- this could be an endian issue, I'm not certain yet because I don't program full time. Can I use the HostToLittleEndian function from Indy? I have endian changing routines but if it's 'already in there' why do that. When I read it by bytes I get $0B in the first byte (lines 10&11 below) which is 11 sensors if I decode just that byte.

Here is the series of bytes I receive currently;

1 - A5 Frame Start
2 - F3 255- Payload length = 243
3 - 0C 12, payload size
4 - A3 WEPACKETID_SENSORRESULTSFIRST_RES
5 - 00 zero
6 - CD 205
7 - 00 Status
8 - 00 Num Te mp sensors
9 - 00 Num Temp sensors
10 - 0B 11, corect Num Strain Sensors
11 - 00 Num Strain Sensors
12 - 00 Temp Sensor index
13 - 00 Temp Sensor index
14 - 00 Temp Sensor Result
15 - 00 Temp Sensor Result
16 - 76 CRC
17 - 7A CRC
18 - A5 Frame start
19 - E4 228
20 - 1B 27 checks out
21 - A4 Sensor results others
22 - 00 zero
23 - CD 205
24 - 00 u16StrainSensorIndex
25 - 00 u16StrainSensorIndex
26 - 73 u16Strain result
27 - 17
28 - 74 u16Strain result
29 - 17
30 - 74 u16Strain result
31 - 17
32 - 74 u16Strain result
33 - 17
34 - 74 u16Strain result
35 - 17
36 - 75 u16Strain result
37 - 17
38 - 75 u16Strain result
39 - 17
40 - 77 u16Strain result
41 - 17
42 - 77 u16Strain result
43 - 17
44 - 77 u16Strain result
45 - 17
46 - 76 u16Strain result
47 - 17
48 - DE CRC
49 - B2 CRC

Pretty sure now the garbage part is an endian issue. More later since I have a full time day job too...
Reply


Messages In This Thread
Sending Byte List - by krshin - 08-22-2018, 07:19 PM
RE: Sending Byte List - by rlebeau - 08-22-2018, 08:27 PM
RE: Sending Byte List - by krshin - 08-23-2018, 05:52 AM
RE: Sending Byte List - by rlebeau - 08-23-2018, 10:32 PM
RE: Sending Byte List - by CaptRick - 08-29-2018, 11:43 AM
RE: Sending Byte List - by rlebeau - 08-29-2018, 06:22 PM
RE: Sending Byte List - by CaptRick - 08-29-2018, 10:50 PM
RE: Sending Byte List - by CaptRick - 08-31-2018, 10:38 AM
RE: Sending Byte List - by rlebeau - 08-31-2018, 05:10 PM
RE: Sending Byte List - by CaptRick - 08-31-2018, 09:02 PM
RE: Sending Byte List - by rlebeau - 08-31-2018, 09:35 PM
RE: Sending Byte List - by CaptRick - 08-31-2018, 09:46 PM
RE: Sending Byte List - by CaptRick - 09-01-2018, 12:46 PM
RE: Sending Byte List - by CaptRick - 09-04-2018, 03:35 PM
RE: Sending Byte List - by rlebeau - 09-04-2018, 06:32 PM
RE: Sending Byte List - by kudzu - 09-05-2018, 02:28 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)