New topic: 

2012R2 - odd behavior of MOD operator

<http://forums.realsoftware.com/viewtopic.php?t=46389>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        gbgb          Post subject: 2012R2 - odd behavior of MOD 
operatorPosted: Sun Dec 30, 2012 4:08 am                         
Joined: Tue May 15, 2007 2:47 am
Posts: 55                Last week I posted a question about problems with 
serial communication - thought there was a difference in operation between 
2011R4.3 and 2012R2. was told that there is no difference so I went on 
debugging my communication problem and found that it is a "software protocol" 
problem.
My application is based on the MODBUS protocol.
Consider the following function which is a MODBUS "read holding registers" 
command - the format of the function is in the remarks:
in my particular case the starting address is 0 and the quantity of registers 
is 20.
As can be seen there is a CRC function which in this case returns the value 
17910

a and b were put in as part of the debugging process to find out how each part 
in the proceeding line worked:
Both in 2011 and 2012 a gets the value of 45 (hex, 69 decimal) - correct.
however the b value gets in 2011 the value F6 (246 decimal - which is correct) 
and in 2012 the value C3B6 - where does this value come from??? It worked OK 
for the start and Length values in this function.

Function MB_Request_Read_Holding_Registers(Address As Byte, Start As Integer, 
Length As Integer) As string
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  'Function : MB_Request_Read_Holding_Registers
  'Purpose  : Generate a Read_Holding_Registers request
  'Parmaeters : Slave Address as Byte
  '     Function code 3 as Byte
  '     Starting Address as 2 Bytes
  '     Quantity of registers as 2 Bytes
  'Returns  : MB Message as String
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  
  Dim StrReturn As String
  Dim CRC as uint16
  dim a,b as string
  
  StrReturn = ""
  StrReturn = StrReturn + Chr(Address)
  StrReturn = StrReturn + Chr(3)
  StrReturn = StrReturn + Chr((Start-1) \ 256) + Chr((Start-1) Mod 256)
  StrReturn = StrReturn + Chr(Length \ 256) + Chr(Length Mod 256)
  
  CRC= CRC_16(StrReturn)
  a = chr(CRC \ 256)
  b = chr(CRC mod 256)
  StrReturn=StrReturn + chr(CRC \ 256) + chr(CRC mod 256)
  
  return  StrReturn
  
End Function
   
                             Top                gbgb          Post subject: 
Solved: 2012R2 - odd behavior of MOD operatorPosted: Sun Dec 30, 2012 4:26 am   
                      
Joined: Tue May 15, 2007 2:47 am
Posts: 55                Just noticed the other answers on my previous post. 
really seems like the UTF-8 problem.
Thanks   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to