[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

quick DLL question

Posted on 2006-05-18
13
Medium Priority
?
212 Views
Last Modified: 2010-04-05
Previously I had an exe app which would process data recieved from a file or serial port. I wish now to process the data in a DLL and i want to confirm that I am able to send the data to a DLL and process it correct.

Each character is recieved one after the other on the serial port and I detect CRLF to know that I have recieved a line to process. Can I do the same with a DLL

ie:
                   CRLF
                      d
                      c
                      b
                      a
  characters recieved on serial
                     |
                     |
     exe pass charaters to DLL                      
                     |
                     |
     DLL creates string (abcd)
0
Comment
Question by:lloydie-t
  • 6
  • 6
12 Comments
 
LVL 1

Expert Comment

by:svvada
ID: 16713071
Should be no problem sending a character array to a function in a DLL for processing. It works just like a normal function.
0
 

Author Comment

by:lloydie-t
ID: 16713135
I dont think it would be an array as each string/character would be sent seperately to the DLL. I am using the array to put the charcters together when CRLF is recieved. If thats possible!
0
 
LVL 1

Expert Comment

by:svvada
ID: 16733287
As far as I know you can't do what you want with a DLL. A DLL is a collection of routines. So when you call a DLL function it executes and returns the result to you. Every time you call the function you get a new instance so there is no way of storing temporary data.

I work a lot with sensor interfacing through serial ports. I'm wondering why you want to do this in a DLL? Maby I can help you find another way of solving your problem?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lloydie-t
ID: 16735577
I am getting inputs from various systems which I am trying to get into one database. At the moment I am limited to being able to log multiple systems of the same type an I really want to be able to log differing systems. Any Ideas? Thanks for the interest.
0
 
LVL 1

Expert Comment

by:svvada
ID: 16736336
Think I need more details to give any specific help. Like how do you interface the serial port are you using a component of sorts? Do you want to interface all the system from one application? How often do you receive data?

I can try to explain how we do it. We have a executable where you can configure inputs. What serial port or file to read from, format of the input (we've given them names) and processing parameters. Then when something is received on the port or a file is updated the fromat is parsed and the processing starts. What kind of processing is determined by the configuration. When the processing is complete the data is written to the database. This is just a simple representation of the system, the processing is quite complex.

You can make a serial port base class for reading data from the serial port. Then sub classes for parsing and processing the data from the various types of systems/formats. If the data should be written to different tables in the database for the varoius inputs you could create a class to handle the database connection with methods to write the various types of data.

Don't know if you make any sence of my ramblings?
0
 

Author Comment

by:lloydie-t
ID: 16737157
So At the moment what I do is have multiple copies of my app running on the same machine.
I have an ini file which allows me to set the parameters of each port.
So I run each exe with a parameter so it knows which part of the ini file to look at (comm.exe /Port1, comm.exe /Port2, etc)
The most of the input processing is done in the exe, but some conversion work is done in an DLL. This allows me to limit the amount of exe's I have to rewrite for each system, as most systems send thier information on one line of text, some on two lines and a few on more than two lines.
So this works know, but it does restrict me to only having multiples of the sames type of systems on the serial ports on a system.
Something like:

 Comm1       Comm2       Comm3         Comm4
    exe            exe              exe              exe
     |_________|__________|__________|
                                 |
                                DLL
                                 |
                            Database

What I really want to do is run an exe as a service. which I suppose will start the other exe's in the background and each exe can use the ini file to let it know which version of the DLL to use. I just thought of that. Does it make sense?
0
 
LVL 1

Expert Comment

by:svvada
ID: 16738209
I've been working on the same model for many years now and then you get stuck in a certain way of thinking so bear with me.  Your configuration seems nice and simple. The service concepts should work nicely. I guess what you are trying to do is to make the exe as thin as possible by putting as much as possible of the functionality into DLL's. Am I right? When you say "multiple copies" and "allows me to limit the amount of exe's I have to rewrite" I conclude that you have several similar executables doing almost the same thing? It seems to me that you only have need for one exe and run multiple instances with different configuration, then you might not even need to use a DLL at all? Then you could configure input from serial port 1 with input format 1. In the code you then listen to/poll port 1, when data is recived then parse and process it with format 1 specific methods, if format 2 from file foo.txt is configured you use file reading and format  2 specific methods. This way you only have one exe to recompile and replace when a new format needs to be added. Let me know if I'm way of target here!
0
 

Author Comment

by:lloydie-t
ID: 16738504
I think we are getting some where. So these would be the differing formats I would recieve

1. Data all on one line
call 1 = 16:37:32    00:04       0:45  2809  7040   #01604637838
call 2 = 16:37:32    00:00       1:25  2800  7041   #INCOMING

2. Data across two lines
call 1 = 22-05-06 23:20:00 200 701
            EI 07754637836 00:01 05:24

3. Data across multiple lines
call 1 =
--------   22/05/06   13:02:24   EXT = 222  LINE = 0011  
00:00:00   OUTGOING CALL  
           DIGITS DIALLED   02422822485  
00:00:17   CALL RELEASED  

call 2 =
--------   22/05/06   12:58:10   EXT = 255  LINE = 0012  
00:00:00   OUTGOING CALL  
           DIGITS DIALLED   0033141893354  
00:05:24   CALL RELEASED

As you can see they are quite a bit different and these  dont include the variations on the above.

So If I have data which is all delivered on one line, once the EOL is received I process it in an DLL to get the data in the right format to be processed by the EXE. I have receive data from a differing system but again data is received on one line I think I would send that data to a different DLL to be formated and returned to the same EXE.

Do you have a better way of getting the differing data processed?
BTW I have upped the points
0
 
LVL 1

Expert Comment

by:svvada
ID: 16749335
You will want to check the lines to verify what kind of line you just read. In this case you might want to use TRegExp (http://regexpstudio.com/) to check the format. When there is multiple lines you just have to hang on to the lines untill you have verified all lines in the telegram. Once you've made sure you've got a valid telegram you can send it to the DLL for processing. As long as you tell the exe what kind of telegram to expect in the ini file you should only need one version of the exe.

In fact you might be able to make the exe pretty much generic by putting the reg exp format in the configuration, but I'll have to think about that one. I'll try to make an example of what I'm thinking about.
0
 

Author Comment

by:lloydie-t
ID: 16749375
Look forward to that
0
 
LVL 1

Accepted Solution

by:
svvada earned 600 total points
ID: 16754361
OK here goes! I've never used the RegExpr for anything before today so I guess the Perl coders will have a good laugh about this. Meaning that there is a lot more you can do with regular expresions so if you choose this approach you should dig a bit deeper than this example. I've implemented the two single lines and then the one with two lines, the ones with four should be the same just more work. I just made a form with a button to have a starting point, anyway here is the code I wrote:

unit fMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FNoOfLinesInTelegram : integer;
    FRegExps : array of string;
    FValidatedLines : array of string;
    FLineNo : integer;
    procedure InitConfig(TelegramID : Integer);
    procedure ReceivedLine(Line : string);
    procedure SendTelegram(TelegramID : Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  RegExpr;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FLineNo := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // Sends 3 different telegrams
  SendTelegram(1);
  SendTelegram(2);
  SendTelegram(3);
end;

procedure TForm1.SendTelegram(TelegramID: Integer);
const
  Telegram1 = '16:37:32    00:04       0:45  2809  7040   #01604637838';
  Telegram2 = '16:37:32    00:00       1:25  2800  7041   #INCOMING';
  Telegram3Line1 = '22-05-06 23:20:00 200 701';
  Telegram3Line2 = 'EI 07754637836 00:01 05:24';
begin
  // This data is received from the serial port or file so this method is just for the example
  InitConfig(TelegramID);
  case TelegramID of
  1: ReceivedLine(Telegram1);
  2: ReceivedLine(Telegram2);
  3:
   begin
     ReceivedLine(Telegram3Line1);
     ReceivedLine(Telegram3Line2);
   end;
  end;
end;

procedure TForm1.InitConfig(TelegramID : Integer);
begin
  // TelegramID, NoOfLInes and the RegExp should then come from the config file so this method just for the example
  case TelegramID of
  1:
   begin
     FNoOfLinesInTelegram := 1;
     SetLength(FRegExps, FNoOfLinesInTelegram);
     // 16:37:32    00:04       0:45  2809  7040   #01604637838
     FRegExps[0] := '^[0-2]\d:[0-5]\d:[0-5]\d\s{4}[0-2]\d:[0-5]\d\s[\d-\s]{6}\d:[0-5]\d\s[\d-\s]{4}\d\s[\d-\s]{4}\d\s{3}#\d+$';
   end;
  2:
   begin
     FNoOfLinesInTelegram := 1;
     SetLength(FRegExps, FNoOfLinesInTelegram);
     // 16:37:32    00:00       1:25  2800  7041   #INCOMING
     FRegExps[0] := '^[0-2]\d:[0-5]\d:[0-5]\d\s{4}[0-2]\d:[0-5]\d\s[\d-\s]{6}\d:[0-5]\d\s[\d-\s]{4}\d\s[\d-\s]{4}\d\s{3}#INCOMING$';
   end;
  3:
   begin
     FNoOfLinesInTelegram := 2;
     SetLength(FRegExps, FNoOfLinesInTelegram);
     // 22-05-06 23:20:00 200 701
     FRegExps[0] := '^[0-3]\d[-][0-1]\d[-]\d{2}\s[0-2]\d:[0-5]\d:[0-5]\d\s\d{3}\s\d{3}$';
     // EI 07754637836 00:01 05:24
     FRegExps[1] := '^EI\s\d{11}\s[0-2]\d:[0-5]\d\s[0-2]\d:[0-5]\d$';
   end;
  end;
  SetLength(FValidatedLines, FNoOfLinesInTelegram);
end;

procedure TForm1.ReceivedLine(Line: string);
begin
  // This where the ExecRegExpr is used to check for a match
  If ExecRegExpr(FRegExps[FLineNo],Line) then
  begin
    // we got a match
    FValidatedLines[FLineNo] := Line;
    // If all lines expected are validated then process
    if FLineNo = FNoOfLinesInTelegram then
    begin
      // Call the DLL with the validated lines for processing
      // The DLL should then look at the telegram ID and decide how to process it
      // CallDLL(FValidatedLines, TelegramID);
      FLineNo := 0;
      Exit;
    end;
    // Look for next line
    Inc(FLineNo);
  end
  else
  begin
    // Here you might want do some error handling?
  end;
end;

end.

Have a look at it and tell me what you think.
0
 

Author Comment

by:lloydie-t
ID: 16941042
swada, soory for not getting back to you sooner. I got bogged down in other stuff and forgot about this. Your solution looks good to me with a few small changes.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question