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.

pvanroos

Member Since 10 Apr 2014
Offline Last Active Oct 28 2014 05:57 PM
-----

Posts I've Made

In Topic: Issues with COM1 through RS485 shield

24 October 2014 - 10:59 PM

Hi all,

 

Did anyone ever figure this out?  I've got a RS-485 Shield from LinkSprite and I can't get it work.  Here are some details from my project:

 

1. Linksprite RS-485 Shield V2.1 - http://linksprite.co...2.1_for_Arduino

2. Using SerialPort for communication:  http://msdn.microsof...y/ee432679.aspx

3. Communicating over CAT6 twisted pair to a device at other end expecting 9600 baud, Even parity, 7 character bits, and one stop bit.

4. Twisted pair inserted into H2 485-A and 485-B ports.

5. Netduino Plus 2 (bought a month ago with no firmware updates)

6. Set to 5V using jumper.

7. Set to D0 and D1 using jumper.

8. Set to TX_CTRL using jumper.

9. Plugged into computer to deploy code.  Headers are not soldered but they fairly snug and not loose.

10: Code:

        static SerialPort serial;
        static OutputPort led;
        const int bufferMax = 10000;
        static byte[] buffer = new byte[bufferMax];
        static int bufferLength = 0;

        public static void Main()
        {         
            led = new OutputPort(Pins.ONBOARD_LED, false);
            serial = new SerialPort(SerialPorts.COM1, 9600, Parity.Even, 7, StopBits.One);
            serial.ReadTimeout = 1000;      
            serial.DataReceived += serial_DataReceived;
            serial.ErrorReceived += serial_ErrorReceived;
            serial.Open();

            while (true)
            {
                {
                    led.Write(true);
                   
                    Debug.Print("Request sent");
                    string hexrequest = "2F3F3030303330303030313039363030210D0A";
                
                    // Create request
                    byte[] seq = StringToByteArray(hexrequest);

                    if (serial.CanWrite)
                        serial.Write(seq, 0, seq.Length);    
                                           
                    led.Write(false);
                }

                string line = "> ";

                for (int i = 0; i < bufferLength; i++)
                {
                    line += buffer[i] + ",";
                }

                Debug.Print(line);
                if(serial.IsOpen) Debug.Print("Port is open.");
                Thread.Sleep(10000);
            }
        }
        static void serial_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
        {
            if (e.EventType == SerialError.TXFull)
            {
                Debug.Print("Error:  TXFull");
            }
            else if (e.EventType == SerialError.RXParity)
            {
                Debug.Print("Error:  RXParity");
            }
            else
            {
                Debug.Print("Error:  Some other error");
            }
        }

        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {

            Debug.Print(dataRecLineNumber + ": Data received ******* - " + t );
       
            int bytesReceived = serial.Read(buffer, bufferLength, bufferMax - bufferLength);
            if (bytesReceived > 0)
            {
                bufferLength += bytesReceived;
                if (bufferLength >= bufferMax)
                    throw new ApplicationException("Buffer Overflow.  Send shorter lines or increase lineBufferMax.");
            }
        }


In Topic: Receiving Junk from Serial Port

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?


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.