Project

General

Profile

MessagingToolkit code problem

Added by admin almost 5 years ago

I am trying out your library for possible use in a commercial project. I have installed 1.8.0 from nuget, and trying your sample code from http://platform.twit88.com/projects/messagingtoolkit/wiki/Wiki_-_Connect_to_Gateway.

I had to change IMobileGateway mobileGateway = MobileGatewayFactory.Default(); to IMobileGateway mobileGateway = MobileGatewayFactory.Default; (not a method call) in order to compile.

However whenever I run the demo I get the following null reference exception:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at MessagingToolkit.Core.Log.LogMethods.SetLogPath () [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Log.Logger.SetLogPath (LogProfile logprofile) [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Log.Logger.SetLogPath () [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Log.Logger.UseSensibleDefaults (System.String logFileName, System.String logLocation, LogLevel logLevel, LogNameFormat logNameFormat) [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Mobile.DefaultMobileGateway..ctor () [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Mobile.MobileGatewayFactory.get_Default () [0x00000] in <filename unknown>:0
at messaging_toolkit_demo.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at MessagingToolkit.Core.Log.LogMethods.SetLogPath () [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Log.Logger.SetLogPath (LogProfile logprofile) [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Log.Logger.SetLogPath () [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Log.Logger.UseSensibleDefaults (System.String logFileName, System.String logLocation, LogLevel logLevel, LogNameFormat logNameFormat) [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Mobile.DefaultMobileGateway..ctor () [0x00000] in <filename unknown>:0
at MessagingToolkit.Core.Mobile.MobileGatewayFactory.get_Default () [0x00000] in <filename unknown>:0
at messaging_toolkit_demo.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

Any help you can provide would be greatly appreciated.

Thanks,


Replies (4)

RE: MessagingToolkit code problem - Added by admin almost 5 years ago

Hi,

Can you attach your source file or code snippet here?

Thanks
Regards
admin

RE: MessagingToolkit code problem - Added by chrisalbrecht almost 5 years ago

Here is my code. I should note that I've been running this on linux with mono 3.2.

using System;
using System.Linq;
using MessagingToolkit.Core;
using MessagingToolkit.Core.Log;
using MessagingToolkit.Core.Mobile;
using MessagingToolkit.Core.Mobile.Event;
using MessagingToolkit.Core.Mobile.Message;

namespace messaging_toolkit_demo {
internal class Program {
private static void Main() {
var config = MobileGatewayConfiguration.NewInstance();

config.PortName = "/dev/ttyACM0";
config.BaudRate = (PortBaudRate)Enum.Parse(typeof (PortBaudRate), "115200");
config.DataBits = (PortDataBits)Enum.Parse(typeof (PortDataBits), "8");
config.Model = "Telit HE910";
config.Pin = "";
config.Parity = PortParity.None;
config.StopBits = PortStopBits.One;
config.Handshake = PortHandshake.None;
config.DisablePinCheck = true;
//config.LogLevel = LogLevel.Verbose;
//config.LogLocation = "/root/mtk-demo";
//config.LogFile = "log.txt";
//config.LogNameFormat = LogNameFormat.Name;
//config.LogQuotaFormat = LogQuotaFormat.NoRestriction;
//config.LogSizeMax = 10000;
var messageGateway = MessageGateway&lt;IMobileGateway, MobileGatewayConfiguration&gt;.NewInstance();
var mobileGateway = MobileGatewayFactory.Default;
try {
mobileGateway = messageGateway.Find(config);
if (mobileGateway == null) {
Console.WriteLine("Error connecting to gateway. Check the log file");
return;
}
Console.WriteLine("Connected to gateway successfully");
mobileGateway.MessageReceived += OnMessageReceived;
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
var sms = Sms.NewInstance();
sms.DestinationAddress = "&lt;redacted&gt;";
sms.Content = "This is a test message";
sms.Flash = false;
sms.StatusReportRequest = MessageStatusReportRequest.SmsReportRequest;
if (mobileGateway.SendToQueue(sms)) {
Console.WriteLine("Message is queued successfully for " + sms.DestinationAddress);
}
if (mobileGateway.Send(sms)) {
Console.WriteLine("Message is sent successfully to " + sms.DestinationAddress + ". Message index is " + sms.ReferenceNo.First());
}
}
private static void OnMessageReceived(object sender, MessageReceivedEventArgs e) { Console.WriteLine("Message Received: " + e.Message.Content); }
}
}

RE: MessagingToolkit code problem - Added by admin almost 5 years ago

Hi,

Previously the library was not tested in Mono as there was limitation on Mono on the SerialPort class. It seems that since then Mono has improved in terms of SerialPort support.

I will test out the compatibility with mono and let you know if Mono can be supported in few days time.

Thanks
Regards
admin

RE: MessagingToolkit code problem - Added by admin almost 5 years ago

Hi,

I have tested on Mono 3.12 on Windows and the library should works with some minor code changes. Yet to test on Unix.

The attached dll and code snippet is working for me. You can try it out to see if it works for you.

Thanks
Regards
admin

dll.zip (691 KB) dll.zip
Program.cs (2.05 KB) Program.cs
    (1-4/4)