Another problem about C++ control

Hi, i am working on a project to control a 7 degree of freedom manipulator, and we are using SSC32 to control the manipulator, so i write the code on Visual C++ 2010 and try to transmit the command to the SSC-32. So i make the code run and the data transmit to ssc-32 (the led did blink), however the servo do not have any response which means it do not move. I’m prety sure the servo is connect to right port (i am using port 0 to 7), is there any possible issue causing this problem?

just in case here is my code,

#include <stdio.h>
#include <stdlib.h>
#include “Windows.h”

int main()
{
HANDLE hComm;
hComm = CreateFile( “COM3”,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hComm == INVALID_HANDLE_VALUE)
{
printf(“connection failed”);
system(“pause”);
return 0;
}

DCB dcbSerialParams = {0};
dcbSerialParams.DCBlength = sizeof(dcbSerialParams);

if (!GetCommState(hComm, &dcbSerialParams)) {
printf("error getting state");
system("pause");
return 0;
}

dcbSerialParams.BaudRate = CBR_19200;
dcbSerialParams.ByteSize = 8;
dcbSerialParams.StopBits = ONESTOPBIT; //ONE5STOPBITS, TWOSTOPBITS
dcbSerialParams.Parity = NOPARITY; // EVENPARITY, ODDPARITY

dcbSerialParams.fRtsControl = RTS_CONTROL_ENABLE;
dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE;
dcbSerialParams.fOutxCtsFlow = FALSE;
dcbSerialParams.fOutxDsrFlow = FALSE;


if (!SetCommState(hComm, &dcbSerialParams)){ //apply setting to setial port
	printf("error getting serial port state");
	system("pause");
	return 0;
}

//tell windows no to wait for data
COMMTIMEOUTS timeouts = {0};

timeouts.ReadIntervalTimeout = 50;
timeouts.ReadTotalTimeoutConstant = 50;
timeouts.ReadTotalTimeoutMultiplier = 10;
timeouts.WriteTotalTimeoutConstant= 50;
timeouts.WriteTotalTimeoutMultiplier = 10;

if(!SetCommTimeouts(hComm, &timeouts)){
	printf("error setting time out");
	system("pause");
}

//read writing data
/*
const int n = 8;
char szBuff[n+1] = {0};
DWORD dwBytesRead = 0;

if(!ReadFile(hComm, szBuff, n, &dwBytesRead, NULL)){ //WriteFile for writing
	printf("error reading data");
	system("pause");
}
*/


char szBuff] = "#0 P1500 \r"; 
int n = sizeof(szBuff);
DWORD dwBytesRead = 0;

if(!WriteFile(hComm, szBuff,n , &dwBytesRead, NULL)){ //WriteFile for writing
	printf("error writing data\n");
	char lastError[1024];
	FormatMessage(
	FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
	NULL,
	GetLastError(),
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
	lastError,
	1024,
	NULL);
	printf(lastError);
	system("pause");
}
else
{
	printf("data transmit sucess");
	system("pause");
}
//second command

char scBuff] = "#0 P500 T1500 \r";
n = sizeof(scBuff);


if(!WriteFile(hComm, szBuff,n , &dwBytesRead, NULL)){ //WriteFile for writing
	printf("error writing data\n");
	char lastError[1024];
	FormatMessage(
	FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
	NULL,
	GetLastError(),
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
	lastError,
	1024,
	NULL);
	printf(lastError);
	system("pause");
}
else
{
	printf("data transmit sucess");
	system("pause");
}



//closing down

CloseHandle(hComm);

}

viewtopic.php?f=2&t=6286
This link might help.

First thing I would try is to change things like:

char scBuff] = "#0 P500 T1500 \r";
to:

char scBuff] = "#0 P500 T1500 \n\r";
Just to make sure it is getting the proper termination character, to execute the command.

Next I think you have a baud rate issue. That is you have:

dcbSerialParams.BaudRate = CBR_19200;

I don’t believe the SSC-32 supports the baud rate of 19200, try changing this to something like 115200, or 38400 and make sure the appropriate baud rate jumpers are set on the SSC-32

Kurt

I suggest you check out your servos using lynxterm just to make sure your hardware is setup correctly.

yes, you are right.

also , seem one of my servo being damage and make the manipulator some time will go unstable, thanks for the help