View previous topic :: View next topic |
Author |
Message |
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
Posted: Wed Mar 13, 2013 11:49 pm |
|
|
Thank you all and specially Ttelmah for helping me in my project work:
This is the reply i am now recieving with my software
Tx:01 03 00 00 00 08 44 0C
Rx:01 03 10 00 88 00 77 00 66 00 55 00 44 00 33 00 22 00 11 9B 94
Thanks again & best Regards;
Ashraf |
|
|
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
Posted: Wed Mar 20, 2013 12:21 am |
|
|
Code: |
while(TRUE)
{
while(!modbus_kbhit());
...................................
default: //We don't support the function, so return exception
modbus_exception_rsp(MODBUS_ADDRESS,modbus_rx.func,ILLEGAL_FUNCTION);
}
}
My code // which does not run
|
Here my code does not run because the program stuck at
while(!modbus_kbhit());
line
Code work fine when i continuously query data but it stuck when i stop my query
how can i resolve this problem?
Thanks
Ashraf |
|
|
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
Posted: Wed Mar 20, 2013 12:43 am |
|
|
Code: | while(!modbus_kbhit()&&(++timeout<50000)); // 1/2 second |
I use this line instead of
Code: | while(!modbus_kbhit()); |
and now code is working.
And now trying to imlement RS485.
Thanks
Ashraf |
|
|
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
|
Posted: Tue Mar 26, 2013 4:16 am |
|
|
Dear All;
I am still in the process of finalizing my code and i found 1 more problem which i want to resolve and need guidance.
Code: |
timeout = 0;
while(!modbus_kbhit()&&(++timeout<50000)); // 1/2 second
|
When i use this peace of code send a query to my slave pic from PC, the slave PIC send the reply on continuous basis after every second.
until i send the query with different address.
Code: |
while(!modbus_kbhit());
|
and when i use this peach of code in while(1) loop the program stuck at this line and i am unable to execute my other part of code.
Where would i fix this code or what am i doing wrong
Regards;
Ashraf |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Tue Mar 26, 2013 5:46 am |
|
|
How have you declared the variable 'timeout'?
Actually a complete program would be helpful now after so many changes.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Tue Mar 26, 2013 5:54 am |
|
|
I think what you would need, is:
Code: |
timeout = 0;
while(!modbus_kbhit()&&(++timeout<50000))
; // 1/2 second
if (timeout<50000)
{
//Put the Modbus reply code here
}
//Then the other code
|
As shown in the original post, the code will think there _has_ been a query request, when timeout triggers, and so will send the reply.
Best Wishes |
|
|
|