Recent

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

BLL

  • Sr. Member
  • ****
  • Posts: 276
Talk to localhost port 2947?
« on: August 04, 2013, 09:09:24 pm »
How can I talk to port 2947 on localhost, where gpsd provides the data from my gps please?

I have given up trying direct access to ttyUSB0 as I can't retrieve sensible data, although cgps does it fine!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Talk to localhost port 2947?
« Reply #1 on: August 04, 2013, 09:58:50 pm »
To 127.0.0.1:2947? The same as you would talk to other ports on servers.

See e.g.
http://wiki.lazarus.freepascal.org/Networking

I like Synapse myself.

(Guessing you're running on Linux, say a Raspberry Pi, with Lazarus trunk on FPC trunk, but telling us this kind of info often helps when answering questions. You could put the info in your forum signature so you don't have to retype it all the time)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Talk to localhost port 2947?
« Reply #2 on: August 04, 2013, 10:06:04 pm »
HI, I haven't done anything with sockets before! I have looked at the link you gave and the nearest thing seems to be:
{$mode objfpc}{$H+} 
 
uses 
  Classes,SysUtils,Sockets,fpAsync,fpSock; 
 
var 
  ClientEventLoop: TEventLoop; 
begin 
  ClientEventLoop := TEventLoop.Create; 
  with TTCPClient.Create(nil) do begin 
    EventLoop := ClientEventLoop; 
    Host := '127.0.0.1'; 
    Port := 12000; 
    Active := true; 
    EventLoop.Run; 
    Stream.WriteAnsiString('Hello'); 
    Active := false; 
  end; 
  ClientEventLoop.Free; 
end.

That is sending data. For receiving, can I use ReadAnsiString instead?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Talk to localhost port 2947?
« Reply #3 on: August 04, 2013, 10:22:51 pm »
I have no idea. Have never used sockets and suspect they're a bit low level.

I'd suggest synapse or lnet.

Indy apparently works for some but I believe it's more complicated and difficult to get to work.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: Talk to localhost port 2947?
« Reply #4 on: August 04, 2013, 10:26:39 pm »
No, WriteAnsiString and ReadAnsiString send/receive the length of the string first as 4 bytes. You would probably need raw data using the Read and Write functions instead.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Talk to localhost port 2947?
« Reply #5 on: August 04, 2013, 10:32:42 pm »
Also, I would look at what protocol gpsd is speaking. It might well be telnet in which case you could use the telnet code from the synapse wiki article.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Talk to localhost port 2947?
« Reply #6 on: August 04, 2013, 11:04:52 pm »
Hmm - looks like a non-starter in pascal. I found this from gpsd:
The GPSD project provides client-side libraries in C, C++, and Python that exercise the sockets export.

I can't believe how difficult it seems to be to read data from a gps!

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: Talk to localhost port 2947?
« Reply #7 on: August 04, 2013, 11:20:55 pm »
Does the GPS use a serial port? In that case it might be easier to write a simple NMEA parser by yourself

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Talk to localhost port 2947?
« Reply #8 on: August 05, 2013, 04:57:53 am »
Hmm - looks like a non-starter in pascal. I found this from gpsd:
The GPSD project provides client-side libraries in C, C++, and Python that exercise the sockets export.
So they don't have any ready made bindings. This is no problem as long as they speak a sensible protocol.

Hint: try connecting to the port with telnet and see what you get. Posts on the internet and the wikipedia article on gpsd made me think it uses telnet (and passes json back and forth - fortunately there's a json parsing/generation unit available with FPC).

Also, the gpsd site has loads of info. There should be a network protocol description somewhere, even if it is only a reference to telnet (or whatever) and JSON RFC.

As for writing NMEA parsers & serial parts: I would strongly advise not to do this as there are a lot of NMEA variations, and the GPSD protocol is a nice abstraction layer. Of course, if nothing else helps, you can do this, but I think figuring out what GPSD talks is much easier.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: Talk to localhost port 2947?
« Reply #9 on: August 05, 2013, 05:52:57 am »
As I found on GPSd site :
Quote
gpsd is a service daemon that monitors one or more GPSes or AIS receivers attached to a host computer through serial or USB ports, making all data on the location/course/velocity of the sensors available to be queried on TCP port 2947 of the host computer. With gpsd, multiple location-aware client applications (such as navigational and cardriving software) can share access to receivers without contention or loss of data. Also, gpsd responds to queries with a format that is substantially easier to parse than the NMEA 0183 emitted by most GPSes.

So you have to listen port 2947 - It is easy to do - I recommend LNet and LTCPComponent.

After that - read  the white papers and other like http://catb.org/gpsd/client-howto.html

Good luck.
Lazarus 3.6 on Windows 11

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Talk to localhost port 2947?
« Reply #10 on: August 05, 2013, 01:17:53 pm »
Wow, Thanks for all the replies. It is a USB gps (BU-353 with the PL-2303 chip to look like a com port. It appears as ttyUSB0. I will try telnet, although I will have to find ot how as I am still very new to the RasPi. I will look at the components mentioned and the info links - lots to do! Thanks for all the advice.

I did try and use the gpsx component, which has a NMEA parser, but that's a disaster under linux - it relies on Sdpo serial component, v0.1.5. The author of this component says it doesn't read ports properly in linux, as I confirmed (it just locks everything up solid!), apart from having some spurious baud rates. The replacement Sdpo, v0.2.0 is no longer a component, so gpsx won't have it!

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Talk to localhost port 2947?
« Reply #11 on: August 05, 2013, 03:47:25 pm »
Hi BamBamns, I have installed LNET component fine. However, if I drop any of the components on the form of my app and run the app, I get an exception error class 'SIGILL' at address B5B4F5E0 and then a window opens called assembler!

fpc 2.7.1, Lazarus 1.1, RasPi with raspbian-wheezy

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Talk to localhost port 2947?
« Reply #12 on: August 05, 2013, 11:33:57 pm »
look at  :o  here BLL
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 #13 on: August 06, 2013, 10:54:03 am »
Hi, I have seen that. In Project options, compiler options, Debugging, I have Generate Debugging info for GDB unchecked. I still get the error!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Talk to localhost port 2947?
« Reply #14 on: August 06, 2013, 11:52:44 am »
It often helps if you attach your project source code  - via project/publish project menu, then zip the directory - so others can look for errors.
If the zip is big, you can of course upload it to a file sharing service and send the link.

These kinds of errors:
Quote
I get an exception error class 'SIGILL' at address B5B4F5E0 and then a window opens called assembler!
are otherwise very difficult to troubleshoot...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018