programming problem using mscomm

A

Thread Starter

Anonymous

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.
 
D

Davis Gentry

Did you set up the motor controllers to respond to
numbers 1 and 2, or perhaps the names MOT1 and MOT2, depending on the required nomenclature?

Another possibility is that the serial buffer is not getting cleared before you write the second command. What happens if you put the second command in a different button?

Davis Gentry
 
M

Michael Griffin

Lines 2 to 4 appear to be intended as a delay loop. With the speed of today's computers, I doubt that this one would really accomplish much. Try longer time delays using a "sleep" statement.

P.S. - Although the "for" loop has no place in this problem, read up on "for" and "while" loops as you seem unfamiliar with them. You are doing this one all wrong.
 
Every industrial protocol I have used will send a reply for every query or command. You are probably just talking on top of the first motor's reply by sending the next motor a command without waiting to read the reply from the first.

The delay you are using to avoid this collision is not valid. In addition to the explanation MG gave you, an optimization pass by the compliler might remove your delay loop entirely if the variable 'icount' is local to the calling function (on the stack). If the variable 'icount' is global and/or static, an optimizer might resolve your loop to 'icount = 11', as the buzy loop does nothing else but this. I mention this to discourge you from thinking that writing the loop as 'for lcount=1 to 2000000000' will do you any better.
 
hi Mr Gentry

You are right. It is the serial buffer. Please could you advise me on how to clear it in time. i have tried 4 different ways to implement the delay but was unsuccessful.

thank you.
 
D

Davis Gentry

Put the calls on the serial port on the timer tick
event - vary the time tick using a text box until it starts working. If the time of tick at which it works is too slow then you'll need to either cut down the amount of data exchanged, get a faster PC, or get a different motion controller. My money on the bottleneck is the controller.

Davis Gentry
 
Top