COM dispatcher strings handling appears not to be binary-safe

5 views
Skip to first unread message

Phil Rhodes

unread,
Jan 4, 2010, 12:55:15 PM1/4/10
to jsl...@googlegroups.com
Hi all.
 
I'm still playing with createComObject, this time with Dick Grier's NETComm activeX control which provides serial port access via an OCX.
 
When I do this:

var serial = createComObject("NETCommOCX.NETComm");
serial.commPort = 0;
serial.RThreshold = 1;
serial.settings = '115200, N, 8, 1';
serial.portOpen = true;
 
for(var i = 1; i < 255; i++){
   serial.output = String.fromCharCode(i);
}
 
... I expect to see 0x00 to 0xFE come out of the serial port. However, what I actually get is as depicted in the attached image. Notice that many values between 0x82 and 0xA0, as well as some others, are actually sent out as 0x3F.
 
I have also tried the following:
 
for(var i = 1; i < 255; i++){
   b = new Buffer();
   p = new Pack(b);
   p.writeInt(i,1);
   serial.output = b.read(1);
}
 
...with the same results.
 
Doing this with cscript.exe and VBscript's binary-safe string handling produces the expected results, so I suspect JSlibs is mishandling the input string somehow.
 
P
serial_jshost.png

soubok

unread,
Jan 4, 2010, 5:26:52 PM1/4/10
to jsl...@googlegroups.com
Hi,

Can you try to write and read the same data to a binary file (I don't
know which COM object to use to test this), and tell me if you
encounter the same issue.
Thanks.

Franck.

> --
> Group jslibs - http://groups.google.com/group/jslibs -
> jsl...@googlegroups.com
> Unsubscribe: jslibs-un...@googlegroups.com

Phil Rhodes

unread,
Jan 5, 2010, 5:41:47 AM1/5/10
to jsl...@googlegroups.com
Hi,

Thanks for looking into this.

Writing to a file works as expected, outputting 0x00-0xFF correctly. Writing
exactly the same data to the OCX produces problems.

My results are attached as a zip file (to prevent email messing up the
formatting). I've included the code I used, dumps from a hex editor looking
at the file output, and the output of a serial port monitor looking at the
serial port output.

I have also made a zip archive containing all the resources necessary to run
this test code, including the OCX and serial port monitor, so that it's easy
to duplicate these results. It's here:

ftp://www.philrhodes.com/public_html/client/soubok/serial-ocx-text.zip (8MB,
includes OCX source code in VB6)

One minor note: if I do this with jscript.exe I have no choice but to do
this:

serial.output = String.fromCharCode(n);

This produces exactly the same problems as jslibs currently has with this:

serial.output = buf.read(1);

We know jscript's string handling is not binary-safe. However jslibs' string
handling is supposed to be binary-safe, which may shed some light on what's
going wrong.

Thanks!

P

serial_ocx_tests.zip
Reply all
Reply to author
Forward
0 new messages