Recent

Author Topic: Talk to localhost port 2947?  (Read 17792 times)

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: Talk to localhost port 2947?
« Reply #15 on: August 18, 2013, 06:19:23 am »
BLL,

What is the version of Lazarus and FPC U use ?
Lazarus 3.6 on Windows 11

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Talk to localhost port 2947?
« Reply #16 on: August 18, 2013, 11:01:15 am »
FPC 2.7.1 and Lazarus 1.1

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Talk to localhost port 2947?
« Reply #17 on: August 18, 2013, 05:53:10 pm »
with synapse you can try something like :
Code: [Select]
uses blcksock;
var sock: TTCPBlockSocket;
    buffer: String = '';
begin
 sock := TTCPBlockSocket.Create;
 sock.Connect('127.0.0.1', '2947'); // connect to gpsd server
// Was there an error?
if sock.LastError <> 0 then
begin
    Showmessage('Could not connect to server.');
end
else
begin
// send a command  to watch GPS Frames
sock.sendString('?WATCH={"enable":true,"json":true}'#13#10);
// loop to read data from gpds
//replace true with a boolean variable to avoid infinite loop
// or use events
while true do
begin
// Time out 200 ms (wait for data)
buffer := sock.RecvPacket(200);
if buffer <> '' then Memo1.Append(buffer); // or writeln(buffer)
// process messages to  not freeze gui
Application.ProcessMessages;
end;
end;

Friendly, J.P
« Last Edit: August 18, 2013, 05:55:10 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Talk to localhost port 2947?
« Reply #18 on: August 18, 2013, 09:05:13 pm »
Hi, Thanks for that. I have now got it working using the LNet Telnet component. I have to turn debugging off but at least it is reading the json data and I have extracted lat and long, which is all I wanted. After doing that, I open a port (ttyUSB1) to talk to a PIC micro. Funny thing is that if I open that port prior to telneting the gps, I get no gps data at all, so I have to get the gps data and close the telnet session before opening the port!

Also had problems as both the gps and the Adafruit USB cable to the PIC use the PL2303 and the OS seemed to decide at random which it called ttyUSB0 and which ttyUSB1!! I have solved that with a .rules file, by creating a SYMLINK to the "PIC" port, so my program always reads the right device and similar for the gps, so gpsd gets the symbolic name rather than the actual and that seems to work fine. What a battle! Now it's off to write the PIC code in C - much easier!! Thanks for all your help.

 

TinyPortal © 2005-2018