How do I use ComPort

Help
2012-04-05
2013-04-30
  • Kevin Quach

    Kevin Quach - 2012-04-05

    Hi All,

    I'm new to Delphi and ComPort so I don't know much about anything.

    I'm currently using Delphi 2010 and I just installed the latest version of ComPort (I think).

    I know I can drag and drop a ComPort Component because I've already tried that but after that I have no idea what to do next.

    I have an application at the moment connected to an Access database and I want to get numbers from the database, compact everything to a define data packet and send that to an external hardware.

    I'll also need to recieve a specific data packet of already defined structure and extract information from that packet.

    Is there and specific functions or informations that I can read to help me better understand what I need to do. I know you want provide code because I haven't provided anything so I'm not expecting much.

    I just want to know where to look for what I need to do to complete my task.

    Thanks in advance

     
  • Stephen Gaunt

    Stephen Gaunt - 2012-04-05

    If the data packets are of a defined length, then I would use a packet reciver (on the com port pallet) to grab the incomming messages. If the incoming messages have a fixed first character (delimiter) then yoiu can tell tyhe pack Receiver about this and the expected length, link the packet receiver to the comport component.
    The packet receiver has a method OnPacket the recieves the incoming packet in Str: string; uise tis to perform the required manipulation on the data (finding commas that sort of thing)

    Writing I use a line like this:-
       Cport.Write(Txbuff, L + 2);

    TxBuff is an array (of byte in this case), I load it with the data to be sent, L is the number of bytes to send
    e.g part of my GPS message simulator application..

    1,2: begin //  GPS
               L := length(TxString);
               if not (L in ) then
                 L := 93;
               SizeBox.Text := inttostr(L);
               for a:= 1 to L do
                  begin
                     c := TxString;
                     TxBuff := ord(C);
                  end;
              TxBuff := $0D;  // CR
              TxBuff := $0A;  // LF

            end;

    however there are lots of other ways to use the CPort system, and some example code in the package!
    Hope this helps
    Steve
     

     
  • Kevin Quach

    Kevin Quach - 2012-04-30

    Hi again,

    Sorry it took so long to reply back but I need to do other parts of the project before trying the Comport section. Now that I'm almost there; I started looking at the example code in the package and I saw that when I press send -> nothing comes up on the memo.

    Is that because the send button doesn't link with COM 1 so it doesn't count as a recieved? If so; how do I test recieving something?

    Regards

     
  • Kevin Quach

    Kevin Quach - 2012-05-04

    Hi sggaunt,

    I was just wondering what 'c' was in your context?

    Also, would you be able to tell me how to adjust your code to send not a string but instead -> 173 bits?

    I tried making a string and added 173 single characters of '1' but it only sent something like 45 characters.

    Is that because I can't do it this way or is there a special setting for comport that I have to do to allow more data to be sent in a single buffer. Maybe I'm doing it wrong?

    My code at the moment is on send button click:

    if DataModule1.ComPortTx.Connected then
      begin
        byteCount := Length(TxString);

        if byteCount < 173 then
          byteCount := 173;

        for I := 0 to 173 do
          TxBuff_ := ord(TxString);

        DataModule1.ComPortTx.Write(TxBuff, byteCount);
      end
      else
        ShowMessage('Must Open Port');

    Can you please help me again?

    Thank you_

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks