Receiving Junk from Serial Port - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
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

Receiving Junk from Serial Port

Serial Port

  • Please log in to reply
6 replies to this topic

#1 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 19 October 2014 - 09:24 AM

Hi Guys

 

I am connecting my serial rs232 device to the netduino plus 2, D0 and D1 and GND. The device is a card reader. All it does is just returns the tag code from the card that's presented to it. Basically when I present a card. It is returning the following output :

1

1

1

1

1

1

1

 

It supposed to return the tag code for example #234765732476824

 

The code is very small so I cant seem to find out where I am going wrong, Thanks in advance guys


using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.IO.Ports;
using System.Text;

namespace SerialPortTest
{
    public class Program
    {

        static SerialPort serial;

        public static void Main()
        {
            serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
            //serial.Handshake = Handshake.None;
            serial.ReadTimeout = 500;

            serial.Open();
            serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);

            Thread.Sleep(Timeout.Infinite);
        }

        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            String response = "";
            byte[] bytes = new byte[1];
            while (serial.BytesToRead > 0)
            {
               response += serial.Read(bytes, 0, bytes.Length);
            }
            Debug.Print(response);
        }
    }
}



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 20 October 2014 - 06:24 AM

I am connecting my serial rs232 device to the netduino plus 2, D0 and D1 and GND. The device is a card reader.

 
Is the card reader designed to be plugged directly into PC serial port? If yes, then you are missing a level shifter (standard RS232 voltages are around ±10 .. 15V, while Netduino requires 3.3 .. 5V).



#3 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 20 October 2014 - 07:38 AM

Hi

 

Thanks for the prompt reply, The card reader's RX and TX and GND is connected directly to the netduino board (D0,D1, GND) and the card reader is powered by an external power supply. The power going to the reader is correct. Anything else I could try ?



#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 20 October 2014 - 07:54 AM

What card reader are you using?

Most RS-232 devices that you simply plug into PC serial port do not work with microcontroller boards such as Netduino, due to different voltage on RX and TX lines, they require a special circuitry called 'level shifter', for example based on MAX232 or its numerous variants.

 

Basically, there are three major reasons for invalid/garbled data on the serial line: missing level shifter, switched TX/RX lines or incompatible baudrate settings (the latter two require repeated verification, even in case you are thousand percent sure they are correct and you've already checked it a dozen times ;).



#5 Spammy786

Spammy786

    Member

  • Members
  • PipPip
  • 26 posts

Posted 20 October 2014 - 01:58 PM

Il double check the baud rate again from the data sheet and il double check my tx/rx comms. the voltage to the reader is supplied by an external power source and its the correct voltage, If I take the reader and connect a DB9 pin on it, connect to my pc and present my tag to it, it will spit out the correct values in HyperTerminal. 

 

The reader I am using is made made by a company called Impro Technologies.

OMNI-SCAN 125kHz Passive tag reader

Model : OMS-900-1-0-GB-XX

 

On a side note, If I purchase this reader (Link below) Can I connect this directly to netduino and read my tag code ?

http://netram.co.za/...odule-uart.html



#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 20 October 2014 - 04:03 PM

the voltage to the reader is supplied by an external power source and its the correct voltage, If I take the reader and connect a DB9 pin on it, connect to my pc and present my tag to it, it will spit out the correct values in HyperTerminal.

 
I think there is still some misunderstanding - the external power source does not directly relate to RS-232 (serial) line signal levels. If the reader works when directly plugged into PC (DB9), this means it uses ±10-15 V signals and that is why it does not work with Netduino, which requires 0/3.3..5V ("TTL UART").
 
Technical note: RS-232 transceivers usually have voltage boosting 'charge pumps' to convert supply voltage, e.g. 5V to +10..15V and -10..-15V required by the transmission line.

 

On a side note, If I purchase this reader (Link below) Can I connect this directly to netduino and read my tag code ?
http://netram.co.za/...odule-uart.html

 
Most likely yes, there is "UART TTL interface" in the feature list.



#7 pvanroos

pvanroos

    New Member

  • Members
  • Pip
  • 3 posts

Posted 21 October 2014 - 01:10 AM

@CW2:  Could the same problem happen with RS-485 communication over a CAT6 twisted pair?  i.e. too low voltages 3.3 to 5V versus 10 to 15?







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.