Hyperterminal Command to RS232 via Visual Basic


Thread Starter


I am attempting to write a code in VB to send a command to my RS232 attached pyrometer. I have the com port settings correct, but I need to know how to send the hyperterminal command "*X04" in visual basic and receive the output of the pyrometer in VB after the "*X04" command is sent.


Ken Emmons Jr.

I'll assume you are using VB.net and not the older VB6...

The serial port object has readline and writeline capabilities (not sure the exact method names... Start typing the method call and visual studio will pull up the different method options...). Look up how these work, either using google search or through MSDN documents. There is a way to do timeouts with the readline call that is helpful so that your application doesn't sit there waiting for a response if, for example, someone unplugged the cable, etc. I have done this with C# and the method calls should be almost identical.

If your command is dynamic, i.e. based on runtime information, you will need to manipulate the string that gets sent before you issue the writeline method.

The only other thing to note is that you can specify the end of line character that is sent with writeline and what is expected as end of line character for readline. Most systems/instruments expect and send one of these at the end of the response: <CR> or <CR+LF>

I'm using Visual Basic 6 and the current code I have can set Com port settings correctly, but it is unable to send the "*X04" to the pyrometer. My current VB6 code to send the command is

MSComm1.Output = "*X04" + Chr(13)

What might be wrong with this?