Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-07

Strange behaviour sending data to a serial port.

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Hi,

I have approached the Synapse mailing list with this problem, but have had no response, so it may be a Lazarus issue.

In any case, maybe someone can suggest a work-around....

I have used the following code to send data to a serial printer using the TBlockSerial synapse variable.

var ser:TBlockSerial;
  ser:=TBlockserial.Create;
  try
    ser.RaiseExcept:=True;
    ser.Connect('COM1');
    ser.Config(9600,8,'N',0,false,false);
    ser.SendString('Invoice: The Galley Restaurant'+#13+#10);
  finally
    ser.Free;
  end;

If I run the above code, there is no response from the printer.

However, if I put a breakpoint into the code and step through it, the printer prints as expected.

Reply by email

Roberto Padovani
to Dave Coventry

2008/7/31 Dave Coventry :

Show quoted text 26 lines
Hi, I have approached the Synapse mailing list with this problem, but have had no response, so it may be a Lazarus issue. In any case, maybe someone can suggest a work-around.... I have used the following code to send data to a serial printer using the TBlockSerial synapse variable. var ser:TBlockSerial; ser:=TBlockserial.Create; try ser.RaiseExcept:=True; ser.Connect('COM1'); ser.Config(9600,8,'N',0,false,false); ser.SendString('Invoice: The Galley Restaurant'+#13+#10); finally ser.Free; end; If I run the above code, there is no response from the printer. However, if I put a breakpoint into the code and step through it, the printer prints as expected.

Hi,
this might be irrelevant and I never used the Synapse routines, but I'll try: are you stepping also into the actual transmitting routine, character by character ?
I am asking this because it is quite strange to see a device thar requires _no_ stop bit, like you configured it:

ser.Config(9600,8,'N',0,false,false);

and by stepping, you might be stopping after each character, so that the device state machine can decode the character. All the devices I have ever seen in the last decade, either PC devices or not, they _need_ exactly 1 stop bit, so an easy shot could be to change it to:

ser.Config(9600,8,'N',1,false,false);

Let me know if it works!

R#

Show quoted text 5 lines
_______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Dave Coventry
to Roberto Padovani

Hi Roberto, thanks for the assistance...

2008/7/31 Roberto Padovani :

Hi, this might be irrelevant and I never used the Synapse routines, but I'll try: are you stepping also into the actual transmitting routine, character by character ?

Placing the breakpoint anywhere prior to the 'end;' of the 'try...finally...end;' block allows the printer to print as expected.

Obviously, the executable can't print.

I am asking this because it is quite strange to see a device thar requires _no_ stop bit, like you configured it: > ser.Config(9600,8,'N',0,false,false);

I took the example in the package and tweaked it slightly for my usage; I' not really sure what parameters I need to pass to the printer, but 9600 for the baud, seemed reasonable, I suppose I could use 7 bits because I am sending ASCII strings, N for the parity because I can't see that parity is required, and the others seemed okay.

Show quoted text 9 lines
and by stepping, you might be stopping after each character, so that the device state machine can decode the character. All the devices I have ever seen in the last decade, either PC devices or not, they _need_ exactly 1 stop bit, so an easy shot could be to change it to: > ser.Config(9600,8,'N',1,false,false); Let me know if it works!

I'm afraid that it makes no difference...

Reply by email

Dave Coventry
to Felipe Monteiro de Carvalho

Thanks Felipe.

2008/7/31 Felipe Monteiro de Carvalho :

The only thing I know is that the code here worked for me: http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communication

That looks interesting; I'll try some experiments.

Maybe the printer needs some time to rest somewhere. Put some Sleep's

:P

Actually, I put in a "showmessage('Printing Complete!');" which did the trick. So it's clearly not a Lazarus issue...

Reply by email

Horacio Jamilis
to Dave Coventry: I have approached the Synapse mailing list with this problem, but have had no response,…

You probably need a "ser.flush" after the ser.SendString, and before destroying the object...

or, if this don?t work, try with a sleep.

Horacio

Dave Coventry escribi?:

Show quoted text 39 lines
Hi, I have approached the Synapse mailing list with this problem, but have had no response, so it may be a Lazarus issue. In any case, maybe someone can suggest a work-around.... I have used the following code to send data to a serial printer using the TBlockSerial synapse variable. var ser:TBlockSerial; ser:=TBlockserial.Create; try ser.RaiseExcept:=True; ser.Connect('COM1'); ser.Config(9600,8,'N',0,false,false); ser.SendString('Invoice: The Galley Restaurant'+#13+#10); finally ser.Free; end; If I run the above code, there is no response from the printer. However, if I put a breakpoint into the code and step through it, the printer prints as expected. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus __________ Informaci?n de NOD32, revisi?n 3302 (20080728) __________ Este mensaje ha sido analizado con NOD32 antivirus system http://www.nod32.com

Reply by email

Dave Coventry
to Felipe Monteiro de Carvalho: The only thing I know is that the code here worked for me:…

Thanks Felipe.

2008/7/31 Felipe Monteiro de Carvalho :

The only thing I know is that the code here worked for me: http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communication

That looks interesting; I'll try some experiments.

Maybe the printer needs some time to rest somewhere. Put some Sleep's

:P

Actually, I put in a "showmessage('Printing Complete!');" which did the trick. So it's clearly not a Lazarus issue...

Reply by email