Im completely confused, I have been trying to get a servo moving left and right using a c# application over a serial port with variying success. Using hyperterminal the board works fine using 'servo 5:80' then 'servo 5:-80'.
However when trying to send the same string using a visual stuido 2005 program I get erratic results. I have setup the program with two buttons so when one button is pushed the string 'servo 5:80' is sent and another button that sends 'servo 5:-80'. I am used to things either working or not working but sometimes when you push the buttons it works but most of the time it doesn't. I tried looping the 'servo 5:-80' a hundred times with the result of the servo moving backwards and forwards erratically. None of this is expereinced using hyperterminal. What really stumps me though is after running this application a few times hyperterminal starts to work erratically as well. Resetting the board does not fix this. Only unpluging and replugging in does.
This leads me to believe that some junk must be getting sent and stored on the board and is producing random results. I have checked what is being sent using another PC with hyperterminal running to receive the strings and there is no difference between what my application sends and what hyperterminal sends when it is working. I have baud set to 19200, one stop bit , no handshaking. I have also tried the example application that sets the led blink rates with equally erratic results. I have also tried using:
panServo =
panServo.ServoMotorId =
panServo.Position = 80;
Which while it sends the correct string three times to hyperterminal on my other PC once again produces erratic results on the board. Here is the code I am using, if anyone has any ideas I would be greatly appreciated as I have to get this working and it is taking alot longer than I would have liked.
Form1.Designer.cs
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using RoboticsConnection.Serializer;using RoboticsConnection.Serializer.Components;using RoboticsConnection.Serializer.Controllers;using RoboticsConnection.Serializer.Ids;using RoboticsConnection.Serializer.Sensors;namespace SerializerControl{ public partial class Form1 : Form { private static ServoMotorController panServo; public Form1() { InitializeComponent(); InitSerializerComponents(); s_.StartCommunication(); panServo = new ServoMotorController(s_); panServo.ServoMotorId = ServoMotorId.ServoMotor5; } private void Periodic_Timer_Tick(object sender, EventArgs e) { s_.PumpEvents(); } private void btnRight_Click(object sender, EventArgs e) { panServo.Position = -80; } private void btnLeft_Click(object sender, EventArgs e) { panServo.Position = 80; } }}
using System;
using
namespace
{
public partial class Form1 : Form
private static ServoMotorController panServo;
public Form1()
InitializeComponent();
InitSerializerComponents();
s_.StartCommunication();
panServo = new ServoMotorController(s_);
panServo.ServoMotorId = ServoMotorId.ServoMotor5;
}
private void Periodic_Timer_Tick(object sender, EventArgs e)
s_.PumpEvents();
private void btnRight_Click(object sender, EventArgs e)
panServo.Position = -80;
private void btnLeft_Click(object sender, EventArgs e)
using RoboticsConnection.Serializer;using RoboticsConnection.Serializer.Components;using RoboticsConnection.Serializer.Controllers;using RoboticsConnection.Serializer.Ids;using RoboticsConnection.Serializer.Sensors;namespace SerializerControl{ partial class Form1 { #region SERIALIZER OBJECTS: // Serializer Objects: private static Serializer s_; #endregion #region SERIALIZER INITIALIZATION private void InitSerializerComponents() { s_ = new Serializer(); s_.PortName = "COM7"; s_.BaudRate = 19200; } #endregion Etc.(rest of this just normal autogenerated code)
#region
#endregion
s_ =
s_.PortName =
s_.BaudRate = 19200;
Etc.(rest of this just normal autogenerated code)
James,
One obvious problem that I see is that you are calling s_.StartCommunication() before you new off a ServoMotorController, and set it's params. You can't do this. :) You have to new off, and initialize all of the Serializer components before establishing communications w/ the Serializer.
I would put the creation/initialization of all Serializer objects in your InitSerializerComponents(), and then call s_.StartCommunication() afterwards.
Best Regards!
Just by way of further diagnosing the problem, let me ask a question.
Are you using a builtin RS-232 port on your board (i.e. actual onboard UART device), or are you using somekind of serial conversion device, as in a USB to RS232 adapter?
Barring actual hardware problems with the Seralizer, it almost sounds like the RS232 device (or conversion device) get's into a state which is persistent between applications. You did say that the problem was resolved when the Serializer board was power cycled, but it could be that the act of power cycling causes the RS-232 port to reinitialize (perhaps through on of the RS-232 control lines).
James Y. Wilson http://www.learningce.com Fortudine Vincimus!
Wow, thanks for the quick replies!
I will implement the code changes as soon as I am back next to the board tonight. And yes I dont have a serial port on the laptop im using so I am using a USB to RS232 adapter. Hmm maybe it is the adapter I will have to test your theory. It does sound more likely than the Serilaizer not resetting. Ill post again if I am successful!
Thanks for all the help :)
I use a USB to RS-232 adapter from time to time, and it seems to work fine for me. Typically the only problem the adapter causes is when you're trying to upgrade your firmware. This is typically fixed by adding a longer character and line delay within Hyperterm.
So, I do suspect it's a problem w/ the app. Please let us know what you find one way or the other.