more G-Labs products

Author Topic: Arduino on SerialPort, questions/problems  (Read 1600 times)

March 10, 2015, 12:40:44 PM
Read 1600 times

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
I have my Arduino connected to Win7 running HG r476.  I run the SerialPort test app on COM4 and it connects and starts popping up notification with my Arduino data, yay!

Then I begin to modify the SerialPort to parse the comma separated data from Arduino and I start getting runtime errors.  I am probably making some mistakes as I try to learn the C# code here, so I would expect compile errors for mistakes on my part if I assign wrong data type to an object. 

However, my real problem is that when I revert the original code I still get these runtime errors popping up:

Code: [Select]
    Error:     Object does not match target type.

I only changed the port to COM4 and changed / reverted this code:

Code: [Select]
Action<byte[]>
HandleMessageReceived = (byte[] message) => {
 
  // this will be called every time a message is received from serial port
Program.Notify("SerialPort Bytes", BitConverter.ToString(message));
 
  //string msg = BitConverter.ToString(message);
  //string[] data = msg.Split(',');
  //Program.Notify("Temp:", msg); //data[0]);
  //Sensor.Temperature.1=data[0];
  //Sensor.Humidity.1=data[1];
 
};


Any advice?

Thanks in advance!
« Last Edit: March 10, 2015, 07:50:31 PM by kevin1 »

March 10, 2015, 01:39:32 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi kevin1,

this is a bug in HG that probably is fixed in r482 (sure it is fixed by r483).
Unfortunately this bug is that when restarting a program even with a new code, previously allocated serialport event handlers will still be running.
The work-around is to restart HG :-/
Anyway, try r482 and let me know if it solve the issue.

Cheers,
g.

March 10, 2015, 07:49:59 PM
Reply #2

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Problem seems to have gone away, I was able to get my Arduino serial data parsed and have a couple virtual modules for the data now :-)

Several questions haven't been able to resolve:
1-I used RaiseEvent to make my data update to the modules, but now I get notification for every event.  Can I disable that?  I'm attaching every sensor I can find/create to the arduino, so lots of notifications ;-)
Code: [Select]
var module1 = Modules.InDomain("HomeAutomation.ArduinoBsmtUtil").WithAddress("1").Get();
Program.RaiseEvent(module1, "Sensor.Temperature", temp.ToString(), "Sensor 1");

2-I had to convert the data to Celsius before RaiseEvent, which is fine...but the line at top right of HG thinks it is Fahrenheit... how to correct that?

3-How do I add a  chart to my Dashboard to show 24 hours of my data?  Can I mix temperature, humidity and other data (like duty cycle of my sump pump) on one chart?

4-I ended up with some extra parameters for my module as I renamed things, how do I get rid of the old ones?

5-Is there a list of the "Features" that can be added to a module?  I saw the code on how to add these, but not the list of what is available.  All the online documentation seems to be different now than 6 months ago; unfortunately it seems like there is less info, less examples now.  Am I looking in wrong area?

Thanks in advance!!!

March 10, 2015, 11:00:12 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
1) I believe this can be handled with the notification filter that was added a couple versions back.  I believe if you click the red button in the notification, it will add it to the filter.  Not sure if that's what you'll want as I haven't used it yet.

4) If you go to the configure -> groups and modules -> your group and select the triple dash button on the right, it will bring up a menu with all parameters.  You should be able to delete specific ones there.