![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
JamesL Guest
|
USB communication to PC |
Posted: Fri Jun 12, 2009 1:22 pm |
|
|
Hello everyone.
I need to make one VB Program which will send some commands to PIC.
My problem is that I have to use USB communication for data transfer.
I need to pass command like "start" and the respond to that should be that the motor would start to spin.
What do I need to do on the PC side and what on the PIC side to make this work ? How can PIC accept and process data that I pass from PC ?
Thank you for your time. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Jun 12, 2009 2:59 pm |
|
|
Easiest way, is probably the CDC device class.
This is illustrated in the examples 'ex_usb_serial.c', and 'ex_usb_serial2.c'. These contain the code to first just echo data back, and the second to allow you to change a memory location, using serial commands. This class, implements basically, a USB 'emulation', of a simple serial port. Seen by the system as 'COMx', and talkable from VB, using the MSCOMM control.
So, your VB program, would need to be told what com port the device is on (it is possible to actually search for the device by name, using the API, but this is more complex programming), and then open this port, and send the commands. The PIC code would be similar to ex_usb_serial2,but with a 'parser', looking for the commands you want to accept. A search here will find lots of parser examples, in particular for modem strings. Once the required string is seen, the output bits would then be changed to perform the required operation.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
JamesL Guest
|
|
Posted: Sat Jun 13, 2009 3:41 am |
|
|
OK. Thank you for your suggestion.
To expand this question I would also like to define some main things when you are writing data to memory per USB.
I am using external memory and I would like to save some part of the encrypted data that I pass from PC into external memory of my device.
What would be the smallest encrypted value that I can write into external memory ? What data type, what writing format ? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sat Jun 13, 2009 3:00 pm |
|
|
That is competely down to your code.
Assume (for example), that your external memory, accepts data in bytes. Then there is nothing to stop your code, reading a byte, modifying one bit, and writing it back. Just as with the #bit, and #byte commands in CCS C itself, it is then down to your parser implementing instructions to access individual bits. So you could have (for example), a 'read_byte' command, and a 'read_bit' command, with the former just having a byte address number, and the latter having a bit number as well. The same applies with writes.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|