Forum: Ruby Win32 Serial Communications, maybe using mscomm.ocx

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John J. (Guest)
on 2006-04-18 19:33
(Received via mailing list)
Hello All,

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

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

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.
Luis L. (Guest)
on 2006-04-19 03:39
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 :-P

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 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!
>
> <terse>
> I'm looking for examples of using the mscomm control with this code:
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...
> </terse>
>
> 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.
John J. (Guest)
on 2006-04-19 17:32
(Received via mailing list)
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 :-P
> 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.
>> <terse>
>> need to speed things up. At 4 seconds a label, a couple of thousand
>>
> Posted via http://www.ruby-forum.com/.
>
>

---
Help everyone. If you can't do that, then at least be nice.
Luis L. (Guest)
on 2006-04-19 18:13
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
Eli B. (Guest)
on 2006-04-19 18:34
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

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
Dave B. (Guest)
on 2006-04-20 18:59
(Received via mailing list)
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
>
> 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
This topic is locked and can not be replied to.