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

Problem with function gets(string) rs232

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



Joined: 25 Oct 2015
Posts: 3

View user's profile Send private message

Problem with function gets(string) rs232
PostPosted: Sun Oct 25, 2015 8:36 am     Reply with quote

Hi I have a problem with the function gets(string).

I make a program in C sharp that send a string by serial port. The string is a hexadecimal number of 6 characters.

When I try receive this with CCS with function gets(string) in the rda interrupt the program does nothing, it ignores the received data from rs232.

Should I send a null character at the end of the string with C sharp?

Thanks
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Sun Oct 25, 2015 9:27 am     Reply with quote

A few things of note:

1. Never use gets() in the RDA ISR. The ISR is for receiving "1" character
2. There is almost never any need to use gets() to begin with.
3. Look at ex_sisr.c located in the examples directory of your PICC install. It will show you how to properly use the RDA interrupt. The only gotcha is the buffer size in that example needs to be a power of 2 (if you don't want this, search the forum for ex_sisr.c and see other threads on how to change it for this).

The big thing here is you need to start looking at it from an "embedded" perspective vs a desktop application perspective. The method gets() can hang in multiple ways. While this can be less problematic in a windows program (I still don't use it here either though), it is absolutely killer for an embedded program. Once you hang, your device is useless.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Oct 25, 2015 9:34 am     Reply with quote

Hi,

You are making a classic mistake with the #int rda serial interrupt handler. This interrupt is designed to receive ONE character, and one character only, which you do with the getc function. If you want to receive multiple characters, create an array and fill the array as characters are received. Have the C# program prefix the data with a 'start' character, such as '!', and append the data with 'stop' character, such as a CR of LF. Start buffering when '!' is received and stop with 'CR' or 'LF' is received.

To answer your specific question, the gets function will hang until a carriage return is detected. You could add that to your C# program.
_________________
John

If it's worth doing, it's worth doing in real hardware!
kevinvig7



Joined: 25 Oct 2015
Posts: 3

View user's profile Send private message

PostPosted: Sun Oct 25, 2015 10:27 am     Reply with quote

Thanks for your answer!

Can you give me an example of a program that does this?
will have to send a string or character followed ?

Thanks!
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Oct 25, 2015 7:02 pm     Reply with quote

Hi,

Read this thread, it describes how to do what you are asking: http://www.ccsinfo.com/forum/viewtopic.php?p=199146&highlight=#199146
_________________
John

If it's worth doing, it's worth doing in real hardware!
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