Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

N+ TCP/IP starter project


  • Please log in to reply
4 replies to this topic

#1 micsea64

micsea64

    New Member

  • Members
  • Pip
  • 3 posts

Posted 31 October 2012 - 09:00 PM

Hi, I want to write a program that talks between two N+'s attached to a router. I want to start off simple, by hitting the onboard button on the N+1 and turning on the onboard LED on the N+2. I want to two boards only communication to happen through the router. In the end, I essentially want to be able to build a completely standalone C# program that will talk to the N+ through TCP/IP or any other Modbus protocols that will work. To start out, I am going to get two N+'s to turn on/off each others onboard LED. I was trying to find any kind of TCP/IP protocol that would allow me to talk to each other, but I haven't had much luck yet. Would TCP/IP be the best way to approach this project, or would I be better off using some other protocols, and were could I find them at? Any help would be greatly appreciated. -Sean

#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 01 November 2012 - 12:16 AM

tcp/ip is the best protocol for this. there is udp, but thats way worse. tcp is fairly easy, you dont need a web interface or such, you can just send/recieve bytes directly wich allows an simple and efficient command structure you do something like this: send a byte = 0 from n1 .. read it on n2: switch(byte_read) { case 0: { turnledon(); } break; case 1: .. turnledoff() .. thats really the simplest version wich is ok for some leds. if you wanna do more you need to send more byte, like the first byte is da command identifier, and all other (depending on command) are the data. than byte[0] = 0; would be the led on/off command, and byte[1] the actual data (0 = off, 1=on) or whatever

#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 November 2012 - 04:44 AM

What you need is just some clicks far from the target. Here is the Modbus library, supporting both TCP and UDP. It comes with a ready-to-test sample, which uses buttons and leds as you wish. http://cetdevelop.codeplex.com/ Cheers
Biggest fault of Netduino? It runs by electricity.

#4 micsea64

micsea64

    New Member

  • Members
  • Pip
  • 3 posts

Posted 02 November 2012 - 04:45 PM

Thanks guys, I downloaded the cetdevelop code, and I am about to start looking through it all and try to figure out exactly whats going on. Thanks for the pointers, and a place to start. If I have any question, I will be sure to ask you guys. -Sean

#5 micsea64

micsea64

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 November 2012 - 09:01 PM

Ok, so what I ended up doing, was getting a simple socket project to work, on the Netduino Plus (1), as well as a Form project. Basically, what I had to do, was figure out how to use sockets to begin with, and for a while, all I could find was massively complicated examples online, but eventually found a basic program that sent data through System.Net.Sockets. So I created a basic Form on my desktop through Visual Studios 2010, that only the minimum. A box for the static IP of the Netduino Plus you are wanting to talk to, a box for the Port in order to talk through the sockets, and a button to toggle the onboard LED. So that is about all there is to the C# Form. The code isn't that complicated at all. So basically you have to set up the socket, then give the Ip address and Port, and then connect, send and close the socket. On the netduino plus side, I first found a video from OZhost, and followed what he did in his project, and kind of did what he did. On his video, he had you send over 3 numbers, the amount of times you wanted to blink the led on and off, then the time on in milliseconds and time off in milliseconds. So I took the basics of how he connected to a socket from that video, and wait for the incoming command, read the current status of the onboard LED, and then do an led.write(!status); which toggles the boolean every time. So for anybody that is completely confused to the ramblings above, I will post the code for anybody that is as "new" to the Netduino Plus as I am. The file is 98kb's for both portions of this example. All you will need is your own netduino plus, a computer with visual studios with the ability to create a form and netduino projects, and a router.

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.