Serial Communication - 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

Serial Communication


  • Please log in to reply
9 replies to this topic

#1 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 13 January 2013 - 08:09 PM

Hello,

 

I have communicated with devices in the past via .net and serial port communication, I'm working on communicating with this GRPS shield and trying to follow the instructions at http://www.seeedstud...re_installation I'm not having any luck communicating with the shield over serial. The device is powered, and per the instructions is connecting to the GSM network. I can control the device via pin 9 and power on and off in my application.

 

When I try to use the driver at http://netduino2seed...ew/19515#311098 and when I try to simply communicate to get an "OK" back from the shield i'm not having any luck. Based on the information in the shields WIKI I would expect to get an "OK" back based on my AT Command of "AT+CMGF=1r"

 

My jumpers are like the below here.

 

Posted Image

 

 

To simplify things, I ended up just trying to write it myself below(source code below), does anyone have ideas?

 

 

  public static string output = "";        static SerialPort serialPort;        public static void Main()        {                        // write your code here            string portName = SerialPorts.COM1;            int baudRate = 19200;            Parity parity = Parity.Odd;            int dataBits = 8;            StopBits stopBits = StopBits.One;                        serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);            serialPort.Open();            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();            byte[] bytesToSend = encoder.GetBytes("AT+CMGF=1r");            serialPort.Write(bytesToSend, 0, bytesToSend.Length);            serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);            while (true)            {                     Thread.Sleep(100); // wait a bit so we get a few bytes at a time...            }        }        static void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            byte[] bufferData = new byte[20];            serialPort.Read(bufferData, 0, 20);            char[] charArray = System.Text.UTF8Encoding.UTF8.GetChars(bufferData);            for (int i = 0; i < charArray.Length - 1; i++)            {                if (charArray[i].ToString() == "r")                {                    //output += charArray[i];                    Debug.Print(output);                    output = "";                }                else                {                    output += charArray[i];                }            }        }     

 



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 13 January 2013 - 08:24 PM

It probably will not help much, but try adding DataReceived event handler before Write() call:  
...serialPort.DataReceived += serialPort_DataReceived;serialPort.Write(...);


#3 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 13 January 2013 - 08:24 PM

Hi,

Looking at the page you linked, I think you should try to use the hardware serial port option.

Also try just sending "ATr" that should get you an "rOKr" response from any modem.

Paul

EDIT:

Hardware option uses D0 and D1 = Netduino classic & plus v1 / v2 - com1

Software option uses D7 and D8 = Netduino plus v2 only - com3



#4 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 13 January 2013 - 08:58 PM

Thanks for the responses gentlemen. I got my first response, and they appear to be steady now. I switched the jumpers to hardware and it looks like that was it. I guess the other configure is for a USB=>TTL configuration I suppose. (not sure)

 

 

Oh and thanks for the "ATr" information, I'll be using that as a health check. I'm a newb to hardware, I have only been a software guy before so this is a new game for me. I really appreciate it!



#5 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 13 January 2013 - 09:15 PM

I"m not sure but I think encoding is off. My response from "ATr" is "AU¨" not sure what that is.. :mellow:



#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 13 January 2013 - 09:23 PM

I think the "software"  option was reffering to using D7 and D8 with a software implementation of a UART so that the Arduino could use its real UART on D0 and D1 for some other hardware device.

Better described as alternate serial port maybe.

 

Has it stopped responding "OK" or did you never get the "OK"?

If a modem does not recognise a command it will respond "rERRORr"

Check your baud rate matches the modems data sheet.

 

EDIT:

A tip is to add an extra r before anything you send to ensure the buffer at the receiver does not have any old characters at the start.



#7 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 13 January 2013 - 09:54 PM

My baud is 19200 which is what the data sheet shows. I'm getting back responses, I never received "OK" I think that must be what AU is and the conversion of the bytes is wrong. Here is what I"m getting back. I'm not sure what this is, when I try to execute an "ATD" dial command my byte array is attached.

 

Command Sent : AT

Recieved : AU¨

Recieved : j5

 

I"m receving a byte array of 85,168,10,106,53,10. when I try to send the ATD command. I'm not sure if that is an error or not.



#8 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 13 January 2013 - 09:59 PM

Here is what I see in my debug window from the ATD command.

 

Command Sent : ATD+0014053615260;

Recieved : A­0Š4ª3Sª2Ú

¡j5



#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 13 January 2013 - 10:09 PM

The shield documentation mentions that the serial communication uses Parity.None, but you have Parity.Odd in your application (or at least in the snippet you posted).



#10 skobyjay

skobyjay

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 13 January 2013 - 10:17 PM

sure enough! thanks for pointing that out!! that was the issue.

 

I'm getting back "OK" now! hopefully this will be the last of my woes. I appreciate it fellows!






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.