CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

mscomm

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

mscomm
PostPosted: Mon Jan 07, 2013 4:14 pm     Reply with quote

I started the first application using RS232 to send data to PC. First I used the hyperterminal and I sent the following every second:

Date: 02/01/13 Time: 01:33:16

..and it worked perfectly. When I tried to make the same using the VB6, I ma getting junk characters. What I am doing wrong? I believe that the problem is in the vb code. The VB code is:

Code:

Dim str As String


Private Sub Form_Load()
Dim stringline As String
Dim fnum As Integer

MSComm1.CommPort = 6
MSComm1.InputLen = 0
MSComm1.InBufferSize = 5000
MSComm1.PortOpen = True
MSComm1.RThreshold = 1



End Sub


Private Sub MSComm1_OnComm()

  If (MSComm1.CommEvent = comEvReceive) Then  ' if something received
       Text1.Text = MSComm1.inpout  'save it to text3
  End If

End Sub


thanks for eveyrhing

Using PIC18F4550, RS232 parameters: 57600,n,8,1
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 4:59 pm     Reply with quote

Hi,

You need to set the MSCOMM Settings property to tell the code the correct
baud rate, date bits, etc. If this is not set then undoubtedly there are some
default values, and they don't match the ones in use by your PIC.

John
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 5:04 pm     Reply with quote

I set these parameters from the gui of visual studio. I removed them from the code to keep it short as possible. But i can confirm that settings match with those of the pic
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 5:57 pm     Reply with quote

Hi,

OK, I like to do it "in-line" so that I can see for sure what is going on. There
is also an inputmode property that should be set to 'text'...

John
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 6:01 pm     Reply with quote

How? The rest is ok?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 7:12 pm     Reply with quote

Hi,

The syntax is mscomm.inputmode = comInputModeText

This is the default setting, so it may be OK, I just like to set it explicitly.

If you don't get it working, I'll send some tested code in the morning.

John
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 8:45 pm     Reply with quote

Two things come to mind - unfortunately, I don't have visual studio 6 installed on this machine, but I seem to remember that the upper baud rate limit was lower than what you are indicating (without adding one of the commercial com ocx packages - I thought it was either 9600 or 19,200). Also you have "Text1.Text = MSComm1.inpout 'save it to text3 " inpout?

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Tue Jan 08, 2013 3:23 am     Reply with quote

Start with making sure the config is right:
If the port is open, close it. Set the settings, then open it. So:

Code:

'On form load.
   If MSComm.PortOpen Then MSComm.PortOpen = False
   MSComm.CommPort = your_port_number
   MSComm.Settings = "57600,N,8,1"
   MSComm.InputMode=comInputModeText
   MSComm.InBufferSize=2048
   MSComm.InputLen=1 'Must be one if you want single characters
   MSComm.Handshaking=comNone
   MSComm.RThreshold=1
   MSComm.NullDiscard=False
   If MSComm.PortOpen = False Then MSComm1.PortOpen = True
   MSComm.DTREnable = True ''Need these if using USB
   MSComm.RTSEnable = True


This configures a port at 57600bps, via a standard serial connection, or USB, for VB6.

Then if you have an event:
Code:

Private Sub MSComm1_OnComm()
   Dim dummy As String
   dummy = MSComm.Input
   Text1.Text = Text1.Text + dummy 'Obviously put this where you want
End Sub


You don't actually need the 'if' you have here, since MSComm.Input will simply return null, if there is no data to read. It'll trigger on every character though, so to see what is coming, you need to append the character to the existing string.

On whether 57600 will work, it depends on the version of VB6, and the chipset. There were problems with the older MSCOMM driver at higher baud rates on some chipsets, but this has been fixed by one of the service packs, and the standard driver will happily run at 57600bps, provided you have these later service packs.

Best Wishes
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Wed Jan 09, 2013 12:39 pm     Reply with quote

Thanks to everyone i changed the baud rate to 9600 imsteadof 57600 and modified the program accordingly and everything is working good. One issue is that when i change the code from

Code:
text1.text =text1.text + dummy


To

Code:
label1.caption = dummy


The data is not being updated.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 09, 2013 3:13 pm     Reply with quote

Your question really has nothing to do with CCS C relative to PICs ! You should either goto a VB forum or PM one of the responders who has already helped you..quick.before this thread is 'locked' as being off topic.

hth
jay
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Wed Jan 09, 2013 3:15 pm     Reply with quote

ok thanks. I think it will be much better to keep it open. Somebody might have the same problem and he find help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Wed Jan 09, 2013 3:42 pm     Reply with quote

Note the line I put in my post:

"It'll trigger on every character though, so to see what is coming, you need to append the character to the existing string. "

The +dummy, is this 'appending'.

Problem is that otherwise you will just get a single character changing as each character arrives, and only have one character in the text to be read.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group