Problem of code for SSC-32

SerialPort serialPort1 = new SerialPort();

        if (serialPort1.IsOpen)
            serialPort1.Close();


        try
        {
            serialPort1.BaudRate = 115200;
            serialPort1.PortName = "COM1";
            serialPort1.Parity = Parity.None;
            serialPort1.DataBits = 8;
            serialPort1.StopBits = StopBits.One;
            //Now open the serial port
            serialPort1.Open();
        }
        catch (Exception ex)
        {
           MessageBox.Show("Couldn't open the Serial Port!");
            MessageBox.Show(ex.ToString());
        }

        serialPort1.Write("#0 P1500\r");

        serialPort1.Write("#1 P1500\r");
        serialPort1.Write("#2 P1500\r");
        serialPort1.Write("#3 P1500\r");
        serialPort1.Write("#4 P1500\r");
        serialPort1.Write("#5 P1500\r");

        serialPort1.Close();

}

[size=200]BUT Problem starts when I write:[/size]

SerialPort serialPort1 = new SerialPort();

        if (serialPort1.IsOpen)
            serialPort1.Close();


        try
        {
            serialPort1.BaudRate = 115200;
            serialPort1.PortName = "COM1";
            serialPort1.Parity = Parity.None;
            serialPort1.DataBits = 8;
            serialPort1.StopBits = StopBits.One;
            //Now open the serial port
            serialPort1.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Couldn't open the Serial Port!");
            MessageBox.Show(ex.ToString());

            serialPort1.Write("#0 P1000 S1000\r");
            serialPort1.Write("#4 P1000 #3 P1100 #5 P1000\r");

            serialPort1.Close();

}

[size=150]I am using TowerPro MG995 total six motors. [/size]

[size=150]The problem is group move doesnot work.[/size]

serialPort1.Write("#4 P1000 #3 P1100 #5 P1000\r");

[size=150]As well as inidividual move also doesnot work.[/size]

serialPort1.Write("#0 P1000 S1000\r");

[size=150]But, this center all servos move works Perfectly:[/size]

    serialPort1.Write("#0 P1500\r");
        serialPort1.Write("#1 P1500\r");
        serialPort1.Write("#2 P1500\r");
        serialPort1.Write("#3 P1500\r");
        serialPort1.Write("#4 P1500\r");
        serialPort1.Write("#5 P1500\r");

hi, are you using .net?
if so you might have to encode your strings as ASCII. string literals in .net are all unicode.

byte ] message = Encoding.ASCII.GetBytes( “#4 P1000 #3 P1100 #5 P1000\r” );
serialPort1.Write( message, 0, message.Length );

this may or may not be the problem, but its worth a shot. my ssc-32 is still in the mail so i havent done any testing myself

-edit-
hm, never mind, SerialPort.Write(String) already does ascii encoding… perhaps some other encoding should be used? or maybe its a diffrent issue entierly :slight_smile:

If this is a cut and paste of your actual code, it appears as if you are missing a close brace, }, after the second MessageBox command in the “catch (Exception ex)” code.

Do you see it?

Thank You, but problem is something else.

I could be wrong, but my quick look through, it looks like you only do something if you get an exception…

That is the code should probably look more like:

SerialPort serialPort1 = new SerialPort();

if (serialPort1.IsOpen)
serialPort1.Close();


try
{
    serialPort1.BaudRate = 115200;
    serialPort1.PortName = "COM1";
    serialPort1.Parity = Parity.None;
    serialPort1.DataBits = 8;
    serialPort1.StopBits = StopBits.One;
    //Now open the serial port
    serialPort1.Open();
    serialPort1.Write("#0 P1000 S1000\r");
    serialPort1.Write("#4 P1000 #3 P1100 #5 P1000\r");
   serialPort1.Close();

}
catch (Exception ex)
{
    MessageBox.Show("Couldn't open the Serial Port!"); 
    MessageBox.Show(ex.ToString());
}

Kurt

Problem not solved, this is exceptional I can use same code to run on first button event, but can’t run on second button event.

We’ll just have to guess what he’s programming on. PIC? Arduino??

Alan KM6VV

Probably VB. Can not debug more until see current stuff. Previous stuff had issues with how the Try/Catch blocks was setup .

Kurt

P.S - Trying the new Quick Reply?

The new quick reply?

Alan KM6VV

It is either new to me or I never noticed it before… Or only some of us now have it. But in both of the profile types (prosilver, subsilver2), there is either a new button or a new sub-dialog at the bottom for Quick Reply…

But: enough hijacking of this thread.
Kurt

(Pssst. Yes, the quick reply is new! I just enabled it yesterday.)