COM4

Myn

Myn

Associate
Joined
31 Mar 2011
Posts
73
Location
Bath, UK
After a somewhat ambiguous title:

I've just inherited a program in VB, a language I have no experience in, which apparently opens a serial port to COM4, and listens for incoming data. This data should be being generated by a hastily put-together box which is plugged in via USB. The program, however, isn't finding any.

How can I check whether any data is incoming on the COM4 port?

Thanks in advance
 
The latter, just listening for data.

I'll give HyperTerminal a try when I'm back in the office tomorrow, thanks :)
 
I'm running Windows 7, so have downloaded HyperTerminal from hilgraeve.net, but am having trouble setting it up to listen for COM4, would you mind if I'm a pain and ask how I might do that? :)
 
In HyperTerminal you should just be able to go File-->New, give it a name (doesn't matter what), then select COM4 and hit OK. Then just select the correct baud rate settings (although for virtual COM ports, sometimes the baud doesn't actually matter) and you should be all set.

This is the part giving me trouble; when I go to File > New, I'm asked to select a name and icon, then asked for an address, port, and a choice of TCP (Winsock) or TCP (SSH). Can't find anything about COM4 :-/

Thanks again for all the help you're giving! You're a lifesaver!
 
Took a while as Ports (COM & LPT) wasn't showing, but just got it appearing; unfortunately nothing new appearing when the box is plugged in!
 
Yeah, I've got one of the Electrical Engineers looking at the box today.

I've been going through the code again and found that it originally tries to open serial port COM4:
Code:
SerialPort1.PortName = TextBox2.Text
Try
   SerialPort1.Open()
   TextBox1.Text = SerialPort1.PortName
Catch ex As Exception
   MsgBox("Caught")
End Try
This always throws an exception, and later on sends data to the port before listening for a response:
Code:
SerialPort1.Write("S")
...
data_a = SerialPort1.ReadByte()

It's just always crashing at SerialPort1.Open(), so is the problem that there is no port to open?

Isn't it great when someone comments code and gives useful variable names?... :)

Thanks again for all the help!
 
I don't know VB but MsgBox("Caught") isn't useful - at the very least change it to include the Exception message. I agree that it will almost certainly be because it can't open COM4 though.

Stupid question time - do you still have COM4 open in Hyperterm? Only one process can have a COM port open at the same time, so Hyperterm will lock any COM port it has open.

Did we establish if COM4 is a physical or a virtual one? If it's virtual then you should be able to virtually connect it to another COM port and test communications that way. If it's a physical COM port I'd suggest getting a null modem cable made up, connect COM4 to a different COM port, open both COM ports up in Hyperterm and test that you can actually send and receive both ways.

Also worth checking what TextBox2.Text is and check it contains the right value for the API.

I've already changed the exception message, it says Port COM4 does not exist.

HyperTerm never had it open in the first place; it couldn't find it.

I've retrieved a list of all serial port names available in VB; I've had the program take each one from the list and immediately try connecting to it, but each time returns with a message saying the port does not exist.

At the moment, it's only returning one value each time, which is COM5, or variations such as COM53, COM5M, etc.
 
All fixed! Turns out it was a driver issue; I'd been given incorrect drivers for our box. /facepalm

The moment I installed them, I plugged the device in and there it was on COM4.

Thanks for all the help guys!
 
Back
Top Bottom