Talk to localhost port 2947? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- BLL · 2013-08-04 19:09 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 · 2013-08-04 19:58 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) ---------------------------------------------------------------------- BLL · 2013-08-04 20:06 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 · 2013-08-04 20:22 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. ---------------------------------------------------------------------- Laksen · 2013-08-04 20:26 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 · 2013-08-04 20:32 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. ---------------------------------------------------------------------- BLL · 2013-08-04 21:04 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 · 2013-08-04 21:20 Does the GPS use a serial port? In that case it might be easier to write a simple NMEA parser by yourself ---------------------------------------------------------------------- BigChimp · 2013-08-05 02:57 Quote from: BLL on August 04, 2013, 11:04:52 pmHmm - 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. ---------------------------------------------------------------------- bambamns · 2013-08-05 03:52 As I found on GPSd site : Quotegpsd 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. ---------------------------------------------------------------------- BLL · 2013-08-05 11:17 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 · 2013-08-05 13:47 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 · 2013-08-05 21:33 look at    here BLL ---------------------------------------------------------------------- BLL · 2013-08-06 08:54 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 · 2013-08-06 09:52 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: QuoteI get an exception error class 'SIGILL' at address B5B4F5E0 and then a window opens called assembler! are otherwise very difficult to troubleshoot... ---------------------------------------------------------------------- bambamns · 2013-08-18 04:19 BLL, What is the version of Lazarus and FPC U use ? ---------------------------------------------------------------------- BLL · 2013-08-18 09:01 FPC 2.7.1 and Lazarus 1.1 ---------------------------------------------------------------------- Jurassic Pork · 2013-08-18 15:53 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 ---------------------------------------------------------------------- BLL · 2013-08-18 19:05 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.