-3
\$\begingroup\$

I have an embedded system powered by a microcontroller. I wanted to design a PC based interface in .net for that system. I am interfacing the Microcontroller with the PC through the RS232 serial COM port. I can make it communicate with the serial port terminal or the hyper terminal. I wanted to know the piece of code that will directly enable my .net program to listen to the signals and commands from serial port and update the values accordingly in the database linked with the program. I am not exactly looking for the serial port class. I am looking for the code that will enable my program to listen to the serial port for communication and update the linked database accordingly.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ This sounds like a better question for SO, as it's all on the PC side. \$\endgroup\$
    – Oli Glaser
    Commented Feb 27, 2013 at 19:31
  • 3
    \$\begingroup\$ msdn.microsoft.com/en-us/library/… \$\endgroup\$
    – vicatcu
    Commented Feb 27, 2013 at 19:58
  • \$\begingroup\$ I don't see any electrical engineering issue here. \$\endgroup\$ Commented Feb 27, 2013 at 20:23
  • \$\begingroup\$ I think interfacing with an embedded system (on a higher than terminal program level) is a common engineering task and many people may consider using .NET on the PC side to achieve this. I agree that "I am looking for the code that will..." is to specific. YOu may want to rephrase that @siddharthtd. \$\endgroup\$
    – Rev
    Commented Feb 27, 2013 at 21:29

1 Answer 1

3
\$\begingroup\$

This may not be the typical engineering question, but interfacing with an embedded system is a common task and many people may consider using .NET on the PC side to achieve this.

Well, if you want to send/receive data in .NET in managed code the SerialPort class ist the way to go.

Protocol based communication, receiving specific data and linking it to a database requires an additional layer of abstraction. Generally it boils down to define and implement several of the OSI layers. A lot of people follow at least part of this model without realizing it.

  1. Physical -> you serial port
  2. (Data link -> no physical addressing on serial port)
  3. Network -> Logical addressing using you protocol definition / telegram format
  4. Transport -> may be additional flow control / sequencing
  5. ...high level

This means:

  • Implement SerialPort class in your .NET application to send and receive data.
  • Define a protocol with type of communication (master/slave) and data contents in mind (data integrity requires checksum, multi slave requires addressing).
  • Based on the protocol, implement a class that processes incoming data and converts it to telegrams (and telegrams back to serial data stream).
  • Implement the same mechanisms on the embedded side. This can often be held simple, because the embedded site is passive (slave).
  • Implement a class that processes telegram contents and handles database access.

You say you want to "listen to the serial port for communication and update the linked database accordingly". It may be tempting to go the way that the embedded just periodically sends data and the PC processes it. I strongly recommend to make the embedded side passive. This means that the slave NEVER sends data if the master did not ask it to.

This gives you the following advantages:

  • easily adjust the rate at that data is acquired
  • easily extend the protocol to execute other function like sending configuration data to the slave without collisions
  • multi-slave communication (put in RS485 converter and there you go, assuming you protocol supports addressing)

There are a lot of things to consider, but this should give a basic idea about how to approach this kind of task.
I end up with slightly different solutions all the time, since every project is different and so are the requirements.

\$\endgroup\$

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