Serial Port Mscomm
I'm using VB Pro 6.0 on WinXP platform (SP1). I'm attempting to communicate with a piece of hardware over an RS-232 connection. I'm doing this via the MSComm control.
This is the snippet Send/Receive Data Via the Serial Port Using MSComm Control on FreeVBCode. The FreeVBCode site provides free Visual Basic code, examples, snippets. Serial port communication using MSComm control - posted in Ask for Help: Can someone please help me in implementing serial port communication using the MSComm control.
The com port is supposed to power the hardware, and that seems to work to a certain extent (an LED lights on the hardware when I open the port). However, when I query the device, I get no response on 2000/XP. However, everything works fine under Win98/ME.
It looks like the NT platforms handle something differently. I've set the Set DTREnable and RTSEnable flags to True at design time, and handshaking is turned off. I've had someone indicate to me that the problem may be the following: 'This may be due to MS driver waiting for CTS or DSR? There should be a way of turning on the RTS/DTR without the software looking for CTS/DSR if that is the source of the problem.'
How can you do this using the MSComm control? Age Empires Age King. Is it even possible?
Thanks in advance for any help! They are not the same machines, but it's not a problem with the port.
It's definitely an OS issue. I've reproduced this on several machines with various OS's to try and determine what's causing it. I know the ports work fine, because I wrote a simulator app that pretends to be the hardware, and I can communicate with it fine (using NULL modem connection) It's only when communicating with the real hardware that the problem occurs. It seems as though it's not getting enough power. Need a serial com guru:-) -jb. I checked the code. Actually, I was receiving mode OnComm events than received bytes.
That is: I expected 1024 bytes, and I received more events than this. This happened only on 2000 systems, and in 9x it worked fine. Anyway, here is the code: put this in Form_Load: ' This is the length of the string that I expect to receive SerBufLen = 1024 With SerPort.CommPort = MainWindow.COMPort.RThreshold = SerBufLen.Settings = '9600,n,8,1'.PortOpen = True End With and the _OnComm event: Private Sub SerPort_OnComm() Dim V As Variant With SerPort If.CommEvent = 2 And.InBufferCount >= SerBufLen Then V =.Input ParseInput V End If End With End Sub Hope this helps. The handshaking actually depends on the hardware device you are talking to. The hardware people should tell you if the need HW handshaking (RTS / CTS ) or SW handshaking (XON / XOFF). Then, you have to set the corresponding property of your MSComm control. If you are unsure about CTS (Clear To Send), have a look at this property: (from MSDN) CTSHolding Property Determines whether you can send data by querying the state of the Clear To Send (CTS) line.