Recent

Author Topic: Use tts0, This example is from chatgpt,but why it doesn't work?  (Read 3174 times)

coradi

  • Full Member
  • ***
  • Posts: 197
Use tts0, This example is from chatgpt,but why it doesn't work?
« on: December 03, 2024, 09:50:21 pm »
This example is from chatgpt,but why it doesn't work?
With hterm the LED from CH UART is working, but with this code, nothing happends

Code: Pascal  [Select][+][-]
  1. program uart19200;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   cthreads, SysUtils, synaser;
  7.  
  8. var
  9.   Serial: TBlockSerial;
  10.   ReceivedData: string;
  11. begin
  12.  // WriteLn('Empfangene Daten: ');
  13.   // Serielle Schnittstelle initialisieren
  14.   Serial := TBlockSerial.Create;
  15.   try
  16.     // Serielle Schnittstelle öffnen
  17. Modify message
  18.  
« Last Edit: December 04, 2024, 02:22:42 pm by coradi »
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #1 on: December 04, 2024, 02:18:37 am »
hello,
i don't see in your code init of the serial port.
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Thaddy

  • Hero Member
  • *****
  • Posts: 18786
  • To Europe: simply sell USA bonds: dollar collapses
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #2 on: December 04, 2024, 06:28:12 am »
You need to ask the question more precise:
Code: Pascal  [Select][+][-]
  1. program SerialPortListener;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   cthreads, SysUtils, synaser;
  7.  
  8. var
  9.   Serial: TBlockSerial;
  10.   ReceivedData: string;
  11.  
  12. begin
  13.   // Initialize the serial port
  14.   Serial := TBlockSerial.Create;
  15.   try
  16.     // Set the device to the appropriate serial port (e.g., /dev/ttyS0 or /dev/ttyUSB0)
  17.     Serial.Connect('/dev/ttyS0');
  18.     // Set the baud rate to 19200, 8 data bits, no parity, 1 stop bit
  19.     Serial.Config(19200, 8, 'N', SB1, False, False);
  20.  
  21.     // Loop to read data from the serial port
  22.     while True do
  23.     begin
  24.       // Check if data is available
  25.       if Serial.CanRead(1000) then
  26.       begin
  27.         // Read the data
  28.         ReceivedData := Serial.RecvPacket(1000);
  29.         // Print the received data
  30.         WriteLn('Received: ', ReceivedData);
  31.       end;
  32.     end;
  33.   finally
  34.     // Clean up
  35.     Serial.Free;
  36.   end;
  37. end.
Not my code, chatGPT  :D :D This one works if the synapse library is in the path or the package is installed. (just tested, minimally on /dev/ttyUSB0, the above code is untouched)

Both synaser examples from the wiki also work when you set up the config for your conection:
https://wiki.freepascal.org/Hardware_Access#Serial_Communication
« Last Edit: December 04, 2024, 07:43:07 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

coradi

  • Full Member
  • ***
  • Posts: 197
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #3 on: December 04, 2024, 04:38:31 pm »
same..nothing happens
No blinking RX LED or something.
With Hterm it works well
I use /dev/ttyUSB0
« Last Edit: December 04, 2024, 04:44:00 pm by coradi »
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

cdbc

  • Hero Member
  • *****
  • Posts: 2682
    • http://www.cdbc.dk
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #4 on: December 04, 2024, 05:54:35 pm »
Hi
Just checking...
You are trying to fit Thaddy's example to use your local values, right?!?
...Not just copy-pasting and hoping...  ;D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

af0815

  • Hero Member
  • *****
  • Posts: 1409
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #5 on: December 04, 2024, 05:59:52 pm »
The samples are for reading data on the computer side, not for sending. If you use HTerm i think, you are sending data to the serial device.
regards
Andreas

Thaddy

  • Hero Member
  • *****
  • Posts: 18786
  • To Europe: simply sell USA bonds: dollar collapses
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #6 on: December 04, 2024, 07:04:36 pm »
That works almost identical. will add that example tomorrow.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

coradi

  • Full Member
  • ***
  • Posts: 197
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #7 on: December 04, 2024, 09:37:12 pm »
At this moment I only need reading. I don'T use hterm.
I used it only to check if I can get Data here, and this work, in Hterm I receive data.
But in PAscal, nothing happens, when I end hterm for free the com Port.

Yes, I only copy paste this and take a look into the Console output Window
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

coradi

  • Full Member
  • ***
  • Posts: 197
Re: Use tts0, This example is from chatgpt,but why it doesn't work?
« Reply #8 on: December 15, 2024, 08:07:57 pm »
Maybe the problem is, that the sending string has no /0 at the end?
But ow can I receive it then, if  can't mody the sending string?
Amstrad Schneider CPC 6128
AVR8/ARM(STM32)

 

TinyPortal © 2005-2018