Apologies for this question but I am a bit of a noob with Delphi. I am using Dejan TComport component to get data from a serial port. A box of equipment connected to the port sends about 100 bytes of binary data to the serial port.
What I want to do is extract the bytes as numerical values into an array so that I can perform calculations on them. TComport has a method Read(buffer,Count) which reads DATA from input buffer.
Function Read(var Buffer; Count: Integer): Integer; The help says the Buffer variable must be large enough to hold Count bytes but does not provide any example of how to use this function. I can see that the Count variable holds the number of bytes received but I can't find a way to access the bytes in Buffer. TComport also has a methord Readstr which reads data from input buffer into a STRING variable. Function ReadStr(var Str: String; Count: Integer): Integer; Again the Count variable shows the number of bytes received and I can use Memo1.Text:=str to display some information but obviously Memo1 has problems displaying the control characters.
I have tried various ways to try and extract the byte data from Str but so far without success. I am sure it must be easy. Here's hoping.
How do I get this data and insert them in 1 memo of my program before they go to the computer? Is still necessary that they go to the computer to be stored in 2 places in the memo and the computer. This sounds like you are trying to intercept the data so that you can display it in a field on a form in your application but you still want the data to wind up 'at the computer'. Where is the data when it is 'at the computer'? Do you mean that it is being put in a database or what? Also, the term 'memo field' sounds like you may be used to working with MS Access. Are you saying that you want to write this to a text field that has multiple lines?
Using the Events in a serial port component TComPort (v4) from a thread in Delphi? A Char in delphi is a Unicode entity, and while TComPort isn't dumb enough to read two bytes and call that a 'unicode character', you still might encounter some strange things if you didn't port to Unicode Delphi properly. Serial Port in Delphi 7 with.
If so, do you want each received piece of data to be written on a separate line? Are you having trouble reading the serial port? If you can answer these questions I can probably help you. I've worked with serial communications in Delphi. Greetings 8080Diver, data is sent by the computer through the serial port, has an automated program that already handle such data and do the work that has been programmed for you, if a register. My problem is, we assume that I get this program, do not use it more, then I want my program, which will take the data by serial port and put in a memo, but this is just one example that I taking these data at 1 memo I can do what you want then, records and more.
I know nothing about serial ports and read the data that pass through it, so I wanted this basic example. I know nothing about serial ports Now, that is going to be a problem.
Dealing with serial ports is not as simple as dropping a TADOCONNECTION and a TADOQUERY component on a DataModule and setting the aprameters and then off you go. There are several factors to consider when working with serial ports, things like:. Is there a carrier signal (i.e. Is the port connected to anything)?. Time outs,. Is there data available at the port?.
Getting the data before it gets over written;. Do you need to send an acknowledgement?. What do you do if the data is garbages (i.e.
Do you send a NACK instead of an ACK)? And that is just to mention a few of the points. No offense intended but this is definitely not for the novice or the faint of heart!
There is a set of components that I use for this purpose and I have a manual that is something like 1200 pages for them. The components are now available for free (that's the Good News) and you can probably find them by searching for their comercial name of 'Asynch Pro'. The Bad News is, as I mentioned, the manual I have is rather thick and the components, while wonderful for working with serial ports, are more than a bit complicated. And they are the best ones I know of.
@MerijnB, Well, IMHO, working with Serial Ports is complicated. I've done it many times over the years and the simple solutions usually turn out to be 'designed for Success (which means they only work if everything is working perfetly and, if something goes wrong, they blow all apart and don't provide muc in the way of information about why). If you don't care about getting all of the data and you don't care about whether you get the same data twice in a row, then there are some really simple solutions. It is not that there is a lot of 'heavy lifting' but, rather, that there a lot of little Lego blocks that you need to remember to put together in the right order. @MelissaCandy&, Unfortunately, I don't have a demo app handy and I don't have the time to create one right now. (Something to do with having a full time position and trying to have a personal life;-). I will say that, if you read the manual and download the components, I believe there are some demo apps that are also available as downloads.
The manual also has a fantastic explanation of serial communications and what all you have to deal with when using serial ports for data communications. It's kind of like bulding a small end table from a stack of boards. If you have never done it before, it seems amazingly complicated; however, if after you've done ift a few times, it isn't so complicated.
Mostly because you pretty much know what you're getting into.;-).