trinamic sixpack and c#

trinamic sixpack and c#

Postby Franklin » 07 Jul 2011, 18:24

Hello everyone,

First off i am new to Programming Trinamic boards. I've got the first version of the Trinamic SixPack.
Now i have played arround with the Software you can download.
I want to program my own software using c# because i know that language very well...

In my software i open the com port and i send a 9 byte array to the board...the data LED flashes but nothing happens...

I send the following: port.Write(new byte [] { 0x01, 0x25, 0x05, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00 }, 0, 3);

that is exactlly how i see if i record a macro at the highest speed...but nothing happens...

am i forgetting something...please help!!

thanks

Franklin
Franklin
User
User
 
Posts: 4
Joined: 07 Jul 2011, 18:18

Re: trinamic sixpack and c#

Postby Olav Kahlbaum (TRINAMIC) » 11 Jul 2011, 08:35

Your command looks good, and the data LED flashing means that the command has been understood by the Sixpack. But I can see that this command is for motor #5 - did you connect a motor to axis #5, or did you mean to use it for a different axis (maybe better start with axis #0).
User avatar
Olav Kahlbaum (TRINAMIC)
Site Admin
 
Posts: 3369
Joined: 11 Aug 2006, 08:02

Re: trinamic sixpack and c#

Postby Franklin » 11 Aug 2011, 16:38

Okay i got it to work :)

The Problem was the amount of bytes transfering at the end

port.Write(new byte [] { 0x01, 0x25, 0x05, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00 }, 0, 3)

instead of the 3 put a 9 and it worked ;)


Other Question...
I am reading the current Position of the motors...
Now i read them every 10ms...if i run the motor to a new position how is the position calculated from the recieved byte array?!

thanks for the help
Franklin
User
User
 
Posts: 4
Joined: 07 Jul 2011, 18:18

Re: trinamic sixpack and c#

Postby Olav Kahlbaum (TRINAMIC) » 12 Aug 2011, 07:44

When using command 0x20 for reading the actual position you will get the following answer:
Byte 0: the response address
Byte 1: 0x20 (the command)
Byte 2: the motor number
Byte 3: position bits 31..24
Byte 4: position bits 23..16
Byte 5: position bits 15..8
Byte 6: position bits 7..0
Byte 7: current motor activity
Byte 8: stop condition status

So when we assume that the answer is in a 9 byte array named "answer", extracting the position looks as follows (C syntax - I am not sure about C# syntax):

int position;
position=(byte[3] << 24) | (byte[4] << 16) | (byte[5] << 8) | (byte[6]);

or you could also do it as follows:

int position;

position=byte[3];
position<<=8;
position|=byte[4];
position<<=8;
position|=byte[5];
position<<=8;
position|=byte[6];
User avatar
Olav Kahlbaum (TRINAMIC)
Site Admin
 
Posts: 3369
Joined: 11 Aug 2006, 08:02

Re: trinamic sixpack and c#

Postby Franklin » 15 Aug 2011, 18:47

So you just add those bytes up and you get the Position?

I get the end position right...

But while the motor is moveing i get a different Position...
I guess i did something wrong in adding the bytes...because i simple changed the to int...
Franklin
User
User
 
Posts: 4
Joined: 07 Jul 2011, 18:18

Re: trinamic sixpack and c#

Postby Olav Kahlbaum (TRINAMIC) » 22 Aug 2011, 07:40

Well it is not simply adding - you have to put the first byte into bits 31..24, the second byte into bits 23..16, the third byte into bits 15..8 and the fourth byte into bits 7..0 of the result value. This is something different than just adding (in the example we simply do this with bitwise (not logical) OR operators and SHIFT operators which should also work in C#).
User avatar
Olav Kahlbaum (TRINAMIC)
Site Admin
 
Posts: 3369
Joined: 11 Aug 2006, 08:02


Return to Modules / Interface issues / PC software

Who is online

Users browsing this forum: No registered users and 2 guests

cron