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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with MSComm

Status
Not open for further replies.

InternAmy

Programmer
Jul 22, 2004
4
US
I'm trying to use MSComm Control to output text from a command parameter to an LED screen. I found some sample code from MSDN and it would not even compile. It highlights 'Dim Comm3 As CECOMMCtl.Comm' and says "User defined type not defined." I more or less copied and pasted from MSDN. Any ideas?

Option Explicit

Dim Message As String
Dim Number_lines As String
Dim Direction As String
Dim Color As String

Sub Main()
Dim Comm3 As CECOMMCtl.Comm
Set Comm3 = CreateObjectWithEvents(CECOMM.Comm, COM3)
End Sub

Public Sub Comm3_OnComm()
Message = Environ("MESSAGE")
Comm3.Output = Message
End Sub
 
It looks to me like you are using a msdn sample for windows CE. Is this intentional? If not I suggest you search this forum for MSCOMM, there are plenty of results!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks, I did use some sample code from MSDN, but did not realize that it was for Win CE (I'm a UNIX programmer, so this is all pretty foreign to me!!!) Can I set up my code to work with my LED in Win XP?
 
Okay, I looked more into the MSComm on this site, and I have a statement like this:

Set Comm3 = CreateObjectWithEvents("MSCOMMLib.MSComm", "COM3")

Now my question is, where and how do I declare Comm3? Thanks so much!!
 
Ok,

1st off It isn't just the library that is the issue here. AFAIK, CreateObjectWithEvents realtes only to the windows CE environment. i.e. it isn't available under "normal" windows (i.e. XP). (note to Strongm I'll be looking for your solution [lol])

In the "normal" windows environment MSCOMM is more usually used as an active x control. This means that you can add it to the controls toolbox and then to the form. (press ctrl + T and put a tick in the Microsoft Comm control 6.0 box)
You can then easily add to the form.

in code
Code:
Private Sub Form_Load ()
   ' Buffer to hold input string
   Dim Instring As String
   ' Use COM1.
   MSComm1.CommPort = 1
   ' 9600 baud, no parity, 8 data, and 1 stop bit.
   MSComm1.Settings = "9600,N,8,1"
   ' Tell the control to read entire buffer when Input
   ' is used.
   MSComm1.InputLen = 0
   ' Open the port.
   MSComm1.PortOpen = True
   ' Send the attention command to the modem.
   MSComm1.Output = "ATV1Q0" & Chr$(13) ' Ensure that 
   ' the modem responds with "OK".
   ' Wait for data to come back to the serial port.
   Do
      DoEvents
   Buffer$ = Buffer$ & MSComm1.Input
   Loop Until InStr(Buffer$, "OK" & vbCRLF)
   ' Read the "OK" response data in the serial port.
   ' Close the serial port.
   MSComm1.PortOpen = False
End Sub

will open your port etc. (code straight form MSDN)

I hope that this offers a bit more light - using the code only approach as you are trying to do is not a trivial undertaking. I would suggest that you use the component approach for the moment (until you find that for some reason it doesn't do what you want)

Good luck

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top