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

Plus 2 serial issue with HA7S


  • Please log in to reply
2 replies to this topic

#1 Fred007

Fred007

    Member

  • Members
  • PipPip
  • 25 posts

Posted 28 May 2014 - 05:24 PM

I have an app running on a plus, and working to bring another instance up on a plus2. It talks to the HA7S and to the temp sensors on the one-wire bus. On the new plus 2 setup, it looks like the serial buffer is getting over written. when I issue the 'S' get all devices command, I get a return that is different lengths but never the 16 characters I am looking for. It feels like a timing issue, but can't confirm/deny that. I am using the following serial settings.

 

Com1:9600,8,1,None

 

I swapped out the plus 2 for another one, no difference. Have used different temp sensors too, no joy. Am thinking now it may be the HA7S chip.

 

Thoughts?



#2 Fred007

Fred007

    Member

  • Members
  • PipPip
  • 25 posts

Posted 28 May 2014 - 06:33 PM

I also swapped out the HA7S and still have the same behavior. Will investigate the code a bit, doing some very simple interrupt handling, but will try a smaller example.



#3 Fred007

Fred007

    Member

  • Members
  • PipPip
  • 25 posts

Posted 29 May 2014 - 05:42 PM

using System;
using System.Collections;
using System.IO;
using System.IO.Ports;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace ndSerialTestHA7S
{
    public class Program
    {
        private const byte R = 82;
        private const byte S = 83;
        private const byte W = 87;
        private const byte s = 115;
        private const byte CR = 13;
        private static SerialPort _serialPort = null;
        private static Queue _serialQueue = new Queue();
        private static Object _lockQueue = new Object();
        public static AutoResetEvent unblockRead = new AutoResetEvent(false);
        public const int _readTimeout = 3000;
        public static void Main()
        {
            _serialPort = new SerialPort(SerialPorts.COM1);
            _serialPort.BaudRate = 9600;
            _serialPort.DataBits = 8;
            _serialPort.StopBits = StopBits.One;
            _serialPort.Parity = Parity.None;
            _serialPort.Handshake = Handshake.None;
            _serialPort.DataReceived += new SerialDataReceivedEventHandler(inboundSerial);

            byte[] devAddress = new byte[45];
            try
            {
                _serialPort.Open();
                writeSerial(R);
                readSerial(devAddress);
                log(devAddress);
                writeSerial(S);
                readSerial(devAddress);
                log(devAddress);
                writeSerial(s);
                readSerial(devAddress);
                log(devAddress);
                writeSerial(s);
                readSerial(devAddress);
                log(devAddress);
                int i = 1;
            }
            catch (SystemException se)
            {
                Debug.Print("Ha7s: " + se.Message);
            }
        }
        private static void inboundSerial(object sender, SerialDataReceivedEventArgs data)
        {
            while (_serialPort.BytesToRead > 0)                     // While there is data on the serial bus
            {
                lock (_lockQueue)
                {
                    _serialQueue.Enqueue((byte)_serialPort.ReadByte());
                }
            }
            unblockRead.Set();
        }
        private static void writeSerial( byte[] data, int len )
        {
            for (int i = 0; i < len; i++)
                _serialPort.WriteByte(data[i]);
        }
        private static void writeSerial(byte data)
        {
            _serialPort.WriteByte(data);
        }
        private static void log( byte[] buffer )
        {
            string message = "Log: ";
            message += new String(Encoding.UTF8.GetChars(buffer));
            Debug.Print(message);
        }
        private static void zero( byte[] buffer, int l)
        {
            for (int i = 0; i < l; i++)
                buffer[i] = 0;
        }
        private static int readSerial(byte[] data, byte termChar = CR)
        {
            zero(data, 20);
            int bytesRead = 0;
            bool keepChecking = true;
            while (keepChecking && (_serialQueue.Count > 0))                   // Have something in the queue
            {
                lock (_lockQueue)                                              // grab lock while dequeing
                {
                    data[bytesRead] = (byte)_serialQueue.Dequeue();            // grab a byte from the queue
                }
                if (data[bytesRead] == termChar)                               // Hit terminating character, stop grabbing bits
                    keepChecking = false;
                bytesRead++;
            }
            while (keepChecking)
            {
                bool signaled = unblockRead.WaitOne(_readTimeout, false);
                if (!signaled)                                              // Timed out, exit loop
                    keepChecking = false;
                else
                {
                    while (keepChecking && (_serialQueue.Count > 0))        // Have something in the queue
                    {
                        lock (_lockQueue)                                   // grab lock while dequeing
                        {
                            data[bytesRead] = (byte)_serialQueue.Dequeue(); // grab a byte from the queue
                        }
                        if (data[bytesRead] == termChar)                    // Hit terminating character, stop grabbing bits
                            keepChecking = false;
                        bytesRead++;
                    }
                }
            }
            return bytesRead;
        }
    }
}

I think it must be something in my setup, do I need to have a ground wire added somewhere for the plus2? (as opposed to a plus?) I have tried two plus 2 devices, two different HA7S devices, multiple temp sensors, and always get indeterminate results from the serial queries. Its like something is stepping on the UART queue, or inbound characters. Not at all like the behavior on the plus, very timing dependent. Started off with a  fairly simple program to just test the serial commands and can't get any good, or consistent results. Even flashed one unit back to 4.2.2 and have the same issues. Entire test program in message.

 

Would really appreciate any pointers. Thanks.






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.