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

Wierd Echo on RS-232 Transmission

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
whmeade10



Joined: 27 Jan 2004
Posts: 12

View user's profile Send private message

Wierd Echo on RS-232 Transmission
PostPosted: Thu Sep 13, 2007 7:28 am     Reply with quote

I am exchanging ASCII information with a GE FANUC PLC via RS-232. I receive a 'P1 and return character' from the PLC and I attempt to send information back. What is happening, and I can't figure it out, is I am sending the P1 I received then the data is attached. Is there a buffer I have to clear?

Example: Receive - P1 then return character
Transmit - P1029640006100781 and a return

I can't figure out how the P1 is being sent. My code is below. I am using version PCWH Compiler v4.053.

Code:

#include <18F452.h>
#use delay(clock=20000000)
#fuses HS,PROTECT,NOLVP,PUT,BROWNOUT, NOWDT                                // set fuses
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)    // setup serial communications

#include <string.h>
#include <input.c>

// ********** DEFINE VARIABLES ***********************************************************************
byte i;
int16 adc_value, pulse_count, ms_final, scale_no;

// ********** START OF MAIN PROGRAM ******************************************************************
void main()
{
   char input_str[3];                                           // set max serial input string to 2
     
   adc_value = 2964;
   pulse_count = 61;
   ms_final = 78;
   scale_no = 1;
   
   while(TRUE)                                                  // start of continious loop
   {
      Get_string(input_str,3);                                  // gets the string
     
      If ((input_str[0] == 'P') && (input_str[1] == '1'))       // check incomming serial data for POLL
      {
          printf("%05lu%05lu%04lu%01lu\r", adc_value, pulse_count, ms_final, scale_no,);
      }                                                         // end of IF statement     
   }                                                            // end of program loop
}                                                               // main end
Ttelmah
Guest







PostPosted: Thu Sep 13, 2007 8:39 am     Reply with quote

Ignoring anything else, your input string needs to be larger. A 3 character string, requires _4_ characters of storage (to include the terminating '\0'). the 'Get_string' function, called with '3' as the length limit, needs _4_ characters of storage.
The reason you are getting the P1 echoed, is that this is what 'Get_string' does. It is designed to get a string being typed in at the other end, and echo the characters. Look at it's code. Every character that is getc received, it immediately sent out again. Simple take tget Gt_string code out of input.c, and make your own version, with the 'putc' entries removed.

Best Wishes
whmeade10



Joined: 27 Jan 2004
Posts: 12

View user's profile Send private message

PostPosted: Thu Sep 13, 2007 9:18 am     Reply with quote

Thanks Ttelmah for the quick reply. I changed the get_string function and increased the string length from 3 to 4 and everything is working perfectly. Thanks agan for taking the time to answer my question.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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