Solved

Serial port dumper as service

Posted on 2004-04-21
17
958 Views
Last Modified: 2012-08-13
Hey,
Im looking for a sample program that would run as a NT5/win2k/xp service and dump all the data from a certain com port to a file The program would read the input from the serial port line by line ( it would phrase the line after \n ) and insert it into the file. I would prefer something written in perl or delphi

Thanks
Tom
0
Comment
Question by:T0masz
  • 8
  • 4
  • 3
  • +1
17 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10889272
0
 

Author Comment

by:T0masz
ID: 10891828
I know how to write a sample program that reads from a port, the problem is that It has to be running as a NT service...

Tom
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10918579
check this

How to write a Windows NT Service (Delphi 5)
http://www.delphifaq.com/fq/q3055.shtml

Creating NT services in Delphi
http://builder.com.com/5100-6387-1050538.html?tag=sc
0
 

Author Comment

by:T0masz
ID: 10920536
The serial components dont work for delphi 7 and thats the only one I have...
Thanks for your help.
Tom
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10925265
Hi Tom,

I am a bot confused here ... You said in last post that you have the program to read/write to serial ports and need to make it run as a service ... Now you say that you do not have the working program ....

What is that you are looking for ?
0
 

Author Comment

by:T0masz
ID: 10929302
I dont have a working program, Im trying to write one, so far I got SerialNG to work but I have no clue how to make it read line by line and write to a file... another question is how far is it to go from a program thats designed as an :application: to a service?

Tom
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 10932287
Hello..
If you use Delphi try the ComPort Component.
You will find it at: http://www.winsoft.sk
Regards,
gtokas.
P.S. As I understand you know how to make an NT Service.
0
 

Author Comment

by:T0masz
ID: 10932734
Whats the advantage of using the commercial version? and Nope I have no clue how to make a service in delphi 7...

Tom
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:George Tokas
ID: 10938940
The advantage is that it is a component added at Delphi's system tab and you don't need to hard code.
As I recall(I don't use Delphi, I use BCB) there is a "NTservice project wizard" at the "New" dialog in Delphi.
Also there are many examples on how to implement a NTService with Delphi. Borland community have some i.e.

gtokas
0
 

Author Comment

by:T0masz
ID: 10941846
Well I might aswell use SerialNG, its a component, I just have no clue how to get it to print every single line to a window/file. As for the service Delphi 7 has no such thing as NTService in the project wizard, There is "Service" or "Service Application" would that be it? OK I guess Service Application is what Im looking for. Ill browse thru the samples from serialng and see what I can come up.

Thanks
Tom
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 10941940
Yes that is what you are looking for.
I'm not familiar with SerialNG so I can't help you.
On the other hand I have extensive expierience with ComPort.

gtokas.
0
 

Author Comment

by:T0masz
ID: 10942228
http://www.domis.de/cms/index.php?module=ContentExpress&func=display&ceid=8
From what I understand I can either read it char by char or as a cluster, the cluster doesnt really work for me cuz Im not looking for size. So onrxcharevent i would have to check if its \n if yes, write to file, if not add onto the string. Is that a good solution? does comport offer a better solution? onreadline even or something?

Tom
0
 

Author Comment

by:T0masz
ID: 10942614
public string ReadUntil(char terminator);

Reads a string of characters, terminated by specified character, from the communication device. Waits for received data, if its needed.

I guess ComPort has what Im looking for, but Ill try to work with serialng for now
here is a question I asked about serialng
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20971167.html

Tom
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 10942688
Below is the example for Delphi6 for ComPort. I think you can find it helpfull.

unit UDemo;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComPort, StdCtrls, Buttons, ComCtrls;

type
  TFormComPort = class(TForm)
    Edit: TEdit;
    ComPort: TComPort;
    Memo: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    ComboBoxBaudRate: TComboBox;
    ComboBoxDataBits: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    ComboBoxStopBits: TComboBox;
    ComboBoxParity: TComboBox;
    SpeedButtonOpenClose: TSpeedButton;
    SpeedButtonSend: TSpeedButton;
    ComboBoxDeviceName: TComboBox;
    StatusBar: TStatusBar;
    SpeedButtonSetRTS: TSpeedButton;
    SpeedButtonClearRTS: TSpeedButton;
    SpeedButtonSetDTR: TSpeedButton;
    SpeedButtonClearDTR: TSpeedButton;
    procedure ComPortRxChar(Sender: TObject);
    procedure SpeedButtonOpenCloseClick(Sender: TObject);
    procedure ComboBoxBaudRateChange(Sender: TObject);
    procedure ComboBoxDataBitsChange(Sender: TObject);
    procedure ComboBoxStopBitsChange(Sender: TObject);
    procedure ComboBoxParityChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButtonSendClick(Sender: TObject);
    procedure ComboBoxDeviceNameChange(Sender: TObject);
    procedure ComPortError(ComPort: TCustomComPort; E: EComError;
      var Action: TComAction);
    procedure ComPortLineError(Sender: TObject; LineErrors: TLineErrors);
    procedure ComPortCTSChange(Sender: TObject);
    procedure ComPortDSRChange(Sender: TObject);
    procedure ComPortRing(Sender: TObject);
    procedure ComPortRLSDChange(Sender: TObject);
    procedure ComPortAfterWrite(Sender: TObject; Buffer: Pointer;
      Length: Integer; WaitOnCompletion: Boolean);
    procedure SpeedButtonSetRTSClick(Sender: TObject);
    procedure SpeedButtonClearRTSClick(Sender: TObject);
    procedure SpeedButtonClearDTRClick(Sender: TObject);
    procedure SpeedButtonSetDTRClick(Sender: TObject);
  private
    { Private declarations }
    FReadCount: Integer;
    FWriteCount: Integer;
    procedure SetModemStatus;
    procedure AddReadBytes(ReadCount: Integer);
    procedure AddWriteBytes(WriteCount: Integer);
  public
    { Public declarations }
  end;

var
  FormComPort: TFormComPort;

implementation

{$R *.DFM}

procedure TFormComPort.SpeedButtonSendClick(Sender: TObject);
begin
  ComPort.WriteString(Edit.Text + #13);
end;

procedure TFormComPort.ComPortRxChar(Sender: TObject);
var Text: String;
begin
  Text := ComPort.ReadString;
  Memo.SelText := Text;
  AddReadBytes(Length(Text));
end;

procedure TFormComPort.SpeedButtonOpenCloseClick(Sender: TObject);
begin
  with ComPort do
  begin
    Active := not Active;

    if Active then
      SpeedButtonOpenClose.Caption := 'Close'
    else
      SpeedButtonOpenClose.Caption := 'Open';

    Memo.Enabled := Active;
    Edit.Enabled := Active;
    SpeedButtonSend.Enabled := Active;
    ComboBoxDeviceName.Enabled := not Active;
    SetModemStatus;
  end;
end;

procedure TFormComPort.ComboBoxDeviceNameChange(Sender: TObject);
begin
  ComPort.DeviceName := ComboBoxDeviceName.Text;
end;

procedure TFormComPort.ComboBoxBaudRateChange(Sender: TObject);
begin
  ComPort.BaudRate := TBaudRate(ComboBoxBaudRate.ItemIndex);
end;

procedure TFormComPort.ComboBoxDataBitsChange(Sender: TObject);
begin
  ComPort.DataBits := TDataBits(ComboBoxDataBits.ItemIndex);
end;

procedure TFormComPort.ComboBoxStopBitsChange(Sender: TObject);
begin
  ComPort.StopBits := TStopBits(ComboBoxStopBits.ItemIndex);
end;

procedure TFormComPort.ComboBoxParityChange(Sender: TObject);
begin
  ComPort.Parity := TParity(ComboBoxParity.ItemIndex);
end;

procedure TFormComPort.FormCreate(Sender: TObject);
begin
  ComboBoxBaudRate.ItemIndex := 0;
  ComboBoxDataBits.ItemIndex := 0;
  ComboBoxStopBits.ItemIndex := 0;
  ComboBoxParity.ItemIndex := 0;
  AddReadBytes(0);
  AddWriteBytes(0);
  SetModemStatus;
end;

procedure TFormComPort.ComPortError(ComPort: TCustomComPort; E: EComError;
  var Action: TComAction);
begin
  MessageDlg('Error ' + IntToStr(E.ErrorCode) + ': ' + E.Message, mtError, [mbOK], 0);
  Action := caAbort;
end;

procedure TFormComPort.ComPortLineError(Sender: TObject;
  LineErrors: TLineErrors);
begin
  if leBreak in LineErrors then MessageDlg('Break detected', mtError, [mbOK], 0);
  if leDeviceNotSelected in LineErrors then MessageDlg('Device not selected', mtError, [mbOK], 0);
  if leFrame in LineErrors then MessageDlg('Frame error', mtError, [mbOK], 0);
  if leIO in LineErrors then MessageDlg('IO error', mtError, [mbOK], 0);
  if leMode in LineErrors then MessageDlg('Mode error', mtError, [mbOK], 0);
  if leOutOfPaper in LineErrors then MessageDlg('Out of paper', mtError, [mbOK], 0);
  if leOverrun in LineErrors then MessageDlg('Overrun error', mtError, [mbOK], 0);
  if leDeviceTimeOut in LineErrors then MessageDlg('Device timeout', mtError, [mbOK], 0);
  if leRxOverflow in LineErrors then MessageDlg('Receiver overflow', mtError, [mbOK], 0);
  if leParity in LineErrors then MessageDlg('Parity error', mtError, [mbOK], 0);
  if leTxFull in LineErrors then MessageDlg('Transmitter full', mtError, [mbOK], 0);
end;

procedure TFormComPort.SetModemStatus;
var ModemStatus: TModemStatus;
begin
  if not ComPort.Active then
  begin
    StatusBar.Panels[2].Text := 'CTS:';
    StatusBar.Panels[3].Text := 'DSR:';
    StatusBar.Panels[4].Text := 'Ring:';
    StatusBar.Panels[5].Text := 'RLSD:';
  end
  else
  begin
    ModemStatus := ComPort.ModemStatus;

    if msCTS in ModemStatus then
      StatusBar.Panels[2].Text := 'CTS: On'
    else
      StatusBar.Panels[2].Text := 'CTS: Off';

    if msDSR in ModemStatus then
      StatusBar.Panels[3].Text := 'DSR: On'
    else
      StatusBar.Panels[3].Text := 'DSR: Off';

    if msRing in ModemStatus then
      StatusBar.Panels[4].Text := 'Ring: On'
    else
      StatusBar.Panels[4].Text := 'Ring: Off';

    if msRLSD in ModemStatus then
      StatusBar.Panels[5].Text := 'RLSD: On'
    else
      StatusBar.Panels[5].Text := 'RLSD: Off';
  end;
end;

procedure TFormComPort.ComPortCTSChange(Sender: TObject);
begin
  SetModemStatus;
end;

procedure TFormComPort.ComPortDSRChange(Sender: TObject);
begin
  SetModemStatus;
end;

procedure TFormComPort.ComPortRing(Sender: TObject);
begin
  SetModemStatus;
end;

procedure TFormComPort.ComPortRLSDChange(Sender: TObject);
begin
  SetModemStatus;
end;

procedure TFormComPort.AddReadBytes(ReadCount: Integer);
begin
  FReadCount := FReadCount + ReadCount;
  StatusBar.Panels[0].Text := 'Read bytes: ' + IntToStr(FReadCount);
end;

procedure TFormComPort.AddWriteBytes(WriteCount: Integer);
begin
  FWriteCount := FWriteCount + WriteCount;
  StatusBar.Panels[1].Text := 'Write bytes: ' + IntToStr(FWriteCount);
end;

procedure TFormComPort.ComPortAfterWrite(Sender: TObject; Buffer: Pointer;
  Length: Integer; WaitOnCompletion: Boolean);
begin
  AddWriteBytes(Length);
end;

procedure TFormComPort.SpeedButtonSetRTSClick(Sender: TObject);
begin
  ComPort.SetRTS;
end;

procedure TFormComPort.SpeedButtonClearRTSClick(Sender: TObject);
begin
  ComPort.ClearRTS;
end;

procedure TFormComPort.SpeedButtonSetDTRClick(Sender: TObject);
begin
  ComPort.SetDTR;
end;

procedure TFormComPort.SpeedButtonClearDTRClick(Sender: TObject);
begin
  ComPort.ClearDTR;
end;

end.

Regards,
gtokas.
0
 

Author Comment

by:T0masz
ID: 11007710
uciaport did the trick, it had everything I needed.

Tom
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11248156
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
tenRun challenge 28 81
canBalance challenge 34 65
sumHeights  challenge 17 61
changeXy challenge 13 58
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now