错误:URI无效:无法解析主机名。如何使代码运行。 [英] Error: Invalid URI: The hostname could not be parsed. How to make the code run.
问题描述
用法:请提供有效参数,例如:
customschemename:// readersIP:portname --ant 1,2
我的阅读器配置如下:
Ip:10.0.0.101本地端口:49200远程端口:5084
可执行文件:Reader.exe
当类型:Reader //10.0.0.101:49200 --ant 1, 2或
读者//10.0.0.101:5084 --ant 1,2
我得到答案:错误:URI无效:无法解析主机名。
Usage: Please provide valid arguments, such as:
customschemename://readerIP:portname --ant 1,2
I have a reader configured as follow:
Ip:10.0.0.101 Local Port:49200 Remote Port:5084
Executable file: Reader.exe
When a type: Reader //10.0.0.101:49200 --ant 1,2 or
Reader //10.0.0.101:5084 --ant 1,2
I get the answer: Error: Invalid URI: The hostname could not be parsed.
Directory of C:\DADOS\READ\READ\BIN\DEBUG
14/12/2015 21:35 <DIR> .
14/12/2015 21:35 <DIR> ..
24/03/2015 11:05 253.440 MercuryAPICE.dll
24/11/2015 15:55 8.704 Read.exe
24/11/2015 15:55 8.704 ReadCustom.exe
24/11/2015 15:55 15.872 ReadCustom.pdb
14/12/2015 14:35 11.600 ReadCustom.vshost.exe
17/03/2010 23:39 490 ReadCustom.vshost.exe.manifest
6 File(s) 298.810 bytes
2 Dir(s) 20.166.651.904 bytes free
C:\DADOS\READ\READ\BIN\DEBUG>read
Usage: Please provide valid arguments, such as:
customschemename://readerIP:portname --ant 1,2
C:\DADOS\READ\READ\BIN\DEBUG>Read //10.0.0.101:49200 --ant 1,2
Error: Invalid URI: The hostname could not be parsed.
C:\DADOS\READ\READ\BIN\DEBUG>read //10.0.0.101:5084 --ant 1,2
Error: Invalid URI: The hostname could not be parsed.
来源:
Source:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading; // for Thread.Sleep
using ThingMagic; // Reference the API
namespace ReadCustom
{
/// <summary>
/// Sample programme that uses custom transport scheme.
/// It shows the usage of tcp serial transport scheme.
/// </summary>
class ReadCustomTransport
{
static void Usage()
{
Console.WriteLine(String.Join("\r\n", new string[] {"Usage: "+"Please provide valid arguments, such as:", "customschemename://readerIP:portname --ant 1,2" }));
Console.ReadKey();
Environment.Exit(1);
}
static void Main(string[] args)
{
// Program setup
if (1 > args.Length)
{
Console.WriteLine(args.Length);
Usage();
}
int[] antennaList = null;
for (int nextarg = 1; nextarg < args.Length; nextarg++)
{
string arg = args[nextarg];
if (arg.Equals("--ant"))
{
if (null != antennaList)
{
Console.WriteLine("Duplicate argument: --ant specified more than once");
Console.ReadKey();
Usage();
}
antennaList = ParseAntennaList(args, nextarg);
nextarg++;
}
else
{
Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
Console.ReadKey();
Usage();
}
}
try
{
// Add the custom transport scheme before calling Create().
// This can be done by using C# API helper function SetSerialTransport().
// It accepts two arguments. scheme and serial transport factory function.
// scheme: the custom transport scheme name. For demonstration using scheme as "tcp".
// Factory function:custom serial transport factory function
Reader.SetSerialTransport("tcp", SerialTransportTCP.CreateSerialReader);
// Create Reader object, connecting to physical device.
// Wrap reader in a "using" block to get automatic
// reader shutdown (using IDisposable interface).
using (Reader r = Reader.Create(args[0]))
{
//Uncomment this line to add default transport listener.
//r.Transport += r.SimpleTransportListener;
r.Connect();
if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
{
Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
if (supportedRegions.Length < 1)
{
throw new FAULT_INVALID_REGION_Exception();
}
r.ParamSet("/reader/region/id", supportedRegions[0]);
}
string model = r.ParamGet("/reader/version/model").ToString();
if ((model.Equals("M6e Micro") || model.Equals("M6e Nano")) && antennaList == null)
{
Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
Usage();
}
// Create a simplereadplan which uses the antenna list created above
SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
// Set the created readplan
r.ParamSet("/reader/read/plan", plan);
//Sync Read
Console.WriteLine("Doing a sync read for 1sec duration");
TagReadData[] tagReads;
// Read tags
tagReads = r.Read(1000);
// Print tag reads
foreach (TagReadData tr in tagReads)
Console.WriteLine(tr.ToString());
// Async Read
Console.WriteLine("Doing an async read for 2sec duration");
// Create and add tag listener
r.TagRead += delegate(Object sender, TagReadDataEventArgs e)
{
Console.WriteLine("Background read: " + e.TagReadData);
};
// Create and add read exception listener
r.ReadException += new EventHandler<ReaderExceptionEventArgs>(r_ReadException);
r.StartReading();
Console.WriteLine("\r\n<Do other work here>\r\n");
Thread.Sleep(1000);
Console.WriteLine("\r\n<Do other work here>\r\n");
Thread.Sleep(1000);
r.StopReading();
}
}
catch (ReaderException re)
{
Console.WriteLine("Error: " + re.Message);
Console.Out.Flush();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
Console.ReadKey();
}
static void r_ReadException(object sender, ReaderExceptionEventArgs e)
{
Console.WriteLine("Error: " + e.ReaderException.Message);
}
#region ParseAntennaList
private static int[] ParseAntennaList(IList<string> args, int argPosition)
{
int[] antennaList = null;
try
{
string str = args[argPosition + 1];
antennaList = Array.ConvertAll<string, int>(str.Split(','), int.Parse);
if (antennaList.Length == 0)
{
antennaList = null;
}
}
catch (ArgumentOutOfRangeException)
{
Console.WriteLine("Missing argument after args[{0:d}] \"{1}\"", argPosition, args[argPosition]);
Usage();
}
catch (Exception ex)
{
Console.WriteLine("{0}\"{1}\"", ex.Message, args[argPosition + 1]);
Usage();
}
return antennaList;
}
#endregion
}
}
推荐答案
您没有给它一个有效的URL来解析。您继续输入:
You're not giving it a valid URL to parse. You keep typing:
//ipAddress:port
你错过了两个斜杠前面的部分:
You're missing the part that goes in front of the two slashes:
http://ipAddress:port
但是,模式名称应该取决于您尝试连接的服务器。它可以是 ftp:
,或文件:
,或 http:
或任何其他名称。
But, what the schema name should be depends on the server that you're trying to connect to. It could be ftp:
, or file:
, or http:
, or any other name.
这篇关于错误:URI无效:无法解析主机名。如何使代码运行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!