Author Topic: Bypass FCS Error code using MDS100  (Read 13258 times)

gstavaris

  • Newbie
  • *
  • Posts: 1
  • I'm a llama!
    • View Profile
Bypass FCS Error code using MDS100
« on: January 31, 2007, 05:03:48 AM »
Hi support
I am trying to use MDS100 with labview programming enviroment.
MDS100 is working fine without sending address prefix "@F0"
How can I bypass FCS code? or how can I calculate myself FCS code?
I have try to sent the following command but it does not working
@F0?P0101hello world 00* + carriage return
I found somewhere that 00* is wildcard for FCS is that right?

thanks a lot
giannis

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Bypass FCS Error code using MDS100
« Reply #1 on: January 31, 2007, 03:11:17 PM »
wildcard FCS is supported on all the PLC, but may not be implemented on MDS100.

You can calculate FCS by following the C or VBASIC examples. The C examples can be found on the PLC's user manual:

http://www.tri-plc.com/MD-man.pdf

For VB6 example, please check:

http://www.tri-plc.com/applications/VBsample.htm

Email: support@triplc.com
Tel: 1-877-TRI-PLCS

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Re:Bypass FCS Error code using MDS100
« Reply #2 on: March 07, 2007, 01:40:47 PM »
Note that in calculating the FCS and converting to ASCI, the symbols :, ;, <, etc. between the digit "9" and character "A" are not used. need to check if number is between 58 and 64 decimal, then add 7 (think thats the number).

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Bypass FCS Error code using MDS100
« Reply #3 on: March 07, 2007, 02:07:30 PM »
The FCS is computed on the ASCII code, not binary number. So all characters from '@' till the last character before the FCS and '*' are invovled in the FCS XOR computation.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Re:Bypass FCS Error code using MDS100
« Reply #4 on: March 07, 2007, 05:01:15 PM »
I'll disagree, here's the "C" code that accepts the PLC FCS and has

   for ( j = 1;  ( j <= k ) ; j++)
         {
         result ^= ReadArray[j];   //XOR operation
         }   
      fcs_high = 48 +(result>> 4);
      /*If it's more than "9" then make it Alpha*/
      if (fcs_high >  57) fcs_high = fcs_high + 7;
      fcs_low = 48 + (result & 0b00001111);
      /*If it's more than "9" then make it Alpha*/
      if (fcs_high >  57) fcs_high = fcs_high + 7;

and here's the code that calculates the FCS that is accepted by the PLC

   for ( j = 1; (ReadArray[j] == 0  ) || ( j <= 18 ) ; j++)
      {
      result ^= ReadArray[j];   //XOR operation   
      }   
      fcs_high = 48 +(result >> 4);
      /*If it's more than "9" then make it Alpha*/
      if (fcs_high >  57) fcs_high = fcs_high + 7;
      fcs_low = 48 + (result & 0b00001111);
      //If it's more than "9" then make it Alpha
      if (fcs_low > 57)   fcs_low = fcs_low + 7;      
      ReadArray[19] = fcs_high;   // Bit 19 - FCS high digit   
      ReadArray[20] = fcs_low;   // Bit 20 - FCS low digit

Both have been working well for some months now.
 It wasn't until I added a PC into the RS-485 to monitor what was being sent from the PLC and not accepted by the PIC on the other end, and then using TLSERVER FCS calculator that I saw what was happening. The example in the manual happens to use a data string that calculates to a FCS that the digits are 9 or less. This convention is used by other equipment also.


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Bypass FCS Error code using MDS100
« Reply #5 on: March 07, 2007, 09:48:01 PM »
Well, the FCS is computed from XOR'ing all the characters involved which is what's shown in your routine too.

However, the computed FCS result is a 8 bit binary number which need to be converted into two ASCII characters (00 to FF) to represent the number.  An example routine is shown below as htoa2() function.

/*------------------------------------------------------------------------*/
/*  convert the  number "value" into a x-byte ASCII characters to         */
/*  represent the value in Hex code                                       */
/*------------------------------------------------------------------------*/

int htoax(long value, unsigned char *string, unsigned char digit)
{
  register int temp;
  register unsigned char i;

  for (i=0;i<digit;i++) {     /* No of digit to represent variable */
    temp = value % 16;         /* compiler only supports 16-bit logical AND */
    if (temp < 0) temp += 16;
    if (temp < 10) string[digit-1-i]=temp+0x30;
    else string[digit-1-i]=temp+0x37;
    value = value>>4;
  }
  return(1);
}
/*-----------------------------------------------------------------------*/

int htoa4(unsigned int value, char *string)
{
   htoax(value, string, 4);
}
/*-----------------------------------------------------------------------*/

int htoa2(unsigned char value, unsigned char *string)
{
   htoax(value, string, 2);
}
« Last Edit: March 07, 2007, 09:49:23 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Re:Bypass FCS Error code using MDS100
« Reply #6 on: March 08, 2007, 05:36:32 AM »
We are in agreement now, the factor of 7 to jump over the symbols is there. :) The example in the manual should be adjusted to reflect that the non-alpha-numeric symbols are not used. I spent considerable time on this issue, not knowing whether it was an issue with RS-485 (first time user), programming the PLC, hardware or software of the PIC embedded system.