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

RS485 half duplex communication
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Sun Aug 01, 2010 5:55 pm     Reply with quote

anyone? Please...................
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 01, 2010 8:16 pm     Reply with quote

Use Google to find this information. Example:
http://www.control.com/thread/1274413114

Read articles about RS-485 and Modbus:
http://www.bb-elec.com/technical_library.asp

http://en.wikipedia.org/wiki/EIA-485

http://en.wikipedia.org/wiki/Modbus
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Aug 02, 2010 5:22 am     Reply with quote

First problem I see:-
Code:

char PCgetc()
{
   in_char = 0;
   while(!in_char);
   return in_char;
}

With the above code you could miss an incomming char. If you enter this routine after a char has been recieved you will miss it:-
Try
Code:

char PCgetc()
{
   char c;
   while(!in_char);
   c = in_char;
   in_char = 0;
   return c;
}


Second problem:-
Code:

int8 PCgetInt()
{
   int8 i, s[3];
   for(i=0; (s[i]=PCgetc()) != '\r' && i<3; ++i);
   fprintf(PC,"%s",s);
   return atoi(s);
}

You are trying to use s as a string but you only allocate enough storage for 3 chars, you don't initialise the array to all '\0' and your loop allows 3 chars to be read and will also terminate on a '\r' so unless the third char is a '\0' the string will not be null terminated.
You will most likely see garbage or a corruption of your data when output.
atoi will also fail.
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 Previous  1, 2
Page 2 of 2

 
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