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.

lifanek's Content

There have been 23 items by lifanek (Search limited from 21-April 23)


By content type

See this member's

Sort by                Order  

#56647 Multiple Serials Ports in Threads - Best Practices

Posted by lifanek on 05 March 2014 - 02:56 PM in Netduino Plus 2 (and Netduino Plus 1)

I have also noticed event firing with 0 bytes to read - just added if (bytestoread < 1) do nothing.




#56646 How to convert hex value stored in string to binary in string?

Posted by lifanek on 05 March 2014 - 02:52 PM in Visual Studio

No problem - I want to make some ATcommands/PDU library to make it simple in use. My code is simple because I'm a beginner in C# and I'm working on my first bigger project on Netduino and for sure there are a lot of things that could be wrote more efficently.

 

Attached Files

  • Attached File  uGSM.zip   53.24KB   17 downloads



#56635 How to convert hex value stored in string to binary in string?

Posted by lifanek on 05 March 2014 - 12:18 AM in Visual Studio

Hi,
Thanks all for reply - I made string array with binary equivalents in it ("0000", "0001" etc..) and I convert hex to string from this array :)



#56549 How to convert hex value stored in string to binary in string?

Posted by lifanek on 01 March 2014 - 03:49 PM in Visual Studio

Hi all,

I'm trying to accomplish something like this:

http://www.serasidis...scontroller.htm

and now I'm writing some code to decode PDU format to text.

The steps are:

- Some values represented by hex numbers stored in string, i.e. "31584C1E8BC160"

- Reversing it like this ===>  "60C18B1E4C5831"

- Here comes the hardest part - every 7 bits I need to add a 0 bit, because PDU uses 7-bit GSM ASCII.

I can convert it right away beacuse it is stored in hex and everything is shifted by 1 bit every 7 bits.

(see this http://www.serasidis..._conversion.gif )

 

I wanted to do it like this:

 

string hex = "60" (first two chars from the main string)

int x = Convert.ToInt32(hex, 16)

BinaryString = Convert.ToString(x, 2)

 

but it seems that there is no Convert in .NET MF :(

 

Is there any workaround possible for this?

Thanks,

Lifanek

 




#56214 First steps: SerialPort problem

Posted by lifanek on 19 February 2014 - 11:32 PM in Visual Studio

I am also testing 485 through 75176 but I'm getting some noise. Using this code:

static OutputPort RW485 = new OutputPort(Pins.GPIO_PIN_D2, true); //False - write / True - read

static void transmit()
{
while (true)
{
lock (monitor)
{
RW485.Write(true);
const string input = "Test$n";
byte[] sender = Encoding.UTF8.GetBytes(input);
serial.Write(sender, 0, sender.Length);
RW485.Write(false);
}
Thread.Sleep(5000);
}
}

This should give You Test$ message over 485 every 5 sec

 

Check out this:

 

http://img80.imagesh...63/43013093.png

 

it is from polish electronic forum and guys was trying to use 75176 without noise (You can see there some pull up resistors etc.) - I will try this... maybe next week

 

 

 

hello lifanek,

i'm really sorry first of all., i will definetly keep in mind what u said.

 

and yes i'm already using a [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]MAX232 for PC communication (or USB to TTL)., [/color]

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]i have an ADM3485 IC for RS485, will it work.????[/color]

 

Check out data sheets for this device - for example MAX485 and 75176 for me look like same device just made by other companies - maybe ADM3485 is just like that.




#56212 First steps: SerialPort problem

Posted by lifanek on 19 February 2014 - 11:29 PM in Visual Studio

This code was made by me from other examples just for testing purposes (this is why it is printing "transmit thread works" - i just wanted to know that the thread is running).

 

For communicating with PC I have used Arduino Mega and Arduino IDE serial monitor - the only job for arduino was read from one UART and write it to second (read from Netduino and write to PC) and same thing in other direction (read from PC and write to netduino).




#56197 First steps: SerialPort problem

Posted by lifanek on 19 February 2014 - 07:37 AM in Visual Studio

Hi Sayatan,

check out this thread - maybe something helps

http://forums.netdui...serial +threads

 

And please - could You spend a little bit more time on writing Your posts? It's hard to read.

 

Just like Chris I think You should use some MAX232 for PC communication (or USB to TTL). Also try Debug.Print(buffer.ToString());

 

For RS485 use MAX485 or 75176 and then connect one pin from Arduino to pin 2 and 3 in MAX. If it's LOW then it's receiving and when it goes HIGH You are able to transmit.

 

Example - Pin 3 connected to MAX485 pin 2 and 3

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]static OutputPort pin = new OutputPort[/color](Pins.GPIO_PIN_D3, false);

 

so pin is all the time low so event for reading can be fired.

and then later in code You should have something like this

 

pin.Write(true)

Serial.Write("test");

pin.Write(false)




#56102 Compile error

Posted by lifanek on 15 February 2014 - 06:41 PM in Netduino Plus 2 (and Netduino Plus 1)

Have You recently updated Your .NET MF or flashed a device?




#56101 Unable to reflash erased Netduino on Windows 8 x64

Posted by lifanek on 15 February 2014 - 06:23 PM in Netduino 2 (and Netduino 1)

I couldn't flash my N1+ on win8 x46 (some driver issue) so I did in on 7 x86 :)




#56098 Turn on onboard LED with PC Keyboard.

Posted by lifanek on 15 February 2014 - 05:02 PM in Visual Studio

Check out my code here http://forums.netdui...ces/#entry56074 - maybe You will find there some useful info.



#56071 uning List<struct>

Posted by lifanek on 14 February 2014 - 08:08 AM in Visual Studio

Hey, I've tried to use object array instead of many individual objects and now can navigate them through array index. I will try your solution also - thanks for help :)



#56067 Multiple Serials Ports in Threads - Best Practices

Posted by lifanek on 14 February 2014 - 04:11 AM in Netduino Plus 2 (and Netduino Plus 1)

You can calculate that from baud rate.

Baud rate = bits per second so if You're using 9600 it is 9600/8=1200 bytes per second, then You have 72 bytes to transmit so 72/1200=0,06 seconds.

 

0,06 seconds mean that You have to Thread.Sleep(60) at least. Need more Hz? Increase baud :)

 

You need to sleep BEFORE doing anything with serial.BytesToRead() so:

static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            lock (monitor)            {                Thread.Sleep(100);                   int bytesToRead = serial.BytesToRead;                byte[] buffer = new byte[bytesToRead];                if (bytesToRead == 72)

but I don't see a point in bytesToRead == 72. If You have a fixed number of bytes its better to do something like this:

byte[] yourBytes =  new byte[72]static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            lock (monitor)            {                Thread.Sleep(100);                   int bytesToRead = serial.BytesToRead;                byte[] buffer = new byte[bytesToRead];                if (bytesToRead >0)                {                     Array.Copy(buffer, 0, yourBytes, 0, 72)

and then You have Your 72 bytes to use as You wish




#56064 Multiple Serials Ports in Threads - Best Practices

Posted by lifanek on 14 February 2014 - 12:41 AM in Netduino Plus 2 (and Netduino Plus 1)

One more thing I discovered:

 static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            lock (monitor)            {                Thread.Sleep(100);   << ADD THIS!!!!!!!!                int bytesToRead = serial.BytesToRead;                byte[] buffer = new byte[bytesToRead];                if (bytesToRead > 0)                                       (code continues....)

Why? I found out when I tried to send longer message i.e. "Test1234567890" I received "Test1234567" and few chars got lost, but in step mode (I analyzed every step so it took a while) everything goes well. So I realized the thread have to wait a little bit to get whole message and then process it :)




#56037 Newbie Reference for programming Netduino Microsoft Visual C

Posted by lifanek on 12 February 2014 - 04:15 PM in Visual Studio

You mean something like this: http://arduino.cc/en/Tutorial/HomePage ? I think this can be done by creating new category on forum where people can post working code examples (something like project showcase but much simplier, veryfied and maintained)




#56036 uning List<struct>

Posted by lifanek on 12 February 2014 - 04:04 PM in Visual Studio

Hi,

 

I would like to do something with an object having it's name/id. For example:

 

module sensor = new module

{

id = 47,

name = "tempSensor"

value = 0,

};

 

later in code I read sensor name (i. e. from UART) and put it to string:

string sensorString = "<sensorname or id>";

 

Now I would like to set some value to it - how can I do that?

<sensorname>.value =  100

 

I was thinking about dictionary (<string, module>) but while its missing in MF I dont know what would be the best method to accomplish that?




#56033 Multiple Serials Ports in Threads - Best Practices

Posted by lifanek on 12 February 2014 - 02:49 PM in Netduino Plus 2 (and Netduino Plus 1)

Then, I think, You can get rid of receive() thread and put everything You want to do with Your received msg to  static void serial_DataReceived because it is executed while something is to read (so ASAP :D ).




#56029 Multiple Serials Ports in Threads - Best Practices

Posted by lifanek on 12 February 2014 - 01:08 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi Homey!

I'm actually on ND+ (not 2) :) - Hope no issues here :)

 

So I'm posting working examples made from other examples that:

-use threads

-one thread is posting test message every 5sec

-second is printing in debug received messages

 

Everything works for me - thanks to all who made some code for serial and sharing it  :)

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.NetduinoPlus;using System.IO.Ports;using System.Text;namespace NetduinoPlus_serial_test{    public class Program    {        static SerialPort serial;        static string msg = "";        static object monitor = new object();        public static void Main()        {                                    //serial(using D0 - RX & D1 - TX)            serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);            serial.ReadTimeout = -1;             serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);            serial.Open();                                  //threads            var thread1 = new Thread(recive);            var thread2 = new Thread(transmit);            thread1.Start();            thread2.Start();            Thread.Sleep(Timeout.Infinite);        }        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            lock (monitor)            {                int bytesToRead = serial.BytesToRead;                byte[] buffer = new byte[bytesToRead];                if (bytesToRead > 0)                {                    serial.Read(buffer, 0, buffer.Length);                }                String str = new String(System.Text.Encoding.UTF8.GetChars(buffer));                msg = str;                Debug.Print(msg + " in serial_DataReceived");            }        }        static void recive()        {            while (true)            {                lock (monitor)                {                    if (msg.Length > 0)                    {                        Debug.Print(msg + " in thread");                        msg = "";                    }                                       }                            }        }        static void transmit()        {            while (true)            {                lock (monitor)                {                    Debug.Print("transmit thread works");                    const string input = "Test$n";                    byte[] sender = Encoding.UTF8.GetBytes(input);                    serial.Write(sender, 0, sender.Length);                                    }                Thread.Sleep(5000);            }         }    }}



#55991 [HELP] Using uPLibrary to post to ThingSpeak

Posted by lifanek on 10 February 2014 - 08:59 AM in Netduino Plus 2 (and Netduino Plus 1)

Hello Paolo!

 

I found an answer to my problem while I was writing to You my next message. It was trivial but it is all because I recently made some updates to .NET MF, VS and N+ firmware.

 

I made Your library in .NET 4.3 instead of using 4.2 because of those updates - after switching it back to 4.2 everythings fine now (Program was in 4.2)!

 

Still - many thanks for creating library and providing proffesional help!

Just have to remember one thing dataEntry.fields counts from 0 and ThingSpeak fields are from 1 what means

using dataEntry.fields[1] will update to channel 2.

 

I can't wait for trying out more posibilites of uPLibrary!

 

Thanks,

L.




#55987 Multiple Serials Ports in Threads - Best Practices

Posted by lifanek on 10 February 2014 - 07:32 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi all!

 

I've got some problems with reading from serial - if You guys could please take a look at my code and tell me what I'm doing wrong :(

 

What I have already done and what I'm trying to have:

 

Netduino with its COM1 is connected to Arduino MEGA Serial1

Arduino MEGA is running MultiSerialMega app from examples provided in IDE examples.

 

In short - everything what I write in serial monitor in Arduino IDE is sent to Netduino, and everything I see there is sent by Netduino :)

 

So I wrote this program for Netduino ( I re-wrote some examples and added a little bit extra code).

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.NetduinoPlus;using System.IO.Ports;using System.Text;namespace NetduinoPlus_serial_test{    public class Program    {        static SerialPort serial;        static string msg = "";        public static void Main()        {            // initialize the serial port for COM1 (using D0 - RX & D1 - TX)            serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);            // open the serial-port, so we can send & receive data            serial.Open();            // add an event-handler for handling incoming data            serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);            var thread1 = new Thread(recive);            var thread2 = new Thread(transmit);            thread1.Start();            thread2.Start();            Thread.Sleep(Timeout.Infinite);        }        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            // create a single byte array            byte[] bytes = new byte[1];                                    // as long as there is data waiting to be read            while (serial.BytesToRead > 0)            {                // read a single byte                serial.Read(bytes, 0, bytes.Length);                msg += (char)bytes[0];                                            }            Debug.Print(msg);        }        static void recive()        {            while (true)            {                if (msg.Length > 0)                {                    Debug.Print(msg);                    msg = "";                }                Debug.Print("recive thread works");                Thread.Sleep(1000);            }        }        static void transmit()        {            while (true)            {                Debug.Print("transmit thread works");                const string input = "Test$n";                byte[] sender = Encoding.UTF8.GetBytes(input);                serial.Write(sender, 0, sender.Length);                Thread.Sleep(1000);            }         }    }}

so the transmit thread works perfectly - it sends every second "test$" message and I can see it in serial monitor.

 

But when I'm trying to send something to Netduino nothing happens

( I can see only this >> Debug.Print("recive thread works"); )

 

What I want to do is make Netduino read something from Serial, create a string from it that would be accessible from other parts of program (other threads etc.)

 

Many thanks for any help!




#55983 [HELP] Using uPLibrary to post to ThingSpeak

Posted by lifanek on 09 February 2014 - 09:38 PM in Netduino Plus 2 (and Netduino Plus 1)

Did You want to sent me those files or my program project?

Attached Files




#55925 N+2 ethernet communication with Windows Form

Posted by lifanek on 08 February 2014 - 12:08 AM in Netduino Plus 2 (and Netduino Plus 1)

Try MFDeploy tool and check DHCP or set some IP over there.




#55923 [HELP] Using uPLibrary to post to ThingSpeak

Posted by lifanek on 07 February 2014 - 07:07 PM in Netduino Plus 2 (and Netduino Plus 1)

Hello Paolo,

thank You for reply - I have attached another screenshot - I hope there are all informations needed (too_big.png)

I also tried to create another blank project and added Your library manually by finding .dll file and it's also too big for Netduino :(

Maybe whole library is too big and I should use just a part of it?

 

If I would like to manually copy source code from CodePlex how should I do that? I gave it a try but with no success :(

 

Please take a look at library.png - maybe I missed something. Output.png shows the result of deploy attempt using library that I have created on my own from Your code on CodePlex - You can see there is something wrong but size of it is much much smaller :)

 

Many thanks for helping me out :)

 

L.

Attached Thumbnails

  • library.PNG
  • output.PNG
  • too_big.PNG



#55879 [HELP] Using uPLibrary to post to ThingSpeak

Posted by lifanek on 05 February 2014 - 04:05 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi all!

 

Those are my first attempts to Netduino and internet communiation :)

 

I have followed this tutorial with success:

 

http://community.thi...and-thingspeak/

 

I've connected potentiometer to my Netduino and it was posting data and channel status to Thing Speak.

Everything is great about it, but I found out uPLibrary so what I did:

 

Updated to VS 2012 Express (on 2010ex I couldn't install Nuget).

Updated .Net, SDK and my N+ firmware.

After downloading Nuget and creating new project Ive typed in Nuget console Install-Package uPLibrary.

I wanted to give it a try so I re-writed firs code from here:

 

http://www.embedded1...k-platform.aspx

 

but I get strange error when I'm trying to debug it. Please help!

 

I've attached files with error and code screenshots.

 

BTW.: Are there any simple code examples for this uPLibrary? It is quite hard for a begginer to examine it on my own :) and the library is very interesting.

 

Thank You all in advance!

 

Attached Thumbnails

  • Capture.PNG
  • code.PNG




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.