Author Topic: Visual Basic .NET - serial port receiver question  (Read 28290 times)

trl888

  • Member
  • ***
  • Posts: 2
Visual Basic .NET - serial port receiver question
« on: May 25, 2010, 10:21:35 am »
Question to Jan:

Hi!

First of all, i'm a hardware guy, just starting out with software.

I'm working on a project which involves PC communicating with PLC
through serial port. I'm using your article(Access Serial Ports with
Visual Basic .Net http://www.janaxelson.com/serial_ports_dotnet.htm)
as a starting point to develop the VB.NET app.

Now i'm the point where i need to write a test applicaion which kind
of emulates the PLC. Just a simple form with a textbox. The goal is
that every time data is received the DataReceived event executes, it
reads the data to a string and sends it back to the sender and also
writes the received data to the textbox. You provide a good example
code for DataReceived routine (and adding event handler), but you say
in the article that it is running in a different program thread so
"you need to define a delegate to pass the data to the form" if i want
to write the data to the form's textbox. What is the simplest way to
do it? The example is in the ComPortTerminal demo, also found on the site, but it is way too
complicated to read for me right now(like i said im just starting with
software). I'm trying to keep everything as simple as possible at this
point.

Lauri
« Last Edit: June 29, 2015, 10:26:05 am by Jan Axelson »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Visual Basic .NET - serial port receiver question
« Reply #1 on: May 25, 2010, 10:42:35 am »
Thank you for posting your question to the forum.

You need a delegate to pass the event data to a form. My ComPortTerminal example does so.

An example that illustrates just delegates is here:

http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx

Also see:

http://msdn.microsoft.com/en-us/library/aa288459%28VS.71%29.aspx

The .NET newsgroups are a useful resource for questions relating to .NET:

http://www.microsoft.com/communities/newsgroups/en-us/

Look under Developer Discussions > Visual Tools

Jan




GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Visual Basic .NET - serial port receiver question
« Reply #2 on: July 22, 2010, 12:41:29 pm »
Hi,
I am Hardware guy who does software when forced, can I make a recomendation use C# its closer to C than Visual C++ without the level of nasty's to trip you up.  I'm guessing as a hardware guy you know C all learning VB will get you is name calling by proper softies.  If however you have legacy code to deal with I pity you (been there, done that, not doing it again if can be helped!), also can I recommend Jan's Serial Port Complete 2nd Ed while some of it is on the website some of it isn't also can I recomend you write a simple VB/C# program that sends a string and recieves it and go from there just cross pins 2&3 on D type and go gradually add more complexity as it is needed.  If you do it that way your simple program can then be used as a base for changes but always keep the original as a master back up.

Glenn 

HelenJames

  • Member
  • ***
  • Posts: 3
answer this topic
« Reply #3 on: July 26, 2010, 04:34:13 pm »
I think we all get a little bit distracted from the main topicstarter's theme

MathewGerhard

  • Member
  • ***
  • Posts: 1
Re: Visual Basic .NET - serial port receiver question
« Reply #4 on: March 16, 2011, 10:19:20 am »
Hey
can some 1 please help me in receiving ir signal at serial port.
There is code available in C++ (winLIRC). but i need the code in vb.
Please let me know.

It's pleasant to get out there and check out restaurants in tunbridge wells for the reason that the foodstuff there is terrific.
« Last Edit: April 14, 2011, 10:56:32 am by MathewGerhard »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Visual Basic .NET - serial port receiver question
« Reply #5 on: March 16, 2011, 10:59:34 am »