Recent

Author Topic: [SOLVED] How to work with synapse (Serial Communication)  (Read 664 times)

Nera

  • Newbie
  • Posts: 4
[SOLVED] How to work with synapse (Serial Communication)
« on: December 03, 2019, 03:47:09 pm »
Code: Pascal  [Select]
  1. {
  2. Good morning people.
  3. I can't make a serial communication with synapse. Below I demonstrate what worked.
  4. Always send $ AA.
  5. }
  6.  
  7.  
  8.  
  9.  
  10. function TSerial.kernelSerial(comando : Ansistring; TotalReturn:LongInt):Ansistring;
  11. var
  12.   Buffer_In  : array[0..TXBUFFERSIZE] of byte;
  13.   Buffer_Out : array[0..TXBUFFERSIZE] of byte;
  14.   pnt : ^byte;
  15.   SizeBufferSend:QWord;
  16.  
  17. begin
  18.       comando:='AABBC00021020064';
  19.       SizeBufferSend:=(length(comando) div 2);
  20.        for i:=0 to  SizeBufferSend-1 do
  21.             begin
  22.                  Buffer_Out[i] := $AA;
  23.             end;
  24.        pnt:=Buffer_Out;
  25.  
  26.        SendBuffer(pnt,SizeBufferSend);
  27.  
  28.        pnt:=Buffer_In;
  29.          
  30.        RecvBuffer(pnt,TotalReturn);                                  
  31.  
  32. end;
  33.  
  34.  
  35.  
  36. //----------------------------------------------------------------------------------------------------------------
  37. This code does not work. Always sends 0 (Zero).
  38.  
  39. function TSerial.kernelSerial(comando : Ansistring; TotalReturn:LongInt):Ansistring;
  40. var
  41.   Buffer_In  : array[0..TXBUFFERSIZE] of byte;
  42.   Buffer_Out : array[0..TXBUFFERSIZE] of byte;
  43.   pnt : ^byte;
  44.   SizeBufferSend:QWord;
  45. begin
  46.       comando:='AABBC00021020064';
  47.       SizeBufferSend:=(length(comando) div 2);
  48.        for i:=0 to  SizeBufferSend-1 do
  49.             begin
  50.                  Buffer_Out[i] := HextoInt('$'+copy(comando,1,2));
  51.             end;
  52.        pnt:=Buffer_Out;
  53.  
  54.        SendBuffer(pnt,SizeBufferSend);
  55.  
  56.        pnt:=Buffer_In;
  57.          
  58.        RecvBuffer(pnt,TotalReturn);                                  
  59.  
  60. end;
  61.  
  62.  
  63. {
  64. Do you have any suggestions on this question? Thanks.
  65. }
  66.  

« Last Edit: December 04, 2019, 09:44:23 am by Nera »

lucamar

  • Hero Member
  • *****
  • Posts: 2147
Re: How to work with synapse (Serial Communication)
« Reply #1 on: December 03, 2019, 04:50:06 pm »
I can't make a serial communication with synapse. Below I demonstrate what worked.
Always send $ AA.

No wonder; you're filling the whole buffer with $AA, what did you expect it to send?

Code: Pascal  [Select]
  1. for i:=0 to  SizeBufferSend-1 do
  2. begin
  3.     Buffer_Out[i] := $AA; {<-- The bufer ends up choked full of $AA's }
  4. end;

Or have I misunderstood you and that was as intended?

In the second function, have you tried converting the hex-string without adding the '$'? And shouldn't you traverse the comando string rather than always copying the first "byte"? As in:
Code: Pascal  [Select]
  1. {Instead of:
  2.     Buffer_Out[i] := HextoInt('$'+copy(comando,1,2));
  3. Try with: }
  4.     Buffer_Out[i] := HextoInt(copy(comando, i*2, 2));

BTW, where does HextoInt come from? I couldn't find it in the help files :-[
« Last Edit: December 03, 2019, 05:01:29 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 600
Re: How to work with synapse (Serial Communication)
« Reply #2 on: December 03, 2019, 05:18:49 pm »
Hi!

HexToInt must be home grown.

You reach the same with str or StrToInt with the right prefix.

I only know Hex2Dec from the StrUtils.

Winni

« Last Edit: December 03, 2019, 05:25:30 pm by winni »

lucamar

  • Hero Member
  • *****
  • Posts: 2147
Re: How to work with synapse (Serial Communication)
« Reply #3 on: December 03, 2019, 05:38:19 pm »
I only know Hex2Dec from the StrUtils.

And, of course, HexToBin (in either StrUtils or Classes), which does in one call the same the OP is trying to do in his loops ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

Nera

  • Newbie
  • Posts: 4
Re: How to work with synapse (Serial Communication)
« Reply #4 on: December 03, 2019, 06:04:53 pm »
I can't make a serial communication with synapse. Below I demonstrate what worked.
Always send $ AA.

No wonder; you're filling the whole buffer with $AA, what did you expect it to send?

Code: Pascal  [Select]
  1. for i:=0 to  SizeBufferSend-1 do
  2. begin
  3.     Buffer_Out[i] := $AA; {<-- The bufer ends up choked full of $AA's }
  4. end;

Or have I misunderstood you and that was as intended?

In the second function, have you tried converting the hex-string without adding the '$'? And shouldn't you traverse the comando string rather than always copying the first "byte"? As in:
Code: Pascal  [Select]
  1. {Instead of:
  2.     Buffer_Out[i] := HextoInt('$'+copy(comando,1,2));
  3. Try with: }
  4.     Buffer_Out[i] := HextoInt(copy(comando, i*2, 2));

BTW, where does HextoInt come from? I couldn't find it in the help files :-[

I expected it to fill the buffer with $ AA (170), but it only shows 0 (zero). The question of fill logic is no problem for me, the important thing is that it fills with $ AA, then I get the logic right.

I managed to make it work with the winni tip. So I tested the logic and it looked like this:

Code: Pascal  [Select]
  1. Buffer_Out[i] :=Hex2Dec('$'+copy(comando,(i*2)+1,2));
               




Nera

  • Newbie
  • Posts: 4
Re: How to work with synapse (Serial Communication)
« Reply #5 on: December 03, 2019, 06:07:28 pm »
Hi!

HexToInt must be home grown.

You reach the same with str or StrToInt with the right prefix.

I only know Hex2Dec from the StrUtils.

Winni

Thanks winni, your tip worked.

Nera

  • Newbie
  • Posts: 4
Re: How to work with synapse (Serial Communication)
« Reply #6 on: December 03, 2019, 06:10:36 pm »
Please, Where do I indicate that the issue has been resolved?

lucamar

  • Hero Member
  • *****
  • Posts: 2147
Re: How to work with synapse (Serial Communication)
« Reply #7 on: December 03, 2019, 06:41:10 pm »
See here: Forum: Mark a thread as resolved  :)

Incidentally, I'd use HexToBin() rather than loop calling Hex2Dec(). But if it works for you, that's OK too.
« Last Edit: December 03, 2019, 06:45:34 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.