T0masz
asked on
Serial port dumper as service
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
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
ASKER
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
Tom
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
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
ASKER
The serial components dont work for delphi 7 and thats the only one I have...
Thanks for your help.
Tom
Thanks for your help.
Tom
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 ?
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 ?
ASKER
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
Tom
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.
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.
ASKER
Whats the advantage of using the commercial version? and Nope I have no clue how to make a service in delphi 7...
Tom
Tom
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
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
ASKER
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
Thanks
Tom
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.
I'm not familiar with SerialNG so I can't help you.
On the other hand I have extensive expierience with ComPort.
gtokas.
ASKER
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
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
ASKER
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
https://www.experts-exchange.com/questions/20971167/SerialNG-read-a-line.html
Tom
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
https://www.experts-exchange.com/questions/20971167/SerialNG-read-a-line.html
Tom
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(Sen der: TObject);
procedure ComboBoxDataBitsChange(Sen der: TObject);
procedure ComboBoxStopBitsChange(Sen der: TObject);
procedure ComboBoxParityChange(Sende r: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButtonSendClick(Sende r: TObject);
procedure ComboBoxDeviceNameChange(S ender: 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(Sen der: TObject);
procedure SpeedButtonClearRTSClick(S ender: TObject);
procedure SpeedButtonClearDTRClick(S ender: TObject);
procedure SpeedButtonSetDTRClick(Sen der: 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.SpeedButtonSe ndClick(Se nder: TObject);
begin
ComPort.WriteString(Edit.T ext + #13);
end;
procedure TFormComPort.ComPortRxChar (Sender: TObject);
var Text: String;
begin
Text := ComPort.ReadString;
Memo.SelText := Text;
AddReadBytes(Length(Text)) ;
end;
procedure TFormComPort.SpeedButtonOp enCloseCli ck(Sender: TObject);
begin
with ComPort do
begin
Active := not Active;
if Active then
SpeedButtonOpenClose.Capti on := 'Close'
else
SpeedButtonOpenClose.Capti on := 'Open';
Memo.Enabled := Active;
Edit.Enabled := Active;
SpeedButtonSend.Enabled := Active;
ComboBoxDeviceName.Enabled := not Active;
SetModemStatus;
end;
end;
procedure TFormComPort.ComboBoxDevic eNameChang e(Sender: TObject);
begin
ComPort.DeviceName := ComboBoxDeviceName.Text;
end;
procedure TFormComPort.ComboBoxBaudR ateChange( Sender: TObject);
begin
ComPort.BaudRate := TBaudRate(ComboBoxBaudRate .ItemIndex );
end;
procedure TFormComPort.ComboBoxDataB itsChange( Sender: TObject);
begin
ComPort.DataBits := TDataBits(ComboBoxDataBits .ItemIndex );
end;
procedure TFormComPort.ComboBoxStopB itsChange( Sender: TObject);
begin
ComPort.StopBits := TStopBits(ComboBoxStopBits .ItemIndex );
end;
procedure TFormComPort.ComboBoxParit yChange(Se nder: TObject);
begin
ComPort.Parity := TParity(ComboBoxParity.Ite mIndex);
end;
procedure TFormComPort.FormCreate(Se nder: 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.ComPortLineEr ror(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.SetModemStatu s;
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.ComPortCTSCha nge(Sender : TObject);
begin
SetModemStatus;
end;
procedure TFormComPort.ComPortDSRCha nge(Sender : TObject);
begin
SetModemStatus;
end;
procedure TFormComPort.ComPortRing(S ender: TObject);
begin
SetModemStatus;
end;
procedure TFormComPort.ComPortRLSDCh ange(Sende r: 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 (WriteCoun t: Integer);
begin
FWriteCount := FWriteCount + WriteCount;
StatusBar.Panels[1].Text := 'Write bytes: ' + IntToStr(FWriteCount);
end;
procedure TFormComPort.ComPortAfterW rite(Sende r: TObject; Buffer: Pointer;
Length: Integer; WaitOnCompletion: Boolean);
begin
AddWriteBytes(Length);
end;
procedure TFormComPort.SpeedButtonSe tRTSClick( Sender: TObject);
begin
ComPort.SetRTS;
end;
procedure TFormComPort.SpeedButtonCl earRTSClic k(Sender: TObject);
begin
ComPort.ClearRTS;
end;
procedure TFormComPort.SpeedButtonSe tDTRClick( Sender: TObject);
begin
ComPort.SetDTR;
end;
procedure TFormComPort.SpeedButtonCl earDTRClic k(Sender: TObject);
begin
ComPort.ClearDTR;
end;
end.
Regards,
gtokas.
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(
procedure ComboBoxBaudRateChange(Sen
procedure ComboBoxDataBitsChange(Sen
procedure ComboBoxStopBitsChange(Sen
procedure ComboBoxParityChange(Sende
procedure FormCreate(Sender: TObject);
procedure SpeedButtonSendClick(Sende
procedure ComboBoxDeviceNameChange(S
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(Sen
procedure SpeedButtonClearRTSClick(S
procedure SpeedButtonClearDTRClick(S
procedure SpeedButtonSetDTRClick(Sen
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.SpeedButtonSe
begin
ComPort.WriteString(Edit.T
end;
procedure TFormComPort.ComPortRxChar
var Text: String;
begin
Text := ComPort.ReadString;
Memo.SelText := Text;
AddReadBytes(Length(Text))
end;
procedure TFormComPort.SpeedButtonOp
begin
with ComPort do
begin
Active := not Active;
if Active then
SpeedButtonOpenClose.Capti
else
SpeedButtonOpenClose.Capti
Memo.Enabled := Active;
Edit.Enabled := Active;
SpeedButtonSend.Enabled := Active;
ComboBoxDeviceName.Enabled
SetModemStatus;
end;
end;
procedure TFormComPort.ComboBoxDevic
begin
ComPort.DeviceName := ComboBoxDeviceName.Text;
end;
procedure TFormComPort.ComboBoxBaudR
begin
ComPort.BaudRate := TBaudRate(ComboBoxBaudRate
end;
procedure TFormComPort.ComboBoxDataB
begin
ComPort.DataBits := TDataBits(ComboBoxDataBits
end;
procedure TFormComPort.ComboBoxStopB
begin
ComPort.StopBits := TStopBits(ComboBoxStopBits
end;
procedure TFormComPort.ComboBoxParit
begin
ComPort.Parity := TParity(ComboBoxParity.Ite
end;
procedure TFormComPort.FormCreate(Se
begin
ComboBoxBaudRate.ItemIndex
ComboBoxDataBits.ItemIndex
ComboBoxStopBits.ItemIndex
ComboBoxParity.ItemIndex := 0;
AddReadBytes(0);
AddWriteBytes(0);
SetModemStatus;
end;
procedure TFormComPort.ComPortError(
var Action: TComAction);
begin
MessageDlg('Error ' + IntToStr(E.ErrorCode) + ': ' + E.Message, mtError, [mbOK], 0);
Action := caAbort;
end;
procedure TFormComPort.ComPortLineEr
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.SetModemStatu
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.ComPortCTSCha
begin
SetModemStatus;
end;
procedure TFormComPort.ComPortDSRCha
begin
SetModemStatus;
end;
procedure TFormComPort.ComPortRing(S
begin
SetModemStatus;
end;
procedure TFormComPort.ComPortRLSDCh
begin
SetModemStatus;
end;
procedure TFormComPort.AddReadBytes(
begin
FReadCount := FReadCount + ReadCount;
StatusBar.Panels[0].Text := 'Read bytes: ' + IntToStr(FReadCount);
end;
procedure TFormComPort.AddWriteBytes
begin
FWriteCount := FWriteCount + WriteCount;
StatusBar.Panels[1].Text := 'Write bytes: ' + IntToStr(FWriteCount);
end;
procedure TFormComPort.ComPortAfterW
Length: Integer; WaitOnCompletion: Boolean);
begin
AddWriteBytes(Length);
end;
procedure TFormComPort.SpeedButtonSe
begin
ComPort.SetRTS;
end;
procedure TFormComPort.SpeedButtonCl
begin
ComPort.ClearRTS;
end;
procedure TFormComPort.SpeedButtonSe
begin
ComPort.SetDTR;
end;
procedure TFormComPort.SpeedButtonCl
begin
ComPort.ClearDTR;
end;
end.
Regards,
gtokas.
ASKER
uciaport did the trick, it had everything I needed.
Tom
Tom
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.cpcug.org/user/clemenzi/technical/Languages/Delphi/Delphi_SerialIO.htm
http://www.programmersheaven.com/zone2/cat55/