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);
}