Wednesday, November 18, 2015

MsComm32 with error "Port already Open" on Windows XP

I post this article as I can't find the solution on Internet. I hope this article can help anybody who has same issue with me.

Few days ago, I had an issue to send output to Werma LED light on Windows XP. It works perfectly on Windows 7. I can say that Windows XP is more fussy than Windows 7. I need to change few codes to fit to Windows XP's requirement.

One of the issue when trigger the light by using mscomm32.ocx is that the light will turn ON on the first time and can't be turned ON afterward. If you try to keep turning ON the light, there is error 8005 - Port already Open.

Trying to turn ON and OFF the light from Hyperterminal and Putty is OK. After further investigation and helped from other colleagues, we found out that Windows XP can't accept Carriage Return and Line Feed. It only accept Carriage Return on output command. Windows 7 can accept and work perfectly.

Windows XP
Chr := 13;
CRLF := FORMAT(Chr);

...
mscomm. Output = 'WR 00 01 01 64' + CRLF;

...


Windows 7
Chr := 13;
CRLF := FORMAT(chr);
Chr := 10;
CRLF := CRLF + FORMAT(Chr)

...
mscomm. Output = 'WR 00 01 01 64' + CRLF;

...

Windows 7 can accept both type of above coding :)

No comments:

Post a Comment