| Author |
Message |
|
mdanell
|
Post subject: Send text to pic example Posted: Tue Jun 12, 2012 5:13 am |
|
Joined: Tue Jun 12, 2012 5:04 am Posts: 5
|
|
Hello, i use your Open Source Framework 3.0.0.0
not I send a text from pc to pic and vice versa ... as it should send the text from pc to pic?
thanks and sorry for my bad English
|
|
 |
|
 |
|
Simon Inns
|
Post subject: Re: Send text to pic example Posted: Tue Jun 12, 2012 6:23 am |
|
Joined: Thu Apr 01, 2010 6:23 am Posts: 889
|
|
 |
|
 |
|
mdanell
|
Post subject: Re: Send text to pic example Posted: Tue Jun 12, 2012 6:59 am |
|
Joined: Tue Jun 12, 2012 5:04 am Posts: 5
|
|
Thanks,
yes, but works with another version of Framwork and compiled with hi-tech ... tries but fails to do so with the new framework and c18
a few years ago I started to learn using the famework 1.0 and the example you I comment, thanks!
|
|
 |
|
 |
|
mdanell
|
Post subject: Re: Send text to pic example Posted: Tue Jun 12, 2012 4:31 pm |
|
Joined: Tue Jun 12, 2012 5:04 am Posts: 5
|
How I can generate a string for display in the debug? When I run this code hangs the pic... Code: public bool outputString(String text) { // Output a string to the LCD display
// Encode the passed string into an array of bytes for transfer System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); Byte[] outputString = encoding.GetBytes(text);
// Declare our output buffer Byte[] outputBuffer = new Byte[65];
// Byte 0 must be set to 0 outputBuffer[0] = 0;
// Byte 1 must be set to our command outputBuffer[1] = 0x90;
// Byte 2 is our character count outputBuffer[2] = Convert.ToByte(text.Length);
// Copy the characters from the string into the output buffer for (Int64 counter = 0; counter < text.Length; counter++) outputBuffer[3 + counter] = outputString[counter];
// Perform the write command bool success; success = writeRawReportToDevice(outputBuffer);
// We can't tell if the device receieved the data ok, we are // only indicating that the write was error free. return success; }
Code: case 0x90: // *** Send text to PIC *** sprintf(debugString, "Text to PIC"); debugOut(debugString);
for (characterNumber = 0; characterNumber < ReceivedDataBuffer[1]; characterNumber++) { stringtext = ReceivedDataBuffer[2 + characterNumber]; } sprintf(debugString, stringtext); debugOut(debugString); break;
|
|
 |
|
 |
|
mdanell
|
Post subject: Re: Send text to pic example Posted: Tue Jun 12, 2012 5:10 pm |
|
Joined: Tue Jun 12, 2012 5:04 am Posts: 5
|
modify the code and now it works! I do not know if is the right way ... Code: case 0x90: // *** Send text to PIC *** sprintf(debugString, "Text to PIC"); debugOut(debugString);
for (characterNumber = 0; characterNumber < ReceivedDataBuffer[1]; characterNumber++) { string[characterNumber] = ReceivedDataBuffer[2 + characterNumber]; } string[characterNumber] = '\0'; sprintf(debugString, "%s", string); debugOut(debugString); break;
|
|
 |
|
 |
|
mdanell
|
Post subject: Re: Send text to pic example Posted: Tue Jun 12, 2012 5:32 pm |
|
Joined: Tue Jun 12, 2012 5:04 am Posts: 5
|
Now if it all works, send text to the PC and the LCD... Again is the right way? Code: case 0x90: // *** Send text to PIC *** sprintf(debugString, "Text to PIC"); debugOut(debugString);
for (characterNumber = 0; characterNumber < ReceivedDataBuffer[1]; characterNumber++) { string[characterNumber] = ReceivedDataBuffer[2 + characterNumber]; } string[characterNumber] = '\0';
sprintf(LCDString, "%s", string);
// Clear display while (BusyXLCD()); // Wait if LCD busy WriteCmdXLCD(0x01); // Clear display
putsXLCD(LCDString);
sprintf(debugString, "%s", string); debugOut(debugString); break;
|
|
 |
|
 |
|
Simon Inns
|
Post subject: Re: Send text to pic example Posted: Wed Jun 13, 2012 5:53 am |
|
Joined: Thu Apr 01, 2010 6:23 am Posts: 889
|
|
Looks ok to me. The code copied the number of characters indicated by receiveBuffer[1] into an array of char and then terminates the string with '\0' (to make it into a normal C string) before passing it to the LCD.
|
|
 |
|
 |
|