Serial Communication

How do I tranlate this QUick Basic Line

OPEN "COM1:2400,N,8,1,RS,CS,DS,CD" FOR INPUT AS #1

to VB?
The part with "COM1:2400,N,8,1" is obvious to me, but how do I set handshake and the like: "RS,CS,DS,CD"?

I can read a digital voltmeter with soime line of Quick Basic, but I fail when trying to this under VB.
[338 byte] By [subbotnik] at [2007-11-17 16:56:27]
# 1 Re: Serial Communication
I have no experience on this but try to utilize the MS COMM Control in VB.

Good Luck,
-Cool Bizs
coolbiz at 2007-11-10 0:23:11 >
# 2 Re: Serial Communication
When you attach the MS Com control to the form you can set the comms properties. I think the fact that they are in the string from the initial Basic app tells you that they are enabled. Another way to tell what you will have to use is the Pinout on the cable.

Let me know if you need additional information.

LJ
LittleJonny at 2007-11-10 0:24:08 >
# 3 Re: Serial Communication
Use the MSComm control. Here are some of the methods to set it up in runtime. There is actually some pretty good information in the help files, but it takes a lot of reading.

' You have to close the port in order to change settings:
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False

MSComm1.CommPort = CommPort$

MSComm1.Settings = Baud$ + "," & Parity$ & "," & Data% & "," & Stop%

MSComm2.DTREnable = True
MSComm2.RTSEnable = True
MSComm1.Handshaking = 0

This routine reads data from the comm port. The amount of data read depends on the InputLen property. I usually setr it to 1 so it reads one character at a time, but this may not be best for your app.

MSComm1.PortOpen = True
Do
DoEvents
Temp$ = MSComm1.Input
Temp1$ = Temp1$ & Temp$
Loop

Of course, you have to have a way of ending the transfer. With CNC machines, I have looked for a certain character sent when the machine is finished sending (that's why I read one character at a time).
You could use a command button that sets a variable, call it CancelData, equal to true. Then place logic in the do loop to exit when CancelData=True.
Or you could use the OnComm event (Note that setting the RThreshold or SThreshold properties to 0 disables trapping for the comEvReceive and comEvSend events, respectively). See "MSComm Control Constants" in the VB help file.

And don't forget to close the port when you're finished. You will get an error if you try to open a port that's already open.
Ron Stone at 2007-11-10 0:25:18 >
# 4 Re: Serial Communication
Thank you for your quick reply.
I usually do not have problems using the MSComm-Control, or other serial communication control.

And I also have tried a lot of combinations of the respective handshake settings but there are quite a few combinations possible, and so far nothing worked. What I need is to understand that Quick Basic line.
What does RS,CS,DS,CD stand for, probably
RS= RTS, CS=CTS, DS=DTS but CD=?

I also assumed that the QB line tells me that these parameters have to be "enabled". But somewhere I have read that it is the other way round, at least for one of them.
And I realize that I still do not really understand MSComm either. There is a handshake setting under "General" call "comRTS" and there is that checkbox under "Hardware" - to which may the parameter in the QB line refer?
CTS, DTS, and CD(?) does not seem to appear under MSComm, but DTR - how to deal with this one.

I must say that I am quite desperate, a simple problem like this is haunting me for years.

I will try Ron's way of doing it, even though I feel that I have tried this already some time ago.
subbotnik at 2007-11-10 0:26:20 >
# 5 Re: Serial Communication
I think we're going into the way-back machine Sherman (if you remember the old cartoon).

Sounds like you may be dealing with direct modem commands.

CD would be "Carrier Detect". I would only be guessing at the others since its been a long time since I used them and my old documentation was probably eaten by my dog.

I did find a web site, www.qbasic.com, that deals with Qbasic and Quick Basic. If you don't find what you're looking for there, they have a lot of links.

I also found the following on another site, www.rjftrains.com/downloads/markdig2.pdf

QuickBasic:
OPEN COM1:2400,N,8,2,RS,DS,CDFOR RANDOM AS #1

Visual Basic:
Comm1.Settings ="2400,n,8,2"
Comm1.CommPort =1
Comm1.PortOpen =True
Comm1.Handshaking = IIf(RTS_Enabled%,2,0)
Comm1.RTSEnable =RTS_Enabled%

I hope this helps. You might also want to check out some modem command documentation.

best of luck
Ron Stone at 2007-11-10 0:27:16 >
# 6 Re: Serial Communication
I did some digging for my boss a while back and put together this document for him. Hope it helps you.
P Shady at 2007-11-10 0:28:13 >