Checksum calculator help for AB ultra300i help req

More
22 Sep 2014 08:35 #51419 by scubasteve1
I'm trying to program my ultra3000 servo drive with rs-232 communicate. Calculating checksums by hand is getting very.... old. Any thoughts on how I could speed this process up? I just have to add the ASCII value of each character and convert to HEX, and use the last 2 digits. How could I do this through the linux terminal?






"6. Select the Settings tab
A. Verify that Emulation is set to VT100.
B. Click on the ASCII Setup button and make these selections:
Calculating the Checksum
The checksum value is used to verify that the data transferred
correctly. When the Ultra family drive receives a command, it verifies
that the checksum is correct before acting on the data.
To calculate the checksum value, you must obtain the ASCII value of
each character in the command string. (A decimal to ASCII conversion
table is on page C-8.) For example, the ASCII value for the number 5
is 53. To calculate the checksum value, you must add together all of
the ASCII values for the numbers or letters in the command you want
to send, subtract this value from 256, convert the result to a
hexadecimal number, and then use only the last two digits. It may
seem complicated, but after an exercise or two it will become clear.
Selected (checkmark) Not Selected (no checkmark)
Echo typed characters locally Send line ends with line feeds
Append line feeds to incoming line
ends
Force incoming data to 7 bit ASCII
Wrap lines that exceed terminal width"

Please Log in or Create an account to join the conversation.

More
22 Sep 2014 15:38 #51423 by cncbasher
i use an online checksum calc
onlinemd5.com/

there are many more on the internet

Please Log in or Create an account to join the conversation.

More
22 Sep 2014 23:28 - 23 Sep 2014 13:22 #51437 by ArcEye
Hi

I doubt there is an online calculator that does quite what the manual requires.

This is a C program that takes an input string, assigns the ascii value of each charactor to an array of int and then totals all the values.
It then subtracts it from 256 and outputs the resultant hex value.

You just pick the last 2 digits for your checksum.

There is no error checking and the strings are arbitarily set at max 20 charactors (which should be way too long)

Compile with gcc -o ascii2hex main.c

Use in the directory you compiled it with ./ascii2hex ABC - where ABC is the charactor string to convert

Hopefully of some use

regards
/*  Save code as main.c */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
int total;
int iarray[20];
char carray[20];
int x;

    strcpy(carray, argv[1]);
    
    for(x = 0; x < strlen(carray); x++)
        iarray[x] = carray[x];
    
    for(x = 0; x < strlen(carray); x++)    
        total += iarray[x];
        
    total = 256 - total;
    
    printf("\nHex of 256 minus total is 0x0%x or decimal %d\n", total, total); 
    
}
Last edit: 23 Sep 2014 13:22 by ArcEye.

Please Log in or Create an account to join the conversation.

More
23 Sep 2014 06:26 #51461 by andypugh

I'm trying to program my ultra3000 servo drive with rs-232 communicate. Calculating checksums by hand is getting very.... old. Any thoughts on how I could speed this process up?


Are you compiling standard commands as a one-time thing, or do you anticipate needing to send command strings indefinitely?

If you are going to have to do this indefinitely then I think you need to write/obtain some sort of filter file that takes a string as input and passes it through to the port with a checksum appended.

Please Log in or Create an account to join the conversation.

More
23 Sep 2014 15:07 #51480 by ArcEye

I'm trying to program my ultra3000 servo drive with rs-232 communicate. Calculating checksums by hand is getting very.... old. Any thoughts on how I could speed this process up?


Are you compiling standard commands as a one-time thing, or do you anticipate needing to send command strings indefinitely?

If you are going to have to do this indefinitely then I think you need to write/obtain some sort of filter file that takes a string as input and passes it through to the port with a checksum appended.


I read it that you were programming your drive (ie setting it up), as opposed to operating it, but good point if the latter.

The program could be adapted to send the complete string with checksum, albeit would need to know all the other protocols involved.

I imagine you are using putty or something similar and doing it by hand to set up the drive parameters?

regards

Please Log in or Create an account to join the conversation.

More
24 Sep 2014 09:22 #51512 by scubasteve1

Hi

I doubt there is an online calculator that does quite what the manual requires.

This is a C program that takes an input string, assigns the ascii value of each charactor to an array of int and then totals all the values.
It then subtracts it from 256 and outputs the resultant hex value.

You just pick the last 2 digits for your checksum.

There is no error checking and the strings are arbitarily set at max 20 charactors (which should be way too long)

Compile with gcc -o ascii2hex main.c

Use in the directory you compiled it with ./ascii2hex ABC - where ABC is the charactor string to convert

Hopefully of some use

regards
/*  Save code as main.c */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
int total;
int iarray[20];
char carray[20];
int x;

    strcpy(carray, argv[1]);
    
    for(x = 0; x < strlen(carray); x++)
        iarray[x] = carray[x];
    
    for(x = 0; x < strlen(carray); x++)    
        total += iarray[x];
        
    total = 256 - total;
    
    printf("\nHex of 256 minus total is 0x0%x or decimal %d\n", total, total); 
    
}


Arceye, thanks for the script I was looking into a character array.


I just need to program the drive this once hopefully. I have to re-configure for a different servo and servo settings and such, and hopefully set up for linuxcnc. I will post some info if anything good comes from this.

Thanks again,
Steve

Please Log in or Create an account to join the conversation.

More
24 Sep 2014 22:38 - 24 Sep 2014 22:40 #51533 by ArcEye
Hi

I managed to find the manual for programming these drives.
What a convoluted process, even Allen-Bradley don't bother producing a program to do it automatically.

I think the best I can do is the below amended program. It takes the input string as before, but outputs the string plus the last 2 digits of the hex code for the checksum
I checked some of the exercises in the manual and it outputs the correct checksums for them

Compile and use the same way as the previous one.
Then the output number can be cut and pasted directly in one operation

Example input and corresponding output

$./ascii2hex 0006D100012EBC

Output string is 0006D100012EBC08

regards
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
int total;
int iarray[20];
char carray[20];
int x;

    strcpy(carray, argv[1]);
    
    for(x = 0; x < strlen(carray); x++)
        iarray[x] = carray[x];
    
    for(x = 0; x < strlen(carray); x++)    
        total += iarray[x];

    total = 256 - total;
    
    sprintf(carray,"%2x", total); 
    x = strlen(carray);
    printf("\nOutput string is %s%c%c\n", argv[1], carray[x-2], carray[x-1]);
}
Last edit: 24 Sep 2014 22:40 by ArcEye.

Please Log in or Create an account to join the conversation.

More
26 Sep 2014 08:41 #51586 by scubasteve1
steve@ubuntu:~$ gcc -o ascii2hex main.c
steve@ubuntu:~$ gcc -o ascii2hex
gcc: fatal error: no input files
compilation terminated.
steve@ubuntu:~$ gcc -o ascii2hex ./main.c
steve@ubuntu:~$ ./ascii2hex
Segmentation fault (core dumped)
steve@ubuntu:~$ ./ascii2hex 111

Hex of 256 minus total is 0x0ffbff97d or decimal -4195971
steve@ubuntu:~$


Ok, something smells like newbie here..... what am I not doing here> I have the script saved in the root as main.c . I see the GCC command there with -o. is this just ascii2hex here? my ascii2hex file is in a sub-directory, should that be listed?

Please Log in or Create an account to join the conversation.

More
26 Sep 2014 13:32 - 26 Sep 2014 13:33 #51588 by ArcEye
Hi

First off use the new code, it gives an output you can just paste into your serial program.

Create a directory in your home folder and save it there as main.c
Open a terminal and cd to that dir

This code needs compiling into an executable ONCE
gcc -o ascii2hex main.c

That tells gcc to name the binary ascii2hex

Now in that dir you call the binary with
./ascii2hex xxxxxxxx
where xxxxxxx is the charactor string

There is no error checking, so if you do not provide a string, it will segfault.

Hopefully that clarifies

regards
Last edit: 26 Sep 2014 13:33 by ArcEye.

Please Log in or Create an account to join the conversation.

More
13 Oct 2014 10:28 #51993 by scubasteve1
Update here....

Thanks Arc, I was able to reset the drive to factory defualts. Annnnddd for some reason, Ultraware decided to discover the drive... now I can operate via ultraware which is muuccchhh better for now... I reall just want to use it to test out some stuff.

Please Log in or Create an account to join the conversation.

Time to create page: 0.080 seconds
Powered by Kunena Forum