Hi all.
I am working on a gui based app for the K8097 card permiting the user to define a changable set of commands. The gui app is written in Visual Studio 2013 in c++. The Move function looks as follows:
void Move(int motor, int steps, int direction, int speed, System::IO::Ports::SerialPort^ serialPort)
{
//forming the message sent to the motor driver
array<unsigned char, 1> ^WriteBuffer = { 0xFF, 0x1C, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
//steps
WriteBuffer[2 + motor * 6] = steps & 0xFF;
WriteBuffer[3 + motor * 6] = (steps >> 8) & 0xFF;
WriteBuffer[4 + motor * 6] = (steps >> 16) & 0xFF;
WriteBuffer[5 + motor * 6] = (steps >> 24) & 0xFF;
//speed
WriteBuffer[6 + motor * 6] = speed & 0xFF;
//direction
WriteBuffer[7 + motor * 6] = direction & 0xFF;
//message checksum
unsigned char checksum = 0x1C;
for (int i = 0; i<6; i++)
{
checksum += WriteBuffer[2 + motor * 6 + i];
}
checksum = (~checksum) + 1;
WriteBuffer[26] = checksum;
// sending the message
serialPort->Write(WriteBuffer,0,WriteBuffer->Length);
array<System::Byte, 1> ^ReadBuffer = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Sleep(100);
int BytesRead = 7;
int remainder = 1;
while (remainder == 1))
{
Sleep(50);
BytesRead = serialPort->Read(ReadBuffer, 0, ReadBuffer->Length);
remainder = (ReadBuffer[2] >> motor) % 2;
}
}
Yet, I have a problem that after the first reading I get the ReadBuffer equal to:
ReadBuffer ={0xFF, 0x7, 0x0, 0x0, 0xBF, 0x3A, 0x0}
So my question is why do i get a 0x00 in the third byte of status command while the motor is running?