Arduino driver issues (Causing exceptions) - c#

I'm attempting to use ArduinoDriver (through NU-Get) to connect to my Arduino Uno R3 in Visual Studio (in C#). This is the code I'm attempting to run:
using ArduinoUploader;
using ArduinoUploader.Hardware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArduinoDriver.SerialProtocol;
using System.Threading;
using ArduinoDriver;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var driver = new ArduinoDriver.ArduinoDriver(ArduinoModel.UnoR3, "COM3", true);
driver.Send(new DigitalWriteRequest(13, ArduinoDriver.DigitalValue.Low));
driver.Send(new DigitalWriteRequest(13, ArduinoDriver.DigitalValue.High));
Console.WriteLine("doing it!");
}
}
}
The code compiles correctly. However I'm getting an exception at runtime on line 18 (the new Driver Instantiation) in the form of:
System.MissingMethodException: 'Method not found: 'Void ArduinoUploader.ArduinoSketchUploader..ctor(ArduinoUploader.ArduinoSketchUploaderOptions)'.'
I have checked and double-checked the package and dependencies and they are all installed and up to date.
I have also tried both false and true for the AutoBootstrap option in the Arduino Driver Constructor. When it is set to true, the results are as above. When set to false I receive the following exception instead:
System.IO.IOException: 'Unable to get a handshake ACK when sending a handshake request to the Arduino on port COM3. Pass 'true' for optional parameter autoBootStrap in one of the ArduinoDriver constructors to automatically configure the Arduino (please note: this will overwrite the existing sketch on the Arduino).'
I should also point out that I have checked the port for the Arduino and it is definitely connected to COM3 (tested and working in the Arduino I.D.E).
Finally on running the script in Visual Studio, the Arduino flashes its lights in the way that it normally would when a successful upload is in progress. However it hangs for a couple of seconds at the driver instantiation and then puts out the exceptions.
If anyone out there can shed some light on this that would be amazing, I have googled like crazy and have not found any tutorials or other people dealing with this issue. Please let me know if any further info is required.
Cheers!
Using Windows 10 Bootcamped (Mac)

I got the same MissingMethodExeption. I synchronized the packages ArduinoDriver and ArduinoUploader (i.e. in my case downgrading the ArduinoUploader form v3.0.0 to v2.4.5) using the NuGet package manager.
This solved the issue for now...

I copped a tumbleweed badge on this one, so I think I have discovered my own answer; which is to use visual micro, and never speak of Arduino Driver again.
cheers!

Related

Controlling AIM-TTI Power supply via C#

I’m working with a Aim-TTi CPX400DP power supply and tasked with using it remotely strictly via Visual Studio using C#. I’ve seen a lot of people on here using LabView and other software but nothing with Visual Studio. In addition upon looking up a manual for this power supply I’m also not seeing any syntax that I could use to call for this power supply in C#. Does anyone have an knowledge or support they could lend for this issue?
I’ve tried downloading NiMax and using it to verify the power supply is connected via USB. It’s denoting the Power supply as COM4. However, when I open up the panel in NiMax there’s no other connections or operations to speak of. I have no way of connecting it and sending or receiving data
Firstly I should let you know I work for Aim-TTi so I can assist in using your CPX400DP in Visual Studio with C#.
The USB port on a CPX400DP is implemented as a CDC class virtual COM port and can be treated as a standard COM port by any application software.
Below you find a small console application that I created in C#.
Make sure to add "using System.IO.Ports;" which may require you to install the package of the same name (published by Microsoft) from the NuGet Package Manager in Visual Studio.
I would recommend single stepping through this code and then you can see the responses you get in the rx_message string.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
namespace CPX_Console
{
class Program
{
static SerialPort _serialPort;
static void Main(string[] args)
{
string tx_message;
string rx_message;
_serialPort = new SerialPort();
// configure the serial port to use the sesired COM port
// Note, you dont have to configure the baud rate or any of the other default serialPort settings
_serialPort.PortName = "COM7";
// open the COM port
_serialPort.Open();
// query the CPX identification string
tx_message = "*IDN?";
_serialPort.WriteLine(tx_message);
// get the response
rx_message = _serialPort.ReadLine();
// set channel 1 output to 1.23V
tx_message = "V1 1.23";
_serialPort.WriteLine(tx_message);
// enable channel 1
tx_message = "OP1 1";
_serialPort.WriteLine(tx_message);
// query the measured output voltage on channel 1
tx_message = "V1O?";
_serialPort.WriteLine(tx_message);
// get the response
rx_message = _serialPort.ReadLine();
// close the COM port
_serialPort.Close();
}
}
}

Creating a COM port out of a ttyUSB port in Ubuntu

The Question
I'm having to work with a rather awkward API at the moment which insists on me giving the address of a device, linked via USB port, in the form COM*. However, on the Ubuntu machine on which I'm working, and have to use, if I plug in this device it will automatically be assigned an address in the form /dev/ttyUSB*.
Given that I can't modify the source code of the API - which I would dearly like to do! - what is the least painful way getting the API to talk to said device?
Extra Detail
An example of how to use the API from the manual:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.caen.RFIDLibrary;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
CAENRFIDReader MyReader = new CAENRFIDReader();
MyReader.Connect(CAENRFIDPort.CAENRFID_RS232, "COM3");
CAENRFIDLogicalSource MySource = MyReader.GetSource("Source_0");
CAENRFIDTag[] MyTags = MySource.InventoryTag();
if (MyTags.Length > 0)
{
for (int i = 0; i < MyTags.Length; i++)
{
String s = BitConverter.ToString(MyTags[i].GetId());
Console.WriteLine(s);
}
}
Console.WriteLine("Press a key to end the program.");
Console.ReadKey();
MyReader.Disconnect();
}
}
}
The line MyReader.Connect(CAENRFIDPort.CAENRFID_RS232, "COM3"); is where I'm running into problems.
A little later in the manual, it states that the Connect method is to have two parameters:
ConType: The communication link to use for the connection.
Address: Depending on ConType parameter: IP address for TCP/IP communications ("xxx.xxx.xxx.xxx"), COM port for RS232 communications ("COMx"), an index for USB communications (not yet supported).
Bonus Question
The API in question seems to have been written on the assumption that it would be run on a Windows machine. (It's in C#.) The COM* format seems to be favoured - I'm happy to be corrected on this point - by Windows architectures, whereas Ubuntu seems to favour the ttyUSB* format. Assuming that I can funnel the data from my device from a ttyUSB* port to a COM* port, will the API actually be able to find said data? Or will it incorrectly follow the default Windows path?
Given the new information i suspect you can just give the ttyUSB as the parameter, mono will handle the connection correctly. However the same caution for the line endings below still applies. You might also consider making the parameter a command-line parameter thus making your code run on any platform by being able to supply the COM/USB through the command line parameters. I see no other issues using this code. Did you try it yet?
PS: i think your confusion is actually the statement usb id's are not supported yet, i suspect that is because the library relies on a (text-based) serial connection wich are fundamentally different from direct USB connections (wich drivers normally handle) that handle the connection in a more direct way. The ttyUSB ports on linux however DO represent the (UART) serial connections the same way as windows COM-ports, these are not direct USB connections.
Some handy info about the differences: https://rfc1149.net/blog/2013/03/05/what-is-the-difference-between-devttyusbx-and-devttyacmx/
Old answer
I am assuming you run this program on Mono?
Mono expects the path to the port, so COM* will not do. You could try creating a symlink named COM* to the ttyUSB*. Preferrably located in the environment directory. Once you get them linked the program should see no difference. However line endings in the data/program might be different than on windows. If the device expects CRLF and the program uses Environment.NewLine you might get unexpected behaviour too. It might just be easier if you have the permission/rights to edit the assembly with recompilation tools.

Listener for function was unable to start. Azure function app timetrigger

I'm getting the following error when I run the azure function from visual studio in local environment:
The listener for function 'Function1' was unable to start. Microsoft.WindowsAzure.Storage: Bad Request.
Here is my code
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace FunctionApp3
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
}
and configuration (i.e, local.settings.json)
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
But when I setup a http trigger function app, it works fine.
Update:
Since you use a locally virtualized Storage Emulator, then your Connecting String is correct.
If your firewall restricts func from accessing the Storage Account, then this error may be reported. The firewall is one of the reasons that the listener cannot access the virtual Storage Emulator.
When running the function locally, all triggers except httptrigger need to use the Storage Emulator. If the firewall restricts the listener's access to virtual storage, problems can occur when performing functions. That's why you don't get errors with httptrigger, because it doesn't use a virtual Storage Emulator.
Try disabling the firewall and see if that resolves the issue.
Of course, it is also possible that the Storage Emulator service is not open. Try typing
"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" status
in cmd to check the status.
If it returns false, enter the following command to start the Storage Emulator:
"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init
"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
To sum up:
This type of problem is generally for three reasons.
1.Connection string error prevents connection,
2.firewall is set
3.some services are not turned on.
Hope it helps.
Original Answer:
Same code works fine on my side,
Solution:
Try to copying the same code to a different location.
Maybe this can help you.
If this happening in Visual Studio Code, it may be due to local emulator not started.
Install Azurite plugin in VS Code and then start it.
https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=/azure/storage/blobs/toc.json
To start the emulator, open the command palette by pressing F1 in Visual Studio Code and then execute the following command.
Azurite: Clean
I found out that the problem lied in the fact I had the Azure Storage Emulator running in an other drive then I had my project. i.e. emulator was running on C:\Emulator and project was running locally on S:\MyFunction

Cosmos basic example does not run

I am trying to get started with Cosmos using C#. I installed Visual studio 2017, and Cosmos user kit.
On many tutorials on youtube, I have seen that the VMWare player starts whenever they press the "run" button.
However, in my case, I get the following error:
"A project with an Output type of class library cannot be started directly."
My code is really simple, and it is the basic example given in the documentation. Please help me to solve this issue.
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
namespace CosmosKernel2
{
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
}
protected override void Run()
{
Console.Write("Input: ");
var input = Console.ReadLine();
Console.Write("Text typed: ");
Console.WriteLine(input);
}
}
}
Cosmos is a kernel. You can't "run a kernel on windows". If you want to run your cosmos kernel straight out of Visual Studio you need a virtual machine.
Cosmos uses Vmware out of the box. Make sure you have it installed.
Alternatively you can use VirtualBox, I personally got it to run on that too.
You can also run it on an actual machine with a bootloader, like Grub. You can dual boot into windows or your own kernel that way.
Cosmos has instructions here: https://github.com/CosmosOS/Cosmos/wiki/Deployment
Set the boot that cosmos generates as startup project to run it.

System.Net's Webclient in C# won't connect to server

Is there something I need to do to get System.Net working with Microsoft Visual C# 2008 Express Edition? I can't seem to get any web type controls or classes to work at all.. the below WebClient example always throws the exception "Unable to connect to the remote server".. and consequently I can't get the WebBrowser control to load a page either.
Here is the code (Edited):
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
using (WebClient client = new WebClient()) {
string s = client.DownloadString("http://www.google.com");
this.textBox1.Text = s;
}
}
}
}
This is in a simple form with only a textbox control (with multiline set to true) in it. The exception gets thrown on the DownloadString(...) line. I also tried using WebRequest.. same exception!
EDIT:
I am connected to a Linksys WRT54G Router that connects directly to my cable modem. I am not behind a proxy server, although I did run proxycfg -u and I got:
Updated proxy settings
Current WinHTTP proxy settings under:
HKEY_LOCAL_MACHINE\
SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\
WinHttpSettings :
Direct access (no proxy server).
I am using Windows XP and not running any kind of firewall. Only AVG at the moment. I'm pretty sure I shouldn't have to forward any ports or anything, but I did try forwarding port 80 to my workstation on my router. Didn't help.
(update - I meant proxycfg, not httpcfg; proxycfg -u will do the import)
First, there is nothing special about "express" here. Second, contoso is a dummy url.
What OS are you on? And do you go through a proxy server? If so, you might need to configure the OS's http stack - proxycfg will do the job on XP, and can be used to import the user's IE settings.
The sample is fine, although it doesn't correctly handle the multiple IDisposable objects - the following is much simpler:
using (WebClient client = new WebClient()) {
string s = client.DownloadString("http://www.google.com");
// do something with s
}
Do you have any firewall software on your PC that might be affecting it? Have you tried with any sites other than Google?

Categories