111912 14:11:42 write: E,X111912 14:11:42 received: X+0000000111912 14:11:42 write: E,Y111912 14:11:42 received: Y+0000000111912 14:11:42 write: F,C,S2M200,I2M-100,R111912 14:11:42 received: CS2M200,I2M-100,111912 14:11:42 received: R111912 14:11:43 write: E,X111912 14:11:43 received: +0000000111912 14:11:43 write: E,Y111912 14:11:43 received: -0000024111912 14:11:43 received: ^111912 14:11:43 write: E,X111912 14:11:43 received: X+0000000111912 14:11:43 write: E,Y111912 14:11:43 received: Y-0000100111912 14:11:44 write: F,C,S1M50,I1M20,R111912 14:11:44 received: CS1M50,I1M20,R111912 14:11:44 write: E,X111912 14:11:44 received: +0000006111912 14:11:44 write: E,Y111912 14:11:44 received: -0000100111912 14:11:44 write: F,C,S2M200,I2M-100,R111912 14:11:44 received: ^
111912 14:11:55 write: F,C,S2M200,I2M-100,R111912 14:11:55 received: ^111912 14:11:55 write: E,X111912 14:11:55 received: X+0000140111912 14:11:55 write: E,Y111912 14:11:55 received: Y-0000100….111912 14:11:56 Script stopped
Q.) The fact that the issue is random and inconsistent makes me think there is something wrong with the Controller. A.) Incorrect, the VXM always sends the caret ("^") when it has completed running its program. The idea that it only APPEARS to be random is due to either a timing issue or other software issue in your code. The shorter your program execution time and the more rapidly your checks for the ^ the more likely that it will miss one either by a read that actually had 2 ^^ in the buffer, satisfying the 1st check, but then the next check has none because it was already read. (or a check was made before, or at the moment that the ^ is arriving at the port) Serial port timing is not a constant, it is an average. If you can post compilable code then it can be shown where in the code that the "random loss of a ^" can be shown.
-------- Original Message --------
Subject: Re: command complete '^' not received from motor controller Date: Tue, 19 Aug 2014 09:35:49 -0700 (PDT) From: hbnj...@gmail.com Reply-To: velmex-...@googlegroups.com To: velmex-...@googlegroups.com
I encounter the exact problem. I use C# to send the commands. The fact that the issue is random and inconsistent makes me think there is something wrong with the Controller. If the issue was due to the code and command strings I would assume the issue would happen consistently and at the same line or time every run. I know this was posted a year and a half ago but I would appreciate a reply if you have found the cause and the solution. THX -- You received this message because you are subscribed to the Google Groups "Velmex Controls" group. To unsubscribe from this group and stop receiving emails from it, send an email to velmex-contro...@googlegroups.com. To post to this group, send email to velmex-...@googlegroups.com. Visit this group at http://groups.google.com/group/velmex-controls. For more options, visit https://groups.google.com/d/optout.
Vxm.DriverTerminalShowState(1, 0);
if (Vxm.PortIsOpen() != 1)
Vxm.PortOpen(Settings.velmexComPort, Settings.velmexBaudRate);
int _distance = 0;
if (!pulse)
_distance = GetDistanceInDegrees(motorNumber, distance);
else _distance = distance;
Vxm.PortSendCommands("F,C,S");
Vxm.PortSendCommands(motorNumber.ToString());
Vxm.PortSendCommands("M");
if (motorNumber == 1)
Vxm.PortSendCommands(Settings.M1Speed.ToString());
else
Vxm.PortSendCommands(Settings.M2Speed.ToString());
Vxm.PortSendCommands(",I");
Vxm.PortSendCommands(motorNumber.ToString());
Vxm.PortSendCommands("M");
if (direction == '-')
Vxm.PortSendCommands(direction.ToString());
Vxm.PortSendCommands(_distance.ToString());
Vxm.PortSendCommands(",R");
Vxm.PortWaitForChar("^", 0);
Vxm.DriverTerminalShowState(0, 0);
if (motorNumber == 1)
Settings.M1Position = Convert.ToInt32(Vxm.MotorPosition(1)) / Settings.M1PulsePerDegree;
if (motorNumber == 2)
Settings.M2Position = Convert.ToInt32(Vxm.MotorPosition(2)) / Settings.M2PulsePerDegree;
Vxm.PortClose();
distance = updatePosition(motorNumber, direction, distance);
return 0;
}
catch (Exception except)
{
System.Windows.Forms.MessageBox.Show(except.Message, "Motor Control: Move()");
return 0;
}
}
_______________________________________________________________________________
After you memntioned there might be some timing issues I added several delays to give the controller enough time.
Here is the Code with delays:
_______________________________________________________________________________
public int move(int motorNumber, char direction, int distance, bool pulse) // pulse Boolean value is true when distance is sent in pulse counts, if false the distance is sent in degrees.
{
try
{
Thread.Sleep(50);
Vxm.DriverTerminalShowState(1, 0);
if (Vxm.PortIsOpen() != 1)
Vxm.PortOpen(Settings.velmexComPort, Settings.velmexBaudRate);
int _distance = 0;
if (!pulse)
_distance = GetDistanceInDegrees(motorNumber, distance);
else _distance = distance;
Vxm.PortSendCommands("F,C,S");
Vxm.PortSendCommands(motorNumber.ToString());
Thread.Sleep(200);
Vxm.PortSendCommands("M");
if (motorNumber == 1)
Vxm.PortSendCommands(Settings.M1Speed.ToString());
else
Vxm.PortSendCommands(Settings.M2Speed.ToString());
Vxm.PortSendCommands(",I");
Vxm.PortSendCommands(motorNumber.ToString());
Vxm.PortSendCommands("M");
Thread.Sleep(300);
if (direction == '-')
Vxm.PortSendCommands(direction.ToString());
Vxm.PortSendCommands(_distance.ToString());
Thread.Sleep(300);
Vxm.PortSendCommands(",R");
Thread.Sleep(900);
Vxm.PortWaitForChar("^", 0);
Thread.Sleep(300);
//Vxm.DriverTerminalShowState(1, 0);
if (motorNumber == 1)
Settings.M1Position = Convert.ToInt32(Vxm.MotorPosition(1)) / Settings.M1PulsePerDegree;
if (motorNumber == 2)
Settings.M2Position = Convert.ToInt32(Vxm.MotorPosition(2)) / Settings.M2PulsePerDegree;
Vxm.PortClose();
distance = updatePosition(motorNumber, direction, distance);
return 0;
}
catch (Exception except)
{
System.Windows.Forms.MessageBox.Show(except.Message, "Motor Control: Move()");
return 0;
}
}
___________________________________________________________________________
Here are other functions that are called by the above (move()) function:
___________________________________________________________________________
private static int GetDistanceInDegrees(int motorNumber, int distance)
{
int _distance = distance;
if (motorNumber == 1)
_distance = _distance * Settings.M1PulsePerDegree;
if (motorNumber == 2)
_distance = _distance * Settings.M2PulsePerDegree;
return _distance;
}
___________________________________________________________________________
private int updatePosition(int motorNumber, char direction, int distance)
{
if (direction == '-')
distance = -1 * distance;
if (motorNumber == 1)
M1Position += distance;
if (motorNumber == 2)
M2Position += distance;
return distance;
}
____________________________________________________________________________
Vxm.PortWaitForChar("^", 0); to Vxm.PortWaitForChar("^", 5000);and see if the program only locks up for 5 seconds? or if it continues to be locked up for 30 seconds or more?