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.
I need help with serialport.read. I’m sending a serialport.write ("TSTG") out of a VB app to the netduino thru an xbee shield. I’m receiving the bytes but I’m having trouble with converting it back to a text. Will the final version have serialport.readline option.
Thanks,
Jon
Private Sub Data_Received(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Try
Dim i As Integer
Dim n As Integer = sPort.BytesToRead
Dim buffer() = New Byte(n - 1) {}
sPort.Read(buffer, 0, n)
For count = 0 To (n - 1)
DataIn = CStr(buffer(i))
Debug.Print(DataIn)
i = i + 1
Next count
Catch ex As Exception
Debug.Print(ex.Message.ToString())
End Try
End Sub
Here's a program that will accept a string from the serial port and turn the LED on or off
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports System.IO.Ports
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino
Imports System.Text
Imports Microsoft.VisualBasic.Constants
Module Module1
Private WithEvents UART As SerialPort
Private DataFromPC As String = ""
Private LED As New OutputPort(Pins.ONBOARD_LED, False)
Sub Main()
UART = New SerialPort("COM1", 19200, Parity.Even, 8, StopBits.One)
UART.Open()
Thread.Sleep(Timeout.Infinite)
End Sub
Private Sub SerialIn() Handles UART.DataReceived
Dim Length As Integer = UART.BytesToRead
Dim Datax(Length) As Byte
UART.Read(Datax, 0, Length)
DataFromPC &= New String(Encoding.UTF8.GetChars(Datax))
If DataFromPC.IndexOf(vbLf) >= 0 Then
DataFromPC = DataFromPC.Trim.ToUpper
If DataFromPC = "ON" Then
LED.Write(True)
ElseIf DataFromPC = "OFF" Then
LED.Write(False)
Else
End If
DataFromPC = ""
End If
End Sub
End Module
Hi Bonzo, welcome to the boards
It's quite confusing, but here it is.
The reference is "Microsoft.SPOT.Hardware.SerialPort"
But the imports line is "Imports System.IO.Ports"
I know they're not named the same, but that's how it is.
Thank you!
It's been a while since I followed boards like this, but this one looks promising!
The reference is "Microsoft.SPOT.Hardware.SerialPort"
But the imports line is "Imports System.IO.Ports"
Well, as you'll see from my screenshot; no_serialport.png105.78KB115 downloads
I have all of the imports, and I've also tried to use the entire reference but still nothing.
Might I have a corrupt install?
Are there any settings somewhere that I've missed?
(I think) I followed the instructions for installing the new SDK and firmware as found on this site.
EDIT:
Could it be that I'm using the Netduino Plus?
Hi Bonzo,
Try typing:
"System.IO.Ports.SerialPort"
That should be the class you're looking for It's in the Microsoft.SPOT.Hardware.SerialPort.dll assembly--but the actual class is just "SerialPort." [You can also just type SerialPort without the full namespace before it, since you have the Imports statement up top.]
Chris
Hi Bonzo,
Right-click on NetduinoPlusApplication1 in the Solution Explorer and select Add Reference. Then select Microsoft.SPOT.Hardware.SerialPort, press OK, and try again
Right-click on NetduinoPlusApplication1 in the Solution Explorer and select Add Reference. Then select Microsoft.SPOT.Hardware.SerialPort, press OK, and try again
Hi,
What's the approach for this code to use it to use it a as a remote serial port for a PC? I want to have a COMx: on my PC, and remotely open it over ET on my LAN using one of the uarts on the netduion +
Thanks,
Paul
Hi,
What's the approach for this code to use it to use it a as a remote serial port for a PC? I want to have a COMx: on my PC, and remotely open it over ET on my LAN using one of the uarts on the netduion +
Thanks,
Paul
Are you saying that you want to make your computer send data to COM5 and have it come out of the Netduino Plus's UART, using the LAN to carry the data?
If so, you'd need some kind of COM-to-IP software on your PC first, to make it send the data via LAN instead of a physical COM port.
After that, you'd want to combine the code in this thread with code that reads the data you sent via your LAN connection.
The Netduino Plus would essentially only become an RS232 extender that operates over IP.
If this is what you want, and only this, there are more suitable devices out there.
If not, check out the webserver examples as well, as they contain code for managing IP traffic.
You got it right. I want to read and write the port. I've seen examples where .NET is used on the pc and includes libraries to open com sessions from the netduion. Since my target environment is .net (I should have said that earlier), it seems like code on the netduion to read from one side and write to the other would do it. The code on the netduion does not need to think about the stream at all, just move it.
You got it right. I want to read and write the port. I've seen examples where .NET is used on the pc and includes libraries to open com sessions from the netduion. Since my target environment is .net (I should have said that earlier), it seems like code on the netduion to read from one side and write to the other would do it. The code on the netduion does not need to think about the stream at all, just move it.
You can use just about anything to trigger the Netduino, that's no problem.
But are you trying to make the link "transparent" in a way that lets you run lets say HyperTerminal on the computer, open a connection on COM5 (or what ever number) and automagically talk to the device connected to the Netduino via LAN?
Or is there more to it than that?
Do you have other functionality planned as well?
You can use just about anything to trigger the Netduino, that's no problem.
But are you trying to make the link "transparent" in a way that lets you run lets say HyperTerminal on the computer, open a connection on COM5 (or what ever number) and automagically talk to the device connected to the Netduino via LAN?
Or is there more to it than that?
Do you have other functionality planned as well?
Hi. You have it right, I want to create a transparent serial port experience from the pc to one of the UARTs on the netduion across my LAN. I have an rs-232 based device that I want to operate remotely from the PC. There is software on the PC that is .net based that can be programmed (homeseer).
To your point, I have a number of other items to integrate with the netduio as well and conceptually I get how to do that based on the sample code and manuals. This one I did not get conceptually how to approach it from an end to end perspective.
I'm thinking there is already com: device provided by USB the netduion and simple code to be a bridge between the PC and the UART can be written.. is it that simple? But when its not USB but Ethernet connected, what provides the virutal serial port on PC side? .net
I'm thinking there is already com: device provided by USB the netduion and simple code to be a bridge between the PC and the UART can be written.. is it that simple? But when its not USB but Ethernet connected, what provides the virutal serial port on PC side? .net
I just have to mention once more that other hardware might be more suitable, but I do understand the joy of a good challenge and learning experience so here goes;
Your solution would (probably) consist of three pieces of software and two pieces of hardware.
Hardware:
-Netduino Plus
-Device to be controlled
Software:
-Netduino Plus software
-Virtual COM
-Homeseer
You've got the hardware, and you've got 1 of 3 softwares.
The Netduino Plus software would have a rather simple function set:
-Receive a byte via LAN, send it to UART
-Receive a byte via UART, send it to LAN
This can almost be achieved by cutting/pasting large parts of the two example codes.
The Virtual COM is probably a bit harder.
It must create a virtual COM port that Homeseer can connect to.
I really don't have any idea how to solve that one, sorry.
Once that has been achieved, it's basically the Netduino software all over again...
-Receive a byte via LAN, send it to Virtual COM
-Receive a byte via Virtual COM, send it to LAN
If Homeseer can communicate via TCP/IP directly, there might be a simpler solution.
What kind of hardware is it you need to talk to?
I'm asking, to find out what kind of datatransfer we're talking about.
I hear you... and great questions. I have looked at lan based serial port redirectors. It has become chip based, reliable and cheap from China.
However there will be multiple things going on at the location where the netduino+ will go. I will use netduino+'s IO pins for sensing and activating other unrelated devices, and I know how to proceed with those. I have one lan cable in the vacinity. It's about the swiss army knife capabilities of the netduino+; to be able to put one cheap device at the location to solve multipe needs.
The serial device is a very simple X10 RF bridge, signals come to a receiver which has a 9600 bps connection via a db25 connector. When an x10 rf device transmits and is detected by the receiver, it creates a small (around 10) coherent set of characters that indicates what address transmitted and short command (on or off). These trasmissions are important, but very infrequent. I have a Homeseer plugin that looks for a com port on the PC to read those characters and takes it from there. I want to build a bridge, so to speak, from one end to the other
And, to a certain degree, yes its the challenge of doing it. But there a number of different similar serial devices that could be attached the same way. There could be a lot of value in this capability beyond my needs.
I brought up the regular, non-plus netduino usb as a way of saying I think i know how to do it via usb using the usb com port provided when using the regular (non plus) net duion. But if my actual "use case" is putting the netduino further from the computer, I have to use a netduino + and figure out how to add that capability via TCP/IP. Homeseer is built on windows .net, so yes the TCP/IP capability is there, I can leverage whatever .net brings to the table there. That seems to be where this discussion is leading.
I appreciate your thoughts, its helping me sort out the "architecture" of this function.
I have used this http://www.eterlogic...ducts.VSPE.html as a virtual serial port emulator on several machines and for several applications with some success. It can possibly handle the virtual com port on the PC side, and then you could make the netduino talk to this via the lan. I have found it to be quite a nice bit of software, and the 32 bit version is free (which is always a bonus!).
Here's a program that will accept a string from the serial port and turn the LED on or off
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports System.IO.Ports
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino
Imports System.Text
Imports Microsoft.VisualBasic.Constants
Module Module1
Private WithEvents UART As SerialPort
Private DataFromPC As String = ""
Private LED As New OutputPort(Pins.ONBOARD_LED, False)
Sub Main()
UART = New SerialPort("COM1", 19200, Parity.Even, 8, StopBits.One)
UART.Open()
Thread.Sleep(Timeout.Infinite)
End Sub
Private Sub SerialIn() Handles UART.DataReceived
Dim Length As Integer = UART.BytesToRead
Dim Datax(Length) As Byte
UART.Read(Datax, 0, Length)
DataFromPC &= New String(Encoding.UTF8.GetChars(Datax))
If DataFromPC.IndexOf(vbLf) >= 0 Then
DataFromPC = DataFromPC.Trim.ToUpper
If DataFromPC = "ON" Then
LED.Write(True)
ElseIf DataFromPC = "OFF" Then
LED.Write(False)
Else
End If
DataFromPC = ""
End If
End Sub
End Module
This code does not work for me. When the code is loading the netduino gives always an error. I work with VB.net 2010