none
serial port in Visual C# (send and receive data)

    Question

  • Hi,

    i need some advice.

    i'm PLC developer, so i don't know a lot of programming in Visual C#, only a basic of VC#. i have one PLC and i want to communicate with PC,precisely i send some data from PLC to the serial port of PC. I was programming PLC to send some data and in Console application of C#, i receive that data. it's all O.K!!

    but, in Windows application i can't receive any data.

    in MainForm.Designer fo VC#, i put one button for start receive data and one RichTextBox for displaying data from PLC.

    Size of data whic i send from PLC to PC is just one byte.

    so, i only need to receive data(byte) from PLC and displaying that byte in RichTextBox.

    i tried to wrote some code for that but when i compiled that code is full of Errors (like namespace definition, end-of file, etc.)

    so, please, i'll be very thankful if someone send to me a simplest code for receive a data through the serial port and displaying him in RichTextBox, Visual C#.

     

    Thanks,

     

    Best regards,

    Garincha 

    Tuesday, July 17, 2007 12:09 PM

Answers

All replies

  • Hi,

     

    Here is good exmaple to your question on the other thread. You need to change code a few to satisfy your need . For more information, visit:

          http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1693232&SiteID=1

     

    You can find introduction to SerialPort class in Msdn. See :

                http://msdn2.microsoft.com/en-us/library/system.io.ports.serialport.aspx

     

    Thanks for your question

     

     

     

         

     

    Thursday, July 19, 2007 5:58 AM
  • You can read (almost) all about the serial port on this url: http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm

     

    All examples are in VB, but the principles are the same as in C#, so although you cannot use the examples directly, it may help you understand how the port works.

    Thursday, July 19, 2007 4:39 PM
  • Thank YOU very much for your answer !!

    Thursday, July 26, 2007 8:56 AM
  • Hi

    I am new for PLC. I think PLC uses MODBUS protocol. I don't know anything about to MODBUS. I have done some search on google but can't find mush about what I am lookin for, thought you might be able to help me. Actually what I am trying to do is, I am developing a solution for RFID product in C#. I have raw data (RFID data that I receive from other hardware) that I want to convert into XML output and in MODBUS stream (don't know what is the right word) which I can send to the PLC when it requests for data. For that I am developing middle-ware software (library) that will simply converts raw data into the output (which is for MODBUS protocol and) I can send to the PLC.

    Thanks

    Regards,

    BBorad
    Sunday, September 20, 2009 10:29 AM
  • Good link and very good article!

    Yes, it seems to have lots of problems in .NET with Serial communications. Not good.

    Especially when it needs for PLC communications.

    But how about the old WIN32 API calls here? shouldn't that work better if it could be wrapped into the NET applications??

    Sunday, September 27, 2009 12:47 PM