[fpc-pascal] Serial to TCP gateway in FPC?
I need to implement a serial to TCP gateway in order to communicate between a Windows based control software and a system controller box. The software and the controller only talk serial to each other and the protocol is proprietary and binary. Now I have a situation where the controller is on a remote location many thousands of km away from here. I have managed to get some help on the remote site to hook up the controller serial port to a serial to USB cable plugged into a Raspberry Pi, which I can reach via VPN from here. So I installed serial2net on the RPi, making it publish the serial port as a TCP port (#2091). This part works OK, so whatever is sent on the TCP socket connection gets transferred to the RS232 serial line and vice versa. So far so good, but now I also need some kind of serial port to TCP converter on the Windows 7 PC I use in my end, which is handling the VPN connection. So I wonder if there are any FPC examples around for conversion serial to TCP (where the TCP part is a client rather than a server), which can compile on Windows. I cannot use any RPi in this end because I cannot get the RPi to connect by VPN to the remote location... Ready made example or suggestions on how to go about writing a converter in FPC are welcome! -- Bo Berglund Developer in Sweden ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Serial to TCP gateway in FPC?
Couldn't you read the serial port data and then stream it with Synapse to the remote location? You can use Synapse to read the serial port data and sent via TCP/IP. On Jun 18, 2017 2:05 AM, "Bo Berglund" wrote: > I need to implement a serial to TCP gateway in order to communicate > between a Windows based control software and a system controller box. > The software and the controller only talk serial to each other and the > protocol is proprietary and binary. > Now I have a situation where the controller is on a remote location > many thousands of km away from here. > I have managed to get some help on the remote site to hook up the > controller serial port to a serial to USB cable plugged into a > Raspberry Pi, which I can reach via VPN from here. So I installed > serial2net on the RPi, making it publish the serial port as a TCP port > (#2091). This part works OK, so whatever is sent on the TCP socket > connection gets transferred to the RS232 serial line and vice versa. > > So far so good, but now I also need some kind of serial port to TCP > converter on the Windows 7 PC I use in my end, which is handling the > VPN connection. > > So I wonder if there are any FPC examples around for conversion serial > to TCP (where the TCP part is a client rather than a server), which > can compile on Windows. I cannot use any RPi in this end because I > cannot get the RPi to connect by VPN to the remote location... > > Ready made example or suggestions on how to go about writing a > converter in FPC are welcome! > > > -- > Bo Berglund > Developer in Sweden > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Serial to TCP gateway in FPC?
On Sun, 18 Jun 2017 09:46:06 -0500, Snorkl e wrote: >Couldn't you read the serial port data and then stream it with Synapse to >the remote location? >You can use Synapse to read the serial port data and sent via TCP/IP. > Probably, but I was hoping for some ready-made example to get going a bit faster... I did another piece of software a year or so ago only involving TCP/IP, also for remote control, but then I used an Indy TCP client component. My problem is getting my head around serial port handlers, which I have so-so experience of in the past. No RS232 work with FPC/Lazarus earlier and in Delphi I used AsyncPro components, but these are so complex that one is lost amongst all properties to set... I would like a dead simple serial component where I could just specify the comm parameters (baud, start/stop bits, handshaking and port) then just open the connection and wait for receive *events*. Yes, it is easier for me to have components with event generation on data reception rather than using blocking components, which I must make threads for and then figure out how to channel the data from the thread into the main application... -- Bo Berglund Developer in Sweden ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Implementing AggPas with PtcGraph
On 2017-06-16 18:49, James Richters wrote: agg^.Font('C:\Windows\Fonts\ConsolaB.ttf' ,45 ) works fine, but as I mentioned I can't be sure windows is installed in C:\Windows When you use the Windows GDI font engine, you don't have to specify the location of the font - that is done for you in the font engine. Also you specify the font name like windows programs do, you don't specify the font filename. For example: agg^.LineWidth(1); agg^.Font('Consola' ,45, True); // Bold agg^.Text(300 ,100 ,'Consola font here.' ); agg^.Font('Courier New' ,45, False, True ); // Italics agg^.Text(300 ,150 ,'Courier New font here.' ); Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Serial to TCP gateway in FPC?
Op 18-06-17 om 18:16 schreef Bo Berglund: Hi, Do you know the SDPO-package ? That has a serial component (SDPOSerial). This has a OnRxData event. Just a thought. I used it in the past without problems. HTH Koenraad. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Silencing redundand FPC messages
Perfect, thank you! Dňa 17. 6. 2017 o 16:05 Jonas Maebe napísal(a): On 17/06/17 12:27, Lubos Pintes wrote: But how can I get rid of "Target OS XXX:"? The parameter -vi- will disable all messages of the level "info", such as the above mentioned message and things like "Compiling XXX" Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Serial to TCP gateway in FPC?
Synapse and fpc works great with serial port, I have a daemon I wrote 4 years ago that reads serial data from a phone PBX runs 24X7 and never an issue. On Jun 18, 2017 11:17 AM, "Bo Berglund" wrote: > On Sun, 18 Jun 2017 09:46:06 -0500, Snorkl e > wrote: > > >Couldn't you read the serial port data and then stream it with Synapse to > >the remote location? > >You can use Synapse to read the serial port data and sent via TCP/IP. > > > > Probably, but I was hoping for some ready-made example to get going a > bit faster... > I did another piece of software a year or so ago only involving > TCP/IP, also for remote control, but then I used an Indy TCP client > component. > My problem is getting my head around serial port handlers, which I > have so-so experience of in the past. No RS232 work with FPC/Lazarus > earlier and in Delphi I used AsyncPro components, but these are so > complex that one is lost amongst all properties to set... > > I would like a dead simple serial component where I could just specify > the comm parameters (baud, start/stop bits, handshaking and port) then > just open the connection and wait for receive *events*. > > Yes, it is easier for me to have components with event generation on > data reception rather than using blocking components, which I must > make threads for and then figure out how to channel the data from the > thread into the main application... > > > -- > Bo Berglund > Developer in Sweden > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Serial to TCP gateway in FPC?
On 06/18/2017 03:04 AM, Bo Berglund wrote: I need to implement a serial to TCP gateway in order to communicate between a Windows based control software and a system controller box. The software and the controller only talk serial to each other and the protocol is proprietary and binary. Now I have a situation where the controller is on a remote location many thousands of km away from here. I have managed to get some help on the remote site to hook up the controller serial port to a serial to USB cable plugged into a Raspberry Pi, which I can reach via VPN from here. So I installed serial2net on the RPi, making it publish the serial port as a TCP port (#2091). This part works OK, so whatever is sent on the TCP socket connection gets transferred to the RS232 serial line and vice versa. So far so good, but now I also need some kind of serial port to TCP converter on the Windows 7 PC I use in my end, which is handling the VPN connection. So I wonder if there are any FPC examples around for conversion serial to TCP (where the TCP part is a client rather than a server), which can compile on Windows. I cannot use any RPi in this end because I cannot get the RPi to connect by VPN to the remote location... Ready made example or suggestions on how to go about writing a converter in FPC are welcome! Why do you need FPC code? Here are free drivers that work in Windows: http://com0com.sourceforge.net/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Implementing AggPas with PtcGraph
>When you use the Windows GDI font engine, you don't have to specify the >location of the font - that is done for you in the font engine. > Also you specify the font name like windows programs do, you don't specify > the font filename. Thank you the information I finally partially figured out the red / blue color problem. After single stepping through tons of the aggpas code for hours (it's quite complicated even to draw a line) with a sample program that just made a red line at the top, I discovered that it's actually doing everything exactly correct! The problem is not with rendering with rgb565, the problem is something in the original that was patched with the setcolor function: Line 122 of agg_color pas has: constructor rgba8.Construct; begin b{*}:=int8u(r_ ); g:=int8u(g_ ); r:=int8u(b_ ); a:=int8u(a_ ); end; This switches red and blue... if I correct it to: constructor rgba8.Construct; begin b{*}:=int8u(b_ ); g:=int8u(g_ ); r:=int8u(r_ ); a:=int8u(a_ ); end; now my colors with rgb565 are correct. Since this is no logical reason to make b:=R_ and r:=B_ it seems more likely that with the rgba format somewhere along the way someone got lazy and just switched red and blue instead of fixing the pixelformat. It became obvious that the original was the thing that was backwards, not the RGB565 patch because I kept stepping through things like: constructor aggclr.Construct(rgba : rgba8 ); begin v:=(rgba.r * 77 + rgba.g * 150 + rgba.b * 29 ) shr 8; r:=rgba.r; g:=rgba.g; b:=rgba.b; a:=rgba.a; end; When I evaluated the variables R=0 G=0 B=255 A=255 But I defined a RED line, not a blue one. I used agg^.lineColor($FF, 0, 0, 255); and according to: procedure Agg2D.lineColor(r ,g ,b : unsigned; a : unsigned = 255 ); var clr : Color; begin clr.Construct(r ,g ,b ,a ); lineColor(clr ); end; This should be red. Every other function or procedure I came across with elements for red, green and blue kept coming up like this, so technically are incorrect. Where the inconsistency come from to fix it properly. For now I just made a compiler directive {$DEFINE AGG2D_USE_RGB565 } and use it to fix things in both agg_2D and agg_color. I've committed these to a custom branch on my github fork of fpGUI at: https://github.com/Zaaphod/fpGUI/tree/Zaaphod_Custom I looked at the file history in fpGUI and it looks like red and blue have been reversed like this since the initial import of aggpas into fpGUI, when I look at the original example agg2dconsole.dpr, it has in it: c.red := getBufItemAsWord(2); c.green := getBufItemAsWord(1); c.blue := getBufItemAsWord(0); c.alpha := getBufItemAsWord(3); but it should have been c.red := getBufItemAsWord(0); c.green := getBufItemAsWord(1); c.blue := getBufItemAsWord(2); c.alpha := getBufItemAsWord(3); and would have been if constructor rgba8.Construct; was correct... instead it was just re-reversed to compensate for the error in agg_color.pas. My point here is that it may be too late to just correct it now, because then everyone who has programs that already 'fix' the problem will then all be wrong, so I'm not sure what the best way to fix this is. James -Original Message- From: fpc-pascal [mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of Graeme Geldenhuys Sent: Sunday, June 18, 2017 12:32 PM To: fpc-pascal@lists.freepascal.org Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph On 2017-06-16 18:49, James Richters wrote: > agg^.Font('C:\Windows\Fonts\ConsolaB.ttf' ,45 ) works fine, but as I > mentioned I can't be sure windows is installed in C:\Windows When you use the Windows GDI font engine, you don't have to specify the location of the font - that is done for you in the font engine. Also you specify the font name like windows programs do, you don't specify the font filename. For example: agg^.LineWidth(1); agg^.Font('Consola' ,45, True); // Bold agg^.Text(300 ,100 ,'Consola font here.' ); agg^.Font('Courier New' ,45, False, True ); // Italics agg^.Text(300 ,150 ,'Courier New font here.' ); Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Implementing AggPas with PtcGraph
Good find and great sleuth work. It is possible that the original reason for switching R and B channels was to make the agg color object more compatible with LCL which seems to prefer BGR, order, but who knows... One obvious problem seems to be function AggToLCLColor(const c: TAggColor): TColor; in Agg_LCL, that relies for conversion on RGBToColor in the Graphics unit. function RGBToColor(R, G, B: Byte): TColor; begin Result := (B shl 16) or (G shl 8) or R; end; Anyway, a quick search of the agg source code shows that the rgba8 object is used only by a handful of units directly. Most agg units and demos use the more complicated aggclr object to represent color. I tried a few demos and seem unaffected by your fix. This explains why the bug was only clearly visible in your case, most of the other agg demos seem indiferent to the bug. On the other hand, besides agg_2D there are agg_fpimage, Agg2D (the one that integrates with LCL) that also use the rgba8 (through the TAggColor alias) and are clearly affected by the R and B swap when using canvas methods that involve the TAggColor object (e.g., AggClearAll, AggClearClipBox, etc). These would need to be updated as well. As an example, after your fix, the call canvas.AggClearAll(255,0,0) to TAggFPCanvas.AggClearAll(const r ,g ,b : byte; a : byte = 255 ) produces a blue background, which is clearly wrong. On 06/18/2017 08:35 PM, James Richters wrote: I finally partially figured out the red / blue color problem. After single stepping through tons of the aggpas code for hours (it's quite complicated even to draw a line) with a sample program that just made a red line at the top, I discovered that it's actually doing everything exactly correct! The problem is not with rendering with rgb565, the problem is something in the original that was patched with the setcolor function: Line 122 of agg_color pas has: constructor rgba8.Construct; begin b{*}:=int8u(r_ ); g:=int8u(g_ ); r:=int8u(b_ ); a:=int8u(a_ ); end; This switches red and blue... if I correct it to: constructor rgba8.Construct; begin b{*}:=int8u(b_ ); g:=int8u(g_ ); r:=int8u(r_ ); a:=int8u(a_ ); end; now my colors with rgb565 are correct. Since this is no logical reason to make b:=R_ and r:=B_ it seems more likely that with the rgba format somewhere along the way someone got lazy and just switched red and blue instead of fixing the pixelformat. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Serial to TCP gateway in FPC?
I know this is off topic, but does Synapse work on Android? I am planning on using FpcUpDeluxe to write an android app that has a TCP client, but am still looking for the TCP component. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal