# Win32 Serial Communications, maybe using mscomm.ocx

**URL:** <https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115>\
**Category:** Ruby\
**Created:** [April 18, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115 "2006-04-18T17:33:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 18, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115/1 "2006-04-18T17:33:18Z")

</div>

Hello All,

It’s good to get back to the RT Mailing List!

I'm looking for examples of using the mscomm control with this code: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35355

I’m working on a project that drives a serial label printer on a  
Windows host.  
I’ve been trying ruby-serialport-0.6 by Guillaume Pierronnet and Alan  
Stern.  
It works as long as no handshaking is needed, i.e. as long as I send  
data slower than the printer can print, it works. The problem is, I  
need to speed things up. At 4 seconds a label, a couple of thousand  
labels a day really adds up (~ 2 hrs).

I found the aforementioned message about using the mscomm control from  
VB, I’m not to well versed on recent Win programming, but I assume this  
is mscomm.ocx.

The code looks good, does anyone know where I can find examples of it’s  
use?

ADVthanksANCE!

Regards,  
JJ

* * *

Help everyone. If you can’t do that, then at least be nice.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 19, 2006, 1:39am UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115/2 "2006-04-19T01:39:57Z")

</div>

John,

I’ll suggest you avoid using mscomm.ocx for many reasons:

First, the overhead of interfacing with OLE/ActiveX/IDispatcher objects  
form plain ruby code.

Second, the microsoft control developer license, forbids its use outside  
any of the VB packages where it was shipped, so you will be “breaking  
the law” using it 😛

Third, why?

Are your serial label using CS and DS control lines for handshake? you  
need to control them from your code to set/get your printer status from  
your code?

for reference, past weeks I needed replace some buggy code from a VB  
project that use MSCOMM control and we found its baddly based on ActiveX  
event-driven model, which isn’t suited for high speed (any speed above  
19200).

We replaced it with a custom dll made with FreeBASIC  
[http://www.freebasic.net](http://www.freebasic.net) and reduced latencies to the minimum, just 30k  
of compiled dll… and solved the problem.

You even could interface it with Ruby using DL.

That just my suggestion of course.

If you need more inside information I’ll glad to provide some guidance.

Regards,

Luis

John J. wrote:

> Hello All,
> 
> It’s good to get back to the RT Mailing List!
> 
> I'm looking for examples of using the mscomm control with this code: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35355
> 
> I’m working on a project that drives a serial label printer on a  
> Windows host.  
> I’ve been trying ruby-serialport-0.6 by Guillaume Pierronnet and Alan  
> Stern.  
> It works as long as no handshaking is needed, i.e. as long as I send  
> data slower than the printer can print, it works. The problem is, I  
> need to speed things up. At 4 seconds a label, a couple of thousand  
> labels a day really adds up (~ 2 hrs).
> 
> I found the aforementioned message about using the mscomm control from  
> VB, I’m not to well versed on recent Win programming, but I assume this  
> is mscomm.ocx.
> 
> The code looks good, does anyone know where I can find examples of it’s  
> use?
> 
> ADVthanksANCE!
> 
> Regards,  
> JJ
> 
> * * *
> 
> Help everyone. If you can’t do that, then at least be nice.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 19, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115/3 "2006-04-19T16:13:16Z")

</div>

John J. wrote:

> Luis,
> 
> Thanks for the suggestions!
> 
> The printer can user DTR or XOn/XOff. The ruby-serialport package  
> doesn’t support DTR on Windows, and the XOn/XOff doesn’t seem to work.  
> The symptom is, when I send labels without a sleep(3.5) between each,  
> it prints the first few, the buffer fills, several labels are dropped,  
> and it continues printing, the cycle repeats.
> 
> I’ll look into FreeBasic. I had downloaded it, but never got around to  
> looking into it. If I could write a DLL or spooler program with it,  
> that would be great.
> 
> Thanks again!
> 
> Regards,  
> JJ  
> So you’re using control lines then… we managed to create a spooler,  
> but for a null-modem (tx-rx only) serial printer.

At which speed are you working? at 19200 we:

Send the command (39 bytes), wait 30ms (the lowest is 15ms, windows  
timer resolution) and get the answer (other 39 bytes).

In our spooler, we don’t need ot feed the answers to the program, so our  
spooler is a linked list of commands and a thread that pop these  
messages and perform the actions…

Sound complicated, but in your ruby side you have  
Spooler::PushMessage(msg) and the dll do everything for you.

Please mail me, I’ll glad to help you with freebasic (it also have a  
nice and colaborative community).

Regards,

Luis

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 19, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115/4 "2006-04-19T16:34:27Z")

</div>

Luis L. wrote:

> John J. wrote:
> 
> > Luis,
> > 
> > Thanks for the suggestions!
> > 
> > The printer can user DTR or XOn/XOff. The ruby-serialport package  
> > doesn’t support DTR on Windows, and the XOn/XOff doesn’t seem to work.  
> > The symptom is, when I send labels without a sleep(3.5) between each,  
> > it prints the first few, the buffer fills, several labels are dropped,  
> > and it continues printing, the cycle repeats.
> > 
> > I’ll look into FreeBasic. I had downloaded it, but never got around to  
> > looking into it. If I could write a DLL or spooler program with it,  
> > that would be great.
> > 
> > Thanks again!

I’d just like to suggest an alternative.

I have to deal with the serial port quite a lot at work, and I’ve  
developed a set of C++ and Perl tools for that. I found controlling the  
serial port via Perl extremely difficult, and ending up coding a socket  
 ↔ serial port bridge in C++ using the excellent CSerial class,  
downloadable from [http://home.ict.nl/~ramklein/Projects/Serial.html](http://home.ict.nl/~ramklein/Projects/Serial.html)

What I now have is a tiny C++ exe (\< 100 Kb) that I call from a script  
and it communicates via a socket, transmitting both ways, acting as a  
gateway.

Perhaps it would be even better to tie it to a .dll

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 19, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115/5 "2006-04-19T15:32:55Z")

</div>

Luis,

Thanks for the suggestions!

The printer can user DTR or XOn/XOff. The ruby-serialport package  
doesn’t support DTR on Windows, and the XOn/XOff doesn’t seem to work.  
The symptom is, when I send labels without a sleep(3.5) between each,  
it prints the first few, the buffer fills, several labels are dropped,  
and it continues printing, the cycle repeats.

I’ll look into FreeBasic. I had downloaded it, but never got around to  
looking into it. If I could write a DLL or spooler program with it,  
that would be great.

Thanks again!

Regards,  
JJ

On 18-Apr-2006, at 19:40, Luis L. wrote:

> the law" using it 😛  
> event-driven model, which isn’t suited for high speed (any speed above  
> If you need more inside information I’ll glad to provide some guidance.
> 
> > need to speed things up. At 4 seconds a label, a couple of thousand
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

* * *

Help everyone. If you can’t do that, then at least be nice.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 20, 2006, 4:59pm UTC](https://www.ruby-forum.com/t/win32-serial-communications-maybe-using-mscomm-ocx/58115/6 "2006-04-20T16:59:08Z")

</div>

Eli B. wrote:

> I have to deal with the serial port quite a lot at work, and I’ve  
> developed a set of C++ and Perl tools for that. I found controlling the  
> serial port via Perl extremely difficult, and ending up coding a socket  
> ↔ serial port bridge in C++ using the excellent CSerial class,  
> downloadable from [http://home.ict.nl/~ramklein/Projects/Serial.html](http://home.ict.nl/~ramklein/Projects/Serial.html)
> 
> What I now have is a tiny C++ exe (\< 100 Kb) that I call from a script  
> and it communicates via a socket, transmitting both ways, acting as a  
> gateway.
> 
> Perhaps it would be even better to tie it to a .dll

Why not use Win32API?

This article demonstrates use of the Windows API in C++, but it’s easily  
translated to Ruby from there.

Cheers,  
Dave
