View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Oct 02, 2013 1:08 pm |
|
|
what the hell is this?
Code: | for(i=modbus_rx.data[1],j=0; i < modbus_rx.data[1]+modbus_rx.data[3]; ++i,++j)
{
if(bit_test(modbus_rx.data[5],j))
bit_set(coils,7-i);
else
bit_clear(coils,7-i);
} |
Thats one wierd looking For declaration....
gives an error: "expect ;" _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Wed Oct 02, 2013 2:10 pm |
|
|
Actually looks perfectly OK.
I'd suspect an error a few lines before.
As has been mentioned many times, CCS often fails to see errors till a few lines later, when something more complex, then triggers a problem...
If any C 'operation', you can have multiple operations separated by commas.
So, the initialisation 'part', initialises two variables, as does the increment part. Normal, and acceptable.
Best Wishes |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu Oct 03, 2013 4:01 pm |
|
|
more on this...
EDIT: i Just realized Modbus TCP servers dont have addresses because the use IP Addresses... but the same thing happens with other members of that struct.... like "func"
I got down to 43 errors... mostly because i got confused on the master slave / client server terms.... I want a Slave/Server.
anyways, now im getting +35 errors as such:
Quote: | *** Error 56 "ex_modbus_slave.c" Line 172(21,28): Element is not a member
*** Error 56 "ex_modbus_slave.c" Line 174(27,31): Element is not a member
*** Error 51 "ex_modbus_slave.c" Line 176(13,17): A numeric expression must appear here |
First error references to this line:
Code: | while(!modbus_kbhit());
delay_us(50);
//check address against our address, 0 is broadcast
if((modbus_rx.address == MODBUS_ADDRESS) || modbus_rx.address == 0) // <----------------------THIS
{
switch(modbus_rx.func)
{
case FUNC_READ_COILS: //read coils
case FUNC_READ_DISCRETE_INPUT: //read inputs |
obviously refering to this variable: modbus_rx.address
so, checking the declaration i find the following:
Code: | #if (MODBUS_TYPE == MODBUS_TYPE_CLIENT)
typedef struct _MBAP_HEADER {
unsigned int16 TransactionIdentifier; //Transaction Identifier of message
unsigned int16 ProtocolIdentifier; //Protocol Identifer of message Modbus Protocol = 0
unsigned int16 Length; //Number of bytes in message including Unit Identifier
unsigned int8 UnitIdentifier; //Unit Identifier of message
} MBAP_HEADER;
struct {
unsigned int8 address; //Unit Identifier of received message
unsigned int16 len; //Number of data bytes in the received message
function func; //The function of the received message
exception error; //Error recieved, if any
unsigned int8 data[MODBUS_BUFFER_SIZE]; //Data of the received message
} modbus_rx;
struct {
MBAP_HEADER MBAPHeader; //MBAP Header of transmit message
function func; //The function of the transmit message
unsigned int8 data[MODBUS_BUFFER_SIZE]; //Data of the transmit mesage
} modbus_tx;
#else
typedef struct _MBAP_HEADER {
unsigned int16 TransactionIdentifier; //Transaction Identifier of message
unsigned int16 ProtocolIdentifier; //Protocol Identifer of message Modbus Protocol = 0
unsigned int16 Length; //Number of bytes in message including Unit Identifier
unsigned int8 UnitIdentifier; //Unit Identifier of message
unsigned int8 WhichSocket; //Not part of MBAP Header, added to determine which socket the server is to send response to
} MBAP_HEADER;
struct {
MBAP_HEADER MBAPHeader; //MBAP Header of received Message
unsigned int16 len; //Number of data bytes in the received message
function func; //The function of the received message
unsigned int8 data[MODBUS_BUFFER_SIZE]; //Data of the received message
} modbus_rx[MODBUS_LISTEN_SOCKETS]; |
The problem i have is that "address" is only a member if configured as a CLIENT as per the #if at the begining...
NOTICE: there are 2 posible defs. for modbus_tx.
I am using the SLAVE example, trying to use it as a SERVER... as per this definition:
Quote: | TCP must establish a connection before transferring data, since it is a connection-based protocol. The Master (or Client in Modbus TCP) establishes a connection with the Slave (or Server). |
from this site: http://www.simplymodbus.ca/TCP.htm
i thought it might be a mistake on the driver.. you know just a simple incorrect define... but it throws millions of errors more if i change the define from CLIENT to SERVER...
any sugestions?
G, _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu Oct 03, 2013 4:17 pm |
|
|
I think... ill have to write my own example...
obviously the slave example is not made to allow TCPIP communications..
At least i think i know now whats wrong... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Oct 05, 2013 8:52 am |
|
|
Can Anyone Confirm there is an Extra #endif at the end of driver: "modbus_app_layer_tcpip.h"
This driver is available on both PCM & PCH so a lot of you should have it.
Thanks..
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Oct 05, 2013 10:04 am |
|
|
I got this down to 5 errors... but im really stuck on this one:
ERRORS:
Quote: | Executing: "C:\Program Files (x86)\PICC - PCH\Ccsc.exe" +FH "ex_modbus_SERVER.c" #__DEBUG=1 +ICD +DF +LN +T +A +M +Z +Y=9 +EA #__18F97J60=TRUE
*** Error 32 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\MODBUS\modbus_app_layer_tcpip.h" Line 370(26,36): Expecting a , or )
*** Error 43 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\MODBUS\modbus_app_layer_tcpip.h" Line 370(43,44): Expecting a declaration
*** Error 36 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\MODBUS\modbus_app_layer_tcpip.h" Line 370(58,63): Expecting a ; or ,
*** Error 43 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\MODBUS\modbus_app_layer_tcpip.h" Line 370(64,65): Expecting a declaration
*** Error 58 "C:\Users\Foo-Bar\Documents\1. PIC Developement\CCS Compiler\MODBUS\modbus_app_layer_tcpip.c" Line 1389(49,50): Expecting a close paren
5 Errors, 0 Warnings. |
LINE 370:
Code: | void ModbusConnectedTask(TCP_SOCKET socket,unsigned int8 which); |
LINE 1389:
Code: | ModbusConnectedTask(socket[i],i); |
no errors above or after... the mentioned lines...
Everyone with PCM and PCH should have the drivers in question...
Please help...
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Oct 08, 2013 11:31 am |
|
|
Anything? anyone?
... Im still stuck on my last post.
g. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 08, 2013 11:39 am |
|
|
Quote: | Everyone with PCM and PCH should have the drivers in question...
Im still stuck on my last post.
|
If we truly have all the files needed to test project (by simply owning
the compiler), then post the main C source filename. We can then make
a project in MPLAB and do a test compilation.
Remember, we (or most of us) don't have any special TCP/IP files
provided by Darren. If you are using those files, then we can't duplicate
your test. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Oct 08, 2013 1:33 pm |
|
|
Hi, Thanks for your reply.
As i said earlier, anyone with PCM or PCH _should_ have all 7 files required for Modbus: RTU, ASCII and TCP/IP
(even those without the Stack)
I got them originally with PCM 4.135
however as you say, most people wont have the TCP/IP Stack.
so most people wont be able to compile Modbus TCP.
The Modbus example does not compile directly for TCP. its written for RTU and ASCII.. ive done the changes i saw as necessary and got it to "compile" to its current state of 5 remaining errors..
current error seems to be related to the "TCP_SOCKET Socket" declaration on tcp.h , but I'm not buying it.
Its like every change i do or try i get other errors saying that something is not declared or declared wrong when it IS declared and Properly too!
If you could provide some debugging method or just some debugging pointers in general that might help me find the error... at this point i appreciate Any kind of help..
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 09, 2013 12:53 pm |
|
|
I'm working on it. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Oct 09, 2013 1:18 pm |
|
|
I don't know if this is "legal" so ill just throw it out there..
Can i give you the modified example im using/made by posting it here or PM? so that you can reproduce my errors
its basically the provided example modified to reference the modbus TCPIP variables etc...
Thank you so much for helping me out.
g. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 09, 2013 1:24 pm |
|
|
I have requested the TCPIP driver package from CCS just a few minutes
ago. If it's possible to do so briefly, you could give me a list of your
mods to the code so that I can duplicate your development environment. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Oct 09, 2013 2:08 pm |
|
|
Everything on: ex_modbus_slave
im copying chunks of code of the main changes with a first and last line of ORIGINAL driver code so you can see what ive changed between those lines...
Code: | #include <18f97j60.h>
#fuses HS, NOWDT, ETHLED
#use delay(clock=25M)
// TCP/IP DEFINES:
#define STACK_USE_CCS_PICEEC 1//18f97j60
#define MODBUS_TYPE MODBUS_TYPE_SERVER
#define MODBUS_PROTOCOL MODBUS_PROTOCOL_TCPIP
#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> |
Code: |
setup_adc_ports(NO_ANALOGS);
//----------------------------
TickInit();
StackInit();
//----------------------------
modbus_init();
while(TRUE)
{
//-----------------------------------------------
StackTask();
ModbusTask();
//-----------------------------------------------
while(!modbus_kbhit()); |
The first IF inside the main() has been commented out since MODBUS_ADDRESS is no longer applicable since Modbus TCP uses an IP address... the define for MODBUS_ADDRESS has been commented out too..
Most importantly all references to:
has been changed to:
Code: | modbus_rx[MODBUS_LISTEN_SOCKETS].func |
the same applies to other members of that struct appearing throughout the example..
All references to MODBUS_ADDRESS have been changed to:
Code: | modbus_rx[MODBUS_LISTEN_SOCKETS].MBAPHeader
|
except in the first if which has been commented out..
Ive included in my project all CCS provided Modbus files in case i had to change or modify anything... but i didnt
i think that covers it...
I cant tell you how much i Appreciate your help...
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 09, 2013 2:27 pm |
|
|
Darren emailed me the package right now, but he says this:
Quote: |
Is he trying to do Modbus over RS232/RS485 or Ethernet? If he is trying
to do it over Ethernet, we have some new code/examples but we haven't
put them in the stack yet. |
Why don't you contact Darren and ask him for the new examples.
Maybe that will solve your whole problem. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Oct 09, 2013 3:10 pm |
|
|
I bet that would!
Ill shoot an email right away to CCS support.
Man, that would be incredible...
Thank you for your help.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|