Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mscomm serial port woes

Status
Not open for further replies.

LegoPiece

Programmer
Mar 19, 2001
95
US
Hi Everyone!

I'm trying to read from and write to a serial port from my VB program, and it's errr.. well, it's not exactly working! I dropped an mscomm control onto the form, applied the proper port settings, then opened the port using the .portopen() method. I then used the MSComm1.output to send some text to the port and that resulted in diddly squat. So... I verified that my target device (bar code reader), which the comm port is connected to works by typing in text using HyperTerminal. It worked great... I basically need to send it &quot;LON&quot; <ENTER> to activate the bar code reader. Is there something else I'm supposed to do to make it work?

Thanks!
LeGo PiEcE

&quot;The Computer Spock! Destroy it!&quot; - Captain James T. Kirk
 
Just a couple of ideas. Sending the device one character at a time. I am assuming that you are also sending Ascii 13 for the enter key? Check the handshaking as well and you may want to switch between the binary and string input mode just for kicks. Let me know if any of this works. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Hi foada!

Thanks for the reply - Okay, regarding the string I send to the serial port : I did try to send it one character at a time e.g.

mscomm1.ouput = &quot;L&quot; + &quot;O&quot; + &quot;N&quot; + vbCr

That didn't work... I even applied trim, in case any spaces got sent... e.g.

mscomm1.output = Trim(&quot;LON&quot;) + vbCr

I then tried the vbCrLf, with the above 'send strings', and today, I'll try a couple of different things.

In HyperTerminal, I type &quot;LON&quot; and <Enter>, which activates the bar code reader fine - so technically, if I can capture what the send string is, perhaps I can paste that back into my vb Code?

Thanks again, and I'll give you an update when I try out the 'binary' input mode property toggling! Stay tuned!
Thanks!
LeGo PiEcE

&quot;The Computer Spock! Destroy it!&quot; - Captain James T. Kirk
 
Before you blame the language, you should buy/make a
&quot;null modem&quot; cable and connect up a PC to your original
PC. Try to communicate between the two via HYPERTERMINAL.
If you can't, you know there's something wrong with the
hardware - something independent of VB.
I use VB pro 6.0. A working code for me has been:


MSComm2.Commport = 2 ' Sets &quot;MSComm2&quot; to represent the
' PC's serial port, Com2
MSComm2.Settings = &quot;38400, N, 8, 1&quot;
' 38,400 baud per second
' No parity bit
' 8 data bits
' 1 stop bit
MSComm2.Handshaking = comXonXoff ' Specifies Xon/Xoff
' handshakong
MSComm2.RTSEnable = True ' Required by Xon/Xoff to also
' RECEIVE data.

MSComm2.InputLen = 0

MSComm2.PortOpen = True



 
Dude, I'm not blaming the language - this all all down to operator error, I accept that, hence me being here. But to reiterate my original post - I DID successfully establish communications with my bar code reader using HyperTerminal, so it's not a hardware, or port-settings related issue. The problem lies with my use of the mscomm control while attempting to establish communications with the bar-code reader. It won't receive events either, so I know it's not related to the string I'm trying to send it to activate the bar code reader. Thanks for the help! Thanks!
LeGo PiEcE

&quot;The Computer Spock! Destroy it!&quot; - Captain James T. Kirk
 
Before you can solve the problem, you must isolate it.
The null-modem cable is a surefire way of verifying
whether you can send ANYTHING via the Comm port, via
HYPERTERMINAL or VB. The bar-code-reader is too indirect -
try monitoring the signal lines via an oscilloscope (in
which case, you won't need a null-modem cable) or another
PC (where you will).
On my desktop PC, neither of the serial ports worked
(even despite the assurances of our network manager).
 
Resolved! Well, the problem was that I overlooked the parity settings with the utmost neolithic incompetence! Anyway, thanks for your insights and help! Thanks!
LeGo PiEcE

&quot;The Computer Spock! Destroy it!&quot; - Captain James T. Kirk
 
Sure is... but at least I can sleep at night knowing that I had HyperTerminal working before my unforgivable, erroneous conduct using the mscomm ActiveX control... =) Thanks!
LeGo PiEcE

&quot;The Computer Spock! Destroy it!&quot; - Captain James T. Kirk
 
I suggest you keep this as a test case. If you ever have
a similar problem in the future, you can always plug in
the tried and true test case - and see if it's a hardware
or software problem.
 
That brought back a few memories! Just to add that the old Windows Terminal (Terminal.exe) is far more useful than Hyperterminal in troubleshooting comms problems. Oh and don't forget to set RThreshold to some non-zero value if you want to receive OnComm events. Aren't barcode readers fun?
 
Hey fissidens - yeah, that RThreshold was a good one all right! I just love the way Microsoft are so concise and explicit with their supporting documentation... it really makes you want to smell the flowers and feel the sunshine of another lovely VB day... Thanks!
LeGo PiEcE

&quot;The Computer Spock! Destroy it!&quot; - Captain James T. Kirk
 
Hi,

It sounds like some of you use serial communication on a semi regular basis. I do a lot of PLC interface stuff and I wrote a little serial utility for communicating to a Serial device. If you are interested let me know and I can give you a link. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Hey foada, - It'd be great if you could provide the link for this utility of yours. I'm actually in the process of creating an ActiveX control for that bar code reader, and your utility might just save me time! What kind of PLCs are you using? Bradleys? Actually, my next little challenge is a Cognex vision-guided incision application with some six-axis arms - that'll be fun! Peace
Lego

&quot;I don't think we have the right or the wisdom to interfere with an alien tribe no matter how it's evolving!&quot; - Captain James T. Kirk

&quot;Your people must embrace these words and the words that follow, for their true meanings are...&quot; - Captain James T. Kirk (same episode)
 
Lego,

Here is the link


If you are not a member of PSC goto


Membership is free.

I generally use Omron PLC but the company I work for builds their own PLC which is what I wrote the utility for. The utility download includes all the source code as well so even if it is not exactly what you are looking for you can modify it to suit your needs. If you have any questions on it let me know. I am also in the process of writing a more deversified app for the serial communications which (I hope) should be done with in the next 2 weeks. Hope this helps. Good Luck. [flip] Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top