Determine Serial Port Settings

I am writing an application which is basically acting as a keyboard wedge.  The data is coming from a custom keyboard through RS232 to USB and into my PC.  Im just wondering if there is a clever way to determine  the correct settings for my MSComm control.  As these keyboards are abit specialist and Im not sure who would know what baud rate etc the keyboard is outputting.  I currently have the MSComm settings below but I find that some strings come through fine (F014 for instance), some are truncated (Cursor L becomes more like Curso) and some need multiple keypresses (Pressing the number 7 does nothing but if I do 7, 8, 9 then on the 9 being pressed all three numbers arrive at the other end.)  

Incidentally I have been getting a preceding character (a small square) before the the expected string.  Whats that all about?  Ive been stripping this out of the string in my code but should I be using that better?

DRTEnable = True
EOFEnable = False
Handshaking 2- comRTS
InBufferSize = 1024
InputMode = 0 - comInputModeText
NullDiscard False
OutBufferSize = 512
ParityReplace = ?
RThreshold = 0
RTSEnable = True
Settings = 115200,n,8,1
SThreshold = 0
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It sounds to me like you may have the correct comm port settings. Otherwise the data you are getting would probably be less consistent.
"Pressing the number 7 does nothing but if I do 7, 8, 9 then on the 9 being pressed all three numbers arrive at the other end" - this is not at all consistent with incorrect comm port settings.
The small square sounds like a character which can't be displayed.
What sort of RS-232 KB is it?
115,200 does seem very fast. Normally a KB would be 9,600 or 19,200.

Have you tried using HyperTerm to display what is coming in from the KB? You should do this. If the settings are correct the data will display as soon as you press a key on the KB. You can quickly and easily experiment with different comm port settings until you find the right ones.

I would try no hardware handshaking, no parity, 8 data bits, 1 stop bit and 9600 baud. Then try all the different baud rates. If that doesn't work then try even parity at all baud rates then odd parity at all baud rates.  You definitely want to leave handshaking off. It is very likely that 8 data bits and 1 stop bit will be correct.

Other that getting documentation for your KB there is no easy way to do this.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simonwaitAuthor Commented:

I tried hyperterminal and found that the leading character on there was some sort of smiley face.  So on here with my original settings I seem to get a result as expected whenever a keypress is made (well if you accept the random character).  Here is a screenshot of what I saw when I hit 1,2,3,4,5,6,7,8,9,0 then the four cursor keys and then 3 function keys once in succession. Hyperterminal Output
So It does indeed appear to be something is up with my mscomm control doesnt it?
No, it looks perfect to me.
The KB is outputting more than a single character when each key is pressed.
The smiley face is a CHR(2) - STX or start of text. That makes sense. There may be others there we can't see.
In HyperTerm select Transfer->Capture Text, then press each key on the KB. That will save the output to a file. You can then look at the content of the file to work out exactly what's going on.
Post the file here if you like and I will take a look at it for you.
What settings are you using?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

simonwaitAuthor Commented:
Here is the file you suggested I capture with every button being pressed.  It was using a virtual version of the physical keyboard because Im not anywhere near that.  The virtual version was written in VB6 with an mscomm control but seems to act exactly the same as the real keyboard when looking at this problem.

I then tried setting my virtual keyboard to 115200 but leaving hyperterminal at 9600 and still got the same results (albeit I didnt do all the keys).  Im not sure if this adds any more information to helping with this but I found it odd that the 2 still communicated OK when at completely different bauds.
OK. Every key pressed starts with STX character (ascii 2) then a string to represent which key was pressed.
I'd suggest that the speed of the virtual keyboard is fixed at 9600, even if you change the setting - no sure why.
9600 is pretty standard for this type of device.
It is unusual that there is no ETX character (ascii 3) after the string. I'm wondering if the emulator isn't perfect. Can you test this with the actual KB?
simonwaitAuthor Commented:
I can but just not for a few days until I go and visit the site again maybe next week.  Thanks for your help so far.
You're welcome. I'll keep my eye out for your next post and try to be of assistance if I can. Please post another HyperTerm capture file of the actual KB and we should be able to sort it out.
simonwaitAuthor Commented:

So I have discovered that the keyboard seems to be split into two sections, the majority of the buttons output this STX character however the numeric keys don't.  In my VB code I was assuming the character was always there and was stripping it out which was causing the code to exit the sub.  This seems easy enough to resolve.  One thing I still find though is that the MSComm control does not trigger the oncomm even on the first numeric key press.  This seems to be linked to the RThreshold value.  If it is set to a low number then it will take 3 keypresses to trigger.  increasing this then means more keypresses.  The instant answer to this is to keep the number to 1 but then this truncates longer strings received.
simonwaitAuthor Commented:
Sorry I forgot to include the capture.
Hi Simon,
It appears that every key is a predefined character or set of characters. Some of them start with Chr(2) and some don't. You will need to write your program is such a way that it receives the entire string from the keyboard before processing it. You will need a table of all possibilities. I will leave the logic to you. You will need to start a new question if you need assistance with this.
simonwaitAuthor Commented:

Yeah I have got the fact that sometimes there is the Chr(2) and sometimes not (this was actually very easy as the code assumed the character was there and would exit if not.  Not it just strips it out and carries on).  My bigger issue is still though the fact that I sometimes either loose part of the string or have to do mutiple presses (depending on the RTheshold value.)  If I set it to trigger oncomm with a single character then longer words are truncated and if II set it higher I dont see shorter strings.  I think part of the problem is that there is no consistent last character to look for.
Hi Simon,
I think I have answered your original question and then some. I think you should post the current issue as a separate question.
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.