Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a PIC with a Real Time Clock (RTC) connected. I can send the date and time manually to the PIC RTC to set the time. However, I wish to do it automatically via the serial port using C# when the PIC sends a prompt.
The current method I use is to send a menu item "Set_Time" to the PIC,
The PIC responds with: Please send date in DD/MM/YY.When I manually enter the date and send, the PIC then responds with: Please send time in HH:MM:SS 24h format. Again I manually enter the time in the requested format. As I am new to C# I cant figure out how to mechanise this procedure, after many attempts I done a Google search without success.
Any ideas please ? :confused:

Presumably, you are using a SerialPort to connect to the PIC, and this is working fine?
In which case, check the serial port data for the string or bytes that identifies a "give me the time" request from the PIC, and then send it the time in the appropriate format:
DateTime now = DateTime.Now;
string date = now.ToString("dd/MM/yy");
string time = now.ToString("HH:mm:ss");
Share this answer
Thanks for the quick response. I'll give that a try and let you know how I get on.
Share this answer

I developed a state-driven serial port programming language in C# and it really makes it easy to communicate with the serial port. It has a built-in debugger also to find and fix the errors just in time.

Would you please try it with the following state ?

state Init
  $date = datetime("dd/MM/yy");
  $time = datetime("HH:mm:ss");
end state

state Idle
end state

It is freely available on sourceforge. If you have any questions, please feel free to ask.[^][^]

Thank you,

Share this answer
yoyogesh 2-Apr-12 6:28am    
i am trying to communicate with the relay driver circuit in C #.

Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900