CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Modbus TCP - SOLVED!!!
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Modbus TCP - SOLVED!!!
PostPosted: Tue Oct 01, 2013 1:59 pm     Reply with quote

Hi All,

Hardware: Olimex PIC-MAXI-WEB
PIC: 18F97J60
Compiler: PCH 5.012
With MPLAB 8.92 --- **Edit**

I'm trying to run Example: "ex_modbus_slave".
Using the TCP/IP Modbus drivers.

I've modified the example code as follows:
(as per the instructions on Modbus.c)
(just an Extract since we are not allowed to copy the example)
Code:
#elif defined(__PCH__)
#include <18f97j60.h>
#fuses HS, NOWDT, ETHLED
#use delay(clock=25M)
#else
#include <16F887.h>
#fuses HS,NOWDT
#use delay(clock=20M)
#endif

// TCP/IP DEFINES:
#define MODBUS_PROTOCOL               MODBUS_PROTOCOL_TCPIP 
#define MODBUS_TYPE                   MODBUS_TYPE_CLIENT
#define MODBUS_SERVER_LISTEN_PORT     502
#define MODBUS_LISTEN_SOCKETS         1
#define MODBUS_BUFFER_SIZE            64
#define MODBUS_SERVER_TIMEOUT         5
#define MODBUS_SERVER_ADDR_0          192
#define MODBUS_SERVER_ADDR_1          168
#define MODBUS_SERVER_ADDR_2          0
#define MODBUS_SERVER_ADDR_3          95 

#include <modbus.c>

#define MODBUS_ADDRESS 0xF7

int8 swap_bits(int8 c)
{


As you can see i removed all the original defined and replaced them with the ones for TCP/IP

I'm using the latest Stack from CCS which i believe to be 5.42.

Upon compile I'm getting 100 errors, but most of them seem to be the kind that goes away when you correct something else:

Quote:
Executing: "C:\Program Files (x86)\PICC - PCH\Ccsc.exe" +FH "ex_modbus_slave.c" #__DEBUG=1 +ICD +DF +LN +T +A +M +Z +Y=9 +EA #__18F97J60=TRUE
*** Error 32 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 230(79,102): Expecting a , or )
*** Error 48 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 230(104,111): Expecting a (
*** Error 43 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 230(112,113): Expecting a declaration
*** Error 32 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 239(80,104): Expecting a , or )
*** Error 48 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 239(106,113): Expecting a (
*** Error 43 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 239(114,115): Expecting a declaration
*** Error 32 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 361(26,36): Expecting a , or )
*** Error 43 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 361(43,44): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 361(44,45): Expecting a declaration
*** Error 48 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 375(1,8): Expecting a (
*** Error 43 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.h" Line 375(15,16): Expecting a declaration
*** Error 119 "C:\Program Files (x86)\PICC - PCH\drivers\tcpip\hardware.h" Line 149(13,53): Please define your MAC/NIC I/O settings


As seen above, i believe the real error is the last one..

I've been looking around but Ive been unable to clear that error and I'm at a loss on where or what else to try.

Can anyone shed some light on this? the stack is composed of so many files I'm having a hard time following it...


regards,
G
_________________
CCS PCM 5.078 & CCS PCH 5.093


Last edited by Gabriel on Fri Oct 11, 2013 11:30 am; edited 1 time in total
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Oct 01, 2013 8:27 pm     Reply with quote

someone?

I just need it to compile... if it works or not i dont care at this stage..
_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 01, 2013 9:47 pm     Reply with quote

We can't help you unless we also contact CCS, per your previous thread
on this topic, and request the stack:
http://www.ccsinfo.com/forum/viewtopic.php?t=51225
For example, I can't just pull up the compiler and test it. I don't have
the stack.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Oct 01, 2013 10:14 pm     Reply with quote

Hi PCM,

Im pulling my hair here...

i got the compiler, Got the Modbus Drivers, got the stack, had some previous experience using the stack on C18... so i had some confidence...

I tried loading the examples.. managed to configure the example to TCP/IP.. and thus it now reads the Modbus TCP Drivers..

Since I last posted ive managed to eliminate one error by modifying the hardware profile to understand im using a 18F97j60...
but then I simply got more of the repetitive bogus errors...

Quote:
*** Error 43 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.c" Line 1241(12,13): Expecting a declaration
*** Error 48 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.c" Line 1241(13,26): Expecting a (
*** Error 48 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.c" Line 1242(13,18): Expecting a (
*** Error 48 "C:\Program Files (x86)\PICC - PCH\drivers\modbus_app_layer_tcpip.c" Line 1242(21,40): Expecting a (

REPEAT TIMES 100.. 95% on .c the other on .h...


its the lack of information that's killing me...

There is absolutely no information on how to configure the stack for modbus... so i read the MODBUS TCP/IP spec and that didnt help...

and the only hint CCS left in the files was for the defines on modbus.c but that was easy enough...

i see no precedence here on the forum for modbus TCP either... atleast that i have found...

sign... i guess ill spend the next month brute forcing this into compilable somthing.


G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 2:12 am     Reply with quote

It doesn't look like a problem specific to MODBUS or TCP stack, just a C syntax error brought up at some place in the code.

As a general suggestion, errors must be parsed top down, second and succeding errors might be just follow-ups. Probably the problem it in the file compiled before the displayed error location. You should think of trivial issues like non-printable characters hidden in the source file etc. Trial and error, e.g. inserting new code or commenting lines and complete source includes usually reveals the primary error location.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 2:29 am     Reply with quote

"I'm using the latest Stack from CCS which i believe to be 5.42."

Err, 5.42 is the latest version of Microchip's TCP/IP stack; 5.42.08 in fact, and they are beta testing 6.00.04. I didn't know that CCS was now able to compile the Microchip stack, and the last version ported by CCS was 3 or 4.something; 3.75 rings a strong bell.

If CCS have updated the TCP/IP stack with V5 of the compiler then that's a good thing to know, and is a potentially strong reason for me "upgrading".
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 6:09 am     Reply with quote

Hi RF...

i said "i believe" because i too was under the impression that ccs had not updated their stack.

However, in the readme file included with the stack it does say 5.42.... im on my cell right now but ill post a direct quote from the readme in 2 hours...
Believe me i was surprised too!

Ive been a part of this forum for a couple of years now. I know how this forum operates, i might not be PCM_P... But i do try to help when i can....

Why would you think im lying, or not done my "homework". But hey, if your fishy bells help me find the solution to my problem let em ring...

Ill post a direct quote in 2 hours or less..

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 6:15 am     Reply with quote

Fvm, thanks for your input...

It does look like a syntax error, and i found one early on this journey... however the errors all get reported to the ccs provided drivers so im a little worried about messing them up...

Ill will post a couple of lines around the first error line to see if you can provide some insight.

Thanks,
G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 7:14 am     Reply with quote

My guess would be, that they are in the process of porting 5.42. You asked for the stack, and they sent you the 'half done' 5.42 version.....

Porting Microchip code, is getting easier, with many sections working directly. Years ago, CCS 'promised' that the compiler would soon be able to compile Microchip code, and while it has never happened, there have been slow moves in that direction.

If you want it working quickly, then I'd go back to CCS, point out that it doesn't compile, and ask for the 'last known good' stack. Otherwise it does sound like it is perhaps surprisingly close (CCS has the habit of producing hundreds of subsequent errors for a single fault), and I'd say it looks like there are just a few actual errors possibly linking to data types or function declarations.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 7:47 am     Reply with quote

From the Readme File:

Quote:
********
Microchip TCP/IP Stack Version Log:
********

Note: Please file bug-reports/bug-fixes at http://support.microchip.com/ or post
to the Microchip TCP/IP -> Ethernet Forum at http://forum.microchip.com/
Look for stack updates at http://www.microchip.com/mal/

********
v5.42.04 Oct 2012
********
Changes:
1. (MRF24WB/G) Patch update features are added into MRF24WB0MA/B and MRF24WG0MA/MB.
MRF24WB0MA/B (no RF module FW version update is necessary)
Serial Port (Xmodem)



thanks Ttelmah, ill check some more declarations and if i cant find anything ill let ccs know.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 8:14 am     Reply with quote

Code:
int1 modbus_write_multiple_coils(unsigned int8 address, unsigned int16 start_address, unsigned int16 quantity, unsigned int8 *values);

/*
write_multiple_registers
Input:     int8       address            Unit Identifier
           int16      start_address      Address to start at
           int16      quantity           Amount of registers to write to
           int16*     values             A pointer to an array holding the data to write
Output:    int1                          0 if successful placed in TX buffer, 1 if unsuccessful
*/
int1 modbus_write_multiple_registers(unsigned int8 address, unsigned int16 start_address, unsigned int16 quantity, unsigned int16 *values);

/*
read_file_record
Input:     int8                address            Unit Identifier
           int8                byte_count         Number of bytes to read
           read_sub_request*   request            Structure holding record information
Output:    int1                                   0 if successful placed in TX buffer, 1 if unsuccessful
*/
int1 modbus_read_file_record(unsigned int8 address, unsigned int8 byte_count, modbus_read_sub_request *request);

/*
write_file_record
Input:     int8                address            Unit Identifier
           int8                byte_count         Number of bytes to read
           read_sub_request*   request            Structure holding record/data information
Output:    int1                                   0 if successful placed in TX buffer, 1 if unsuccessful
*/
int1 modbus_write_file_record(unsigned int8 address, unsigned int8 byte_count, modbus_write_sub_request *request);


its the "modbus_read_file_record" line that gives me the first error...
(second to last line)

i dont see any errors...
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 8:23 am     Reply with quote

I'd say that the modbus_read_sub_request type has not yet been declared.
Might be to do with the order files need to be loaded.
Look for where this is defined.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 9:42 am     Reply with quote

jejeje that IS the declaration of the function!
_________________
CCS PCM 5.078 & CCS PCH 5.093
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 9:52 am     Reply with quote

I think Ttelmah meant the variable:

int1 modbus_read_file_record(unsigned int8 address, unsigned int8 byte_count, modbus_read_sub_request *request);
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 02, 2013 12:42 pm     Reply with quote

.... yeah you are right... sorry.

anyways, further developments on this:

I changed the define from: ------------** EDIT: Copied the same line***
Code:
#define MODBUS_TYPE                   MODBUS_TYPE_CLIENT

to
Code:
#define MODBUS_TYPE                   MODBUS_TYPE_SERVER


Servers are slaves and clients are masters which makes it even more confusing... but anyways that brought me down to 44 errors...

and now 43 since i noticed TCPPutArray is not declared in TCP.h..

so...i push on...
_________________
CCS PCM 5.078 & CCS PCH 5.093


Last edited by Gabriel on Wed Oct 09, 2013 3:37 pm; edited 1 time in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group