Serial Port Component For Lazarus Syndrome

Active6 years, 3 months ago

Join the GUI Generation: QTCreator. More and more projects require a software component these days. Here’s a bit of code that fills in a combo box with the available serial. Yes, also send me special offers about products & services regarding: JavaScript is required for this form. 5dpo Component Library for Lazarus (Sdpo) provides a comport (serial port) component, an UVC video driver component for webcams, a Gtk fast painting form and a Joystick component.

Symptoms

I have a problem in Delphi 2010. I would like to send from my PC some Unicode (16 bits) characters to the printer with serial port (COM port).I use the TCiaComPort component in D2010.

For example:

Lazarus Syndrome Medical

If the printer characterset is ASCII then the characters arrive, but the ciril character is '?' on the Printer screen. But if the printer characterset is Unicode then the characters do not arrive to the printer.

An Unicode character represented in 2 bytes. How can I decompose an Unicode character to byte for byte? For example #$0002?And how can I send this strings byte for byte with the comport? Which function?

TLama
66.2k15 gold badges168 silver badges306 bronze badges
user2363754user2363754

2 Answers

Under Windows (check your OS how to open and write to comm ports), I use the following function to write a UnicodeString to a COMM Port: Bear in mind that the port have to be setup correctly, baud rate, number of bits, etc. See Device Manager => Comm Ports

Syndromeja_mesaja_mesa
1,8231 gold badge8 silver badges6 bronze badges
Serial Port Component For Lazarus Syndrome

Does CiaComPort1.SendStr() accept an AnsiString or UnicodeString as input? Did you try using a COM port sniffer to make sure that CiaComPort is transmitting the actual Unicode bytes as you are expecting?

The fact that you are using #$0002 and #$0003 makes me think it is actually not, because those characters are usually transmitted on COM ports as 8-bit values, not as 16-bit values. If that is the case, then that would explain why the Ж character is getting converted to ?, if CiaComPort is performing a Unicode->Ansi data conversion before transmitting. In which case, you may have to do something like this instead:

However, if CiaComPort is actually performing a data conversion internally, then you will still run into conversion issues for any encoded bytes that are above $7F.

In which case, look to see if CiaComPort has any other sending methods available that allow you to send raw bytes instead of strings. If it does not, then you are pretty much SOL and will need to switch to a better COM component, or just use OS APIs to access the COM port directly instead.

Remy LebeauRemy Lebeau

Lazarus Component Library

361k21 gold badges287 silver badges488 bronze badges

Serial Port Component For Lazarus Syndrome

Not the answer you're looking for? Browse other questions tagged delphidelphi-2010 or ask your own question.