Serial Port Component For Lazarus Syndrome Rating: 4,3/5 9179 votes
  1. Lazarus Syndrome Medical

I am writing a testing application for checking out a TCP to Serialbridge component. I am using Lazarus 1.8.0 and fpc 3.0.4 on Windows 7For the serial port handling I found the 'built-in' Serial unitdescribed here:Now I have a few questions about its usage:1) Serial port name-When opening the port the example does this:str(ComPortNr,tmpstr);ComPortName:= 'COM'+tmpstr+':';serialhandle:= SerOpen(ComPortName);So for say port 29 this results in ComPortName 'COM29:'Is this always the case? On Sun, 09 Sep 2018 13:33:22 +0200, Bo Berglund via Lazarus wrote:3) Receiving data-I forgot to add a question about read timeouts.4) Read timeout-When running this to read incoming data:status:= SerRead(serialhandle, s1, 10);How can I get out of the call if there never arrives 10 bytes? Isthere a timeout somewhere so that I can set it to some small value andput the SerRead into a thread that can check arriving data and iffound fire off an event or such?-Bo BerglundDeveloper in Sweden-Lazarus mailing list. On 09/09/18 12:00, Bo Berglund via Lazarus wrote: I am writing a testing application for checking out a TCP to Serialbridge component. I am using Lazarus 1.8.0 and fpc 3.0.4 on Windows 7 For the serial port handling I found the 'built-in' Serial unitdescribed here: Now I have a few questions about its usage: 1) Serial port name-When opening the port the example does this: str(ComPortNr,tmpstr);ComPortName:= 'COM'+tmpstr+':';serialhandle:= SerOpen(ComPortName); So for say port 29 this results in ComPortName 'COM29:'Is this always the case? I have a hunch that for port numbers 1.9 theWindows port naming is different than for higher port numbers.

And if I want to port this to Linux, I guess thta the name iscompletely different, but no hint is given.I did quite lot of work on the serial.pp unit more recently than thatwiki page, in fact I didn't even know it existed. Please refer to thecomments in that file in the first instance.-Mark Morgan LloydmarkMLl.AT.

UkOpinions above are the author's, not those of his employers or colleagues-Lazarus mailing list. I am writing a testing application for checking out a TCP to Serialbridge component. I am using Lazarus 1.8.0 and fpc 3.0.4 on Windows 7For the serial port handling I found the 'built-in' Serial unitdescribed here: Now I have a few questions about its usage:1) Serial port name-When opening the port the example does this:str(ComPortNr,tmpstr);ComPortName:= 'COM'+tmpstr+':';serialhandle:= SerOpen(ComPortName);So for say port 29 this results in ComPortName 'COM29:'Is this always the case?

Lazarus Syndrome Medical

Component

I have a hunch that for port numbers 1.9 theWindows port naming is different than for higher port numbers.And if I want to port this to Linux, I guess that the name iscompletely different, but no hint is given.Here is the procedure I'm using to fill up a combo box with thenames of the existing serial devices on the platform. Please notethe different naming conventions in Linux and Windows. Also notethat to report a serial port as existing a test is made to open it(using the fpc serial function), and avoid 'phantom' ports.But does not this listing fail if a port is already in use, i.e. TheSerOpen call will return 0 indicating it is not found? 3) Receiving data-For data reception I see this:s:=';ComIn:=';while (Length(Comin)=0) and not keypressed dobegin status:= SerRead(serialhandle, s1, 10);.Since the call parameters are the receive buffer and the count to readI do not understand how this can work.

Serial

S has been emptied (length = 0)just before the call so how can SerRead stuff any data into the bufferstarting at s1, which should not even exist???I would like to have a way to read incoming data asynchronously so Ialso could handle the user feedback and the TCP connection which issending the data that ultimately will arrive on the serial line.Any suggestions on how to do this?I never use SerRead, but rather SerReadTimeout (from the sameunit) which gives a much better control of what is going on. Ofcourse in that case your receiving buffer must be large enough toaccommodate the largest block you expect.

(This replies also toyour further questions).Did not see this before, but it seems like a good choice for readingdata in a loop until the return is less than Count, which means thatthe timeout has caused the exit.Thanks for the suggestion!I hope that it helps.Yes it does, but it would have been even better if not full of HTMLtags and stuff. I have edited out most but I guess there are somestill left.For example inside the code there may be some things like ratherthan -Bo BerglundDeveloper in Sweden-Lazarus mailing list. Il 17:30, Bo Berglund via Lazarus ha scritto: This seems only to deal with ports 1.9, what about the higher numbered ports 10.255?

And would it not be a long execution time for testing all 255 possible com ports on Windows?In my experience both Linux and Windows if you connect a new serialdevice do set a port number just higher than the previous one already there.This means that you'll have to deal with higher numbers only if you havemore than 9 serial lines in your platform, which is a bit unlikely. Notto consider the likelihood of a platform with 200 serial lines!-Do not do to others as you would have them do to you.They might have different tastes.-Lazarus mailing list. Il 17:30, Bo Berglund via Lazarus ha scritto: Unfortunately not possible in the real case because the file transfer protocol of the device only sends a header with the count of the data to follow and then streams all of the bytes.I don't know how your application is built, but if the origin is an ftptransfer, then data are sent in small packets. It would appear that yousomehow get the ftp data and send them to a serial line. It is at thatpoint of the processs that you should create your records to send themindividually via the serial line.-Do not do to others as you would have them do to you.They might have different tastes.-Lazarus mailing list.

Il 17:30, Bo Berglund via Lazarus ha scritto:I hope that it helps.Yes it does, but it would have been even better if not full of HTMLtags and stuff. I have edited out most but I guess there are somestill left.For example inside the code there may be some things like ratherthan Sorry, I forced HTML for better readability.But you may easily extract the clean text (without > and such)by creating an empty html file (whatever.html), and opening it withLibreOffice or OpenOffice. Then you may copy and paste into it thetext from the e-mail, and finally save it as a pure text fle(whatever.txt). It is much faster and safer than manual editing.Giuliano-Do not do to others as you would have them do to you.They might have different tastes.-Lazarus mailing list. On Mon, 10 Sep 2018 19:44:22 +0200, Giuliano Colla via Lazarus wrote:Il 17:30, Bo Berglund via Lazarus ha scritto: This seems only to deal with ports 1.9, what about the higher numbered ports 10.255? And would it not be a long execution time for testing all 255 possible com ports on Windows?In my experience both Linux and Windows if you connect a new serialdevice do set a port number just higher than the previous one already there.On Windows7 at least every time you attach a serial2usb dongle into adifferent USB port than before it creates a new COM port with a highernumber. And this port is sticky on the PC too, it remains 'taken'.So after a few years (my laptop is from 2011) it stacks up and eventhough I have currently only attached 6 such converters (one is a4-way) the com port numbers are 29-30-31-32-33-34.This means that you'll have to deal with higher numbers only if you havemore than 9 serial lines in your platform, which is a bit unlikely.

Notto consider the likelihood of a platform with 200 serial lines!I would eventually get there if I continue to unplug and re-plug thesedongles.-Bo BerglundDeveloper in Sweden-Lazarus mailing list. Il 17:30, Bo Berglund via Lazarus ha scritto: Unfortunately not possible in the real case because the file transfer protocol of the device only sends a header with the count of the data to follow and then streams all of the bytes.I don't know how your application is built, but if the origin is an ftptransfer, then data are sent in small packets. It would appear that yousomehow get the ftp data and send them to a serial line. It is at thatpoint of the processs that you should create your records to send themindividually via the serial line.No FTP!What I meant is that the device I want to communicate with has aproprietary serial protocol and it can do file transfers too.The protocol is delimited and checksummed, but when a file istransferred there is only one block of file data in the middle of thetransfer and it could be up to 1 Mbytes (the memory limit of thedevice).My application is meant to test WiFiSerial converters to evaluatethose we could use with the data device. So I want to run data throughthe unit under test in both direction to verify that it is going towork in the real environment.

For the serial port handling I found the 'built-in' Serial unitdescribed here: Now I have a few questions about its usage:1) Serial port name-When opening the port the example does this:str(ComPortNr,tmpstr);ComPortName:= 'COM'+tmpstr+':';serialhandle:= SerOpen(ComPortName);So for say port 29 this results in ComPortName 'COM29:'Is this always the case?