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();
}
}
}
Related
I installed the Zebra.Printer.SDK via NuGet and included using Zebra.Sdk.Comm; and
using Zebra.Sdk.Printer;.
I am trying to connect to my printer via USB. In the example they do the following:
} else {
printerConnection = new UsbConnection(selectedItem.Address);
}
I tried the same in my application. But I can't find the UsbConnection class. Do I need to add additional dependencies?
The SKD reference
SDK Installation which contains the example
If you installed the Nuget library correctly, you should have the library dependencies needed to run the application. For usb communication, you need the usb dll that allows the interface communication. Please, download the Multiplatform SDK from this Link, it has a folder called PC -.NET, click on it, and then go to “C:\Program Files\Zebra Technologies\link_os_sdk\PC-.NET\v2.15.2634\demos-desktop\Source”, it has a full Visual Studio project that you can install and run immediately. This sample code has all you need, included the dll for usb communication.
For the USB class API documentation please, follow the links below.
Zebra.Sdk.Comm Namespace
https://techdocs.zebra.com/link-os/2-14/pc_net/content/html/85823b27-9fa5-7681-c212-8e536f601bbe.htm
UsbConnection Class
https://techdocs.zebra.com/link-os/2-14/pc_net/content/html/ab837158-704b-90f5-f754-c05091f89421.htm
public UsbConnection(string symbolicName)
Parameters
symbolicName
Type: System.String
The USB symbolic name for the device returned by the UsbDiscoverer.GetZebraUsbPrinters() member function.
Example of symbolicName: \?\usb#vid_0a5f&pid_016e#zq520r#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}
private void SendZplOverUsb(string symbolicName) {
// Instantiate connection for ZPL USB port at given address/symbolicName
Connection thePrinterConn = new UsbConnection(symbolicName);
try {
// Open the connection - physical connection is established here.
thePrinterConn.Open();
// This example prints "This is a ZPL test." near the top of the label.
string zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
// Send the data to printer as a byte array.
thePrinterConn.Write(Encoding.UTF8.GetBytes(zplData));
} catch (ConnectionException e) {
// Handle communications error here.
Console.WriteLine(e.ToString());
} finally {
// Close the connection to release resources.
thePrinterConn.Close();
}
}
Zebra Link-OS - C# view Sample Code
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.
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!
I'm now trying to write a simple program in C# that sends command to the printer to print a plain text but don't know how to. There are 2 main problems that I'm facing now:
1. How to communicate with the printer?
After doing some google search but not getting a satisfying result I went to Brothers' main page and found there a so-called b-PAC3 SDK.
The b-PAC* Software Development Kit is a software tool for Microsoft® Windows® that allows customized labels to be printed from within your own applications.
After having downloaded and installed it, in the directory where it's installed, I found a folder named "Samples"- there are sample codes written in some different language (VB, VS, VSC, ...) I hoped that these sample codes would work since this SDK and the printer come from the same company. But they didn't. Let me show you one of these samples here: (code in C#)
/*************************************************************************
b-PAC 3.0 Component Sample (RfidRW)
(C)Copyright Brother Industries, Ltd. 2009
*************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleSampleCSharp
{
class Program
{
private const int NOERROR = 0;
private const string ANTENNA_READER_WRITER = "Reader/Writer side";
static void Main(string[] args)
{
// Create Rfid Instance
bpac.RfidClass rfid = new bpac.RfidClass(); // Rfid Instance
string selectedDevice; // selected device
/* GetInstalledDevices */
Console.WriteLine("==GetInstalledDevices()==");
object[] arrDevices = (object[])rfid.GetInstalledDevices();
if (rfid.ErrorCode == NOERROR)
{
Console.WriteLine("Succeed to GetInstalledDevices()");
int index = 0;
foreach (string device in arrDevices)
{
Console.WriteLine(String.Format("[{0}] {1}", index, device));
index++;
}
// select device
Console.WriteLine("Please Select Device");
int selectedDeviceIndex = int.Parse(Console.ReadLine());
selectedDevice = arrDevices[selectedDeviceIndex].ToString();
}
else
{
Console.WriteLine("Failed to GetInstalledDevices()");
goto CleanUp;
}
// ....
}
}
}
When I run this code, the first problem comes out: (it displayed exactly as in quote bellow, sorry, I can't post image due to low reputation):
==GetInstalledDevices()==
Succeed to GetInstalledDevices()
Please Select Device
There wasn't any error but seems like program can't find my device, I don't have any idea why this happens.
2. How to write a QL-style command?
I know that each kind of printer has its own command language so after searching on Brother's site I found a reference:
Brother QL Series
Command Reference
(QL-500/550/560/570/580N/
650TD/700/1050/1060N)
I myself have no experience in working with thermal printer and unfortunately there isn't any sample in this command reference which makes it really difficult for me to figure out how the command should be written.
Has anyone worked with Brother QL serie printers before?
P.S: The printer that I'm using is Brother QL 560.
To communicate with the printer, you need a few things:
Get a USB library, like libusb (http://libusb.info/)
Install a driver that will allow you to access the printer via libusb, like Zadig for example (http://zadig.akeo.ie/)
Download the printer's Command Reference from the Internet ("Brother QL Series Command Reference")
Using the information provided in chapter 7 of the command reference and the samples that come with libusb, make a small routine that will detect and open a communication channel with the printer via USB.
Then, using the rest of the information available in the manual, send a series of ESC commands to the printer to either configure it or print labels.
PS: If you need to improve your background on USB communication, I recommend an excellent reference called "USB in a Nutshell", available at beyondlogic dot org (I can't post more than two links).
I think OPOS (from Microsoft) should be the one of the solutions for your case, provided with Brother QL 560 offering its own opos driver. Once you get the driver (in dll), you can just start developing as easily as using general web controls.
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?