1
\$\begingroup\$

I need to send/receive files from/to SerialPort and MSP430F5438A, by clicking a browse button in C# interface, selecting a file (like text, notepad, etc.), and in receive case, to save the file which has been sent from CCS to PC!

I really could not find any related thing on Google or somewhere else. Can anyone at least orientate me?

\$\endgroup\$
8
  • \$\begingroup\$ You should look into modem transfer protocols like ZModem, etc. \$\endgroup\$
    – Majenko
    Jul 23, 2014 at 18:47
  • \$\begingroup\$ @Majenko modem? i'm using UART! \$\endgroup\$ Jul 23, 2014 at 18:49
  • \$\begingroup\$ And? What do you think a modem plugs into? Just because they were designed for using with serial connections with modems doesn't stop them being invaluable for serial connections without modems. \$\endgroup\$
    – Majenko
    Jul 23, 2014 at 18:50
  • \$\begingroup\$ @Majenko i'm sorry but I don't understand what are you trying to say.. \$\endgroup\$ Jul 23, 2014 at 19:08
  • 1
    \$\begingroup\$ If you are going to pursue the modem protocol route, don't start with your own C# app, rather start with someone else's serial terminal program that has those built it, get your embedded code working by testing against that, and then when that is known-good develop your C# code. The point is it's always better to run untested code against tested code, rather than other untested code. You can also use a virtual serial port package to test your C# against a build of your MSP C code created to run on your PC instead. \$\endgroup\$ Jul 23, 2014 at 19:58

1 Answer 1

2
\$\begingroup\$

I would read the file into some sort of buffer on your UI, chop it up into small packets, and send it.

For example, on my UI I allow the user to upload a new firmware image to my device. So I send that firmware file over the UART one line at a time. My MSP430 reads that line into a buffer, which is X characters long, validates it, stores it to a location on an external flash memory, and then receives the next line. Once it has received all of the data, the MSP430 branches into its bootloader code.

You just need to decide how you are going to chunk the data up and size your buffers accordingly.

I do not need to define any special serial protocol because my files are already formatted in a particular way and I can send the file one line at a time and parse it on the other end. http://en.wikipedia.org/wiki/SREC_(file_format)

But for a generic application perhaps you should define a light weight protocol. Like each line will start with a certain character, a sequence number, a payload length, and maybe an end byte. Something along these lines:

| Byte 0               | Byte 1          | Byte 2                              | Byte 3         | Bytes 4 to (p+4) | Byte 5+p           |
|----------------------|-----------------|-------------------------------------|----------------|------------------|--------------------|
| Arbitrary Start Byte | Sequence        | Total number of packets - up to 255 | Payload Length | The data         | Arbitrary End Byte |
| 0x0A                 | Number x        | Of X                                | p < 256        |                  | 0xFF               |

Then you can discard the whole file if one chunk is missing. You could also include a basic checksum to verify that the line didn't get corrupted when it was on the wire.

The parser for this sort of thing would be relatively straight forward to write on both sides.

EDIT: For testing purposes, I reccomend using realterm. It is a flexible binary terminal program that will let you send arbitrary data, files, etc. You can also use it to monitor serial ports.

\$\endgroup\$
5
  • \$\begingroup\$ First of all, "on my UI I allow the user to upload a new firmware image to my device." that's exactly what I want to know how to do. And what is that Payload length thing? \$\endgroup\$ Jul 23, 2014 at 22:01
  • \$\begingroup\$ Payload length for that particular line. So you would clock out a line from the FW file one line at a time one character at a time. When the MSP430 receives its first character and it matches the start character, it will prepare storage for the next character, and so on. When you have finally read in that 4th character, payload length, it tells you how much space to allocate for that particular line of data. You can always make every packet 30 character or something if you want, or you can make the packet length variable. It just helps you to validate the packet and allocate space. \$\endgroup\$
    – Nick
    Jul 23, 2014 at 22:17
  • \$\begingroup\$ You are right, these procedures have to be done after I build the UI so that for instance a browse button has to be clicked to open a file from PC and then implement these procedures. building the UI in C# that is what I really want to know! \$\endgroup\$ Jul 23, 2014 at 22:25
  • \$\begingroup\$ Then I agree with the comment made on the OP. The question about how to create a file browse dialogue would be best suited for stack overflow. But this is what I believe you're looking for: msdn.microsoft.com/en-us/library/… \$\endgroup\$
    – Nick
    Jul 23, 2014 at 22:29
  • \$\begingroup\$ Here's a post on stack overflow on the subject stackoverflow.com/questions/4999734/… \$\endgroup\$
    – Nick
    Jul 23, 2014 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.