943,853 Members | Top Members by Rank

Ad:
Sep 6th, 2006
0

mscomm program problem

Expand Post »
hi

i am a student. i am using vb6 to get an agv running. using mscomm to speak to a main micro which then addresses motor boards. at present i am just testing 2 motors to see if the program will work. in my foward command button the code is as follows:

1 mscomm.output = "MOT1SPF1000"

2 for icount = 1 to 10
3 icount = icount +1
4 next icount

5 mscomm.output = "MOT2SPF1000"

(the string basically tells motor 1 to turn forward at speed 1000)

the motors work fine when addressed indivually
but since i added lines 2-5 only 1 motor spins and it doesnt stop

please could someone advise me on how to correct the program

thank you
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adhi is offline Offline
2 posts
since Sep 2006
Sep 6th, 2006
1

Re: mscomm program problem

U r incrementing the value twice. Once in the For (which will automatically increment by 1) and once inside the for loop. So ur icount values are 1,3,5,7... . Since it never reaches 10, it goes into an infinite loop.

Use
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. for icount = 1 to 10
  2. Next
Last edited by Comatose; Sep 6th, 2006 at 6:44 pm.
Reputation Points: 20
Solved Threads: 10
Junior Poster
aparnesh is offline Offline
193 posts
since Jul 2005
Sep 7th, 2006
0

Re: mscomm program problem

thanks will try
Reputation Points: 10
Solved Threads: 0
Newbie Poster
adhi is offline Offline
2 posts
since Sep 2006
Feb 9th, 2010
0
Re: mscomm program problem
I assume you're using that loop as some way to make the computer wait a moment betwen sending commands. Yes, you are incrementing twice but that's not your problem.

The problem is that the loop isn't doing anything. Counting to 10 (even 100 or 1000) is fast, very fast. RS232 is slow, very (VERY) slow. Most of the first packet of data is still in the output buffer when you chuck the second packet in right behind it so, from the motor's perspective, there's no gap between the commands which confuses the motor controller.

Use the system timer to force processing to wait a moment between commands like this:-

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim t as single
  2.  
  3. ' send first command
  4. MSComm.Output = "MOT1SPF1000"
  5.  
  6.  
  7. Do While MSComm.OutBufferCount > 0
  8. ' wait here till all the first command was sent
  9. DoEvents
  10. Loop
  11.  
  12. ' now lets wait a little longer
  13.  
  14. t = Timer
  15. Do While Timer < t + 0.5
  16. ' This will make processing loop here for half a second
  17. DoEvents
  18. Loop
  19.  
  20. ' Now send the second command .
  21. MSComm.Output = "MOT2SPF1000"


Look at some sample code at the <<plug removed>>
Last edited by Nick Evan; Feb 9th, 2010 at 1:16 pm. Reason: Removed plug
Reputation Points: 6
Solved Threads: 0
Newbie Poster
MikeStump is offline Offline
4 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Com5 without MSComm
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VBA Code for pasting cells down a growing list that continually gets updated





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC