在线结帖!!扫描枪信息相关! 急!急!急!偶有一扫描枪,现在想通C#得到它的型号等基本信息。因为公司要求:只有一个特定型号的扫描枪才可以扫描!请教各个大虾该如何操作!!!急! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.Text;using System.IO.Ports;using System.Threading;namespace PortChatTest{ class PortChat { static bool _continue; static SerialPort _serialPort; static void Main(string[] args) { string name; string message; StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; Thread readThread = new Thread(Read); // Create a new SerialPort object with default settings. _serialPort = new SerialPort(); // Allow the user to set the appropriate properties. _serialPort.PortName = SetPortName(_serialPort.PortName); _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate); _serialPort.Parity = SetPortParity(_serialPort.Parity); _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits); _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits); _serialPort.Handshake = SetPordtHandshake(_serialPort.Handshake); // Set the read/write timeouts _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500; _serialPort.Open(); _continue = true; readThread.Start(); Console.Write("Name: "); name = Console.ReadLine(); Console.WriteLine("Type QUIT to exit"); while (_continue) { message = Console.ReadLine(); if (stringComparer.Equals("quit", message)) { _continue = false; } else { _serialPort.WriteLine( String.Format("<{0}>: {1}", name, message)); } } readThread.Join(); _serialPort.Close(); } public static void Read() { while (_continue) { try { string message = _serialPort.ReadLine(); Console.WriteLine(message); } catch (TimeoutException) { } } } public static string SetPortName(string defaultPortName) { string portName; Console.WriteLine("Available Ports:"); foreach (string s in SerialPort.GetPortNames()) { Console.WriteLine(" {0}", s); } Console.Write("COM port({0}): ", defaultPortName); portName = Console.ReadLine(); if (portName == "") { portName = defaultPortName; } return portName; } public static int SetPortBaudRate(int defaultPortBaudRate) { string baudRate; Console.Write("Baud Rate({0}): ", defaultPortBaudRate); baudRate = Console.ReadLine(); if (baudRate == "") { baudRate = defaultPortBaudRate.ToString(); } return int.Parse(baudRate); } public static Parity SetPortParity(Parity defaultPortParity) { string parity; Console.WriteLine("Available Parity options:"); foreach (string s in Enum.GetNames(typeof(Parity))) { Console.WriteLine(" {0}", s); } Console.Write("Parity({0}):", defaultPortParity.ToString()); parity = Console.ReadLine(); if (parity == "") { parity = defaultPortParity.ToString(); } return (Parity)Enum.Parse(typeof(Parity), parity); } public static int SetPortDataBits(int defaultPortDataBits) { string dataBits; Console.Write("Data Bits({0}): ", defaultPortDataBits); dataBits = Console.ReadLine(); if (dataBits == "") { dataBits = defaultPortDataBits.ToString(); } return int.Parse(dataBits); } public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("Available Stop Bits options:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return (StopBits)Enum.Parse(typeof(StopBits), stopBits); } public static Handshake SetPordtHandshake(Handshake defaultPortHandshake) { string handshake; Console.WriteLine("Available Handshake options:"); foreach (string s in Enum.GetNames(typeof(Handshake))) { Console.WriteLine(" {0}", s); } Console.Write("Stop Bits({0}):", defaultPortHandshake.ToString()); handshake = Console.ReadLine(); if (handshake == "") { handshake = defaultPortHandshake.ToString(); } return (Handshake)Enum.Parse(typeof(Handshake), handshake); } }} Image转换为byte[] winform界面的应用程序,拖动缩放很卡,何解? 求教:C#,根据用户选择不同模式去执行不同的代码? 具体请看帖子内容 请教如何分开提取数值 C#的Spread中金额数据的显示 图片合成视频的方法(C#或Delphi代码) 取dataGrid1值: c# 构造URL时,怎样嵌入用户名和密码 海波大哥帮我啊!关于动态水晶报表的字段问题! 我的类继承是出错了吗,第一次涉及到此块内容。 一个多线程的问题.请高手帮忙回答. C#怎么遍历目录读取图片类型的文件啊
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
using System.Threading;namespace PortChatTest
{
class PortChat
{
static bool _continue;
static SerialPort _serialPort; static void Main(string[] args)
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read); // Create a new SerialPort object with default settings.
_serialPort = new SerialPort(); // Allow the user to set the appropriate properties.
_serialPort.PortName = SetPortName(_serialPort.PortName);
_serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);
_serialPort.Parity = SetPortParity(_serialPort.Parity);
_serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);
_serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);
_serialPort.Handshake = SetPordtHandshake(_serialPort.Handshake); // Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500; _serialPort.Open();
_continue = true;
readThread.Start(); Console.Write("Name: ");
name = Console.ReadLine(); Console.WriteLine("Type QUIT to exit"); while (_continue)
{
message = Console.ReadLine(); if (stringComparer.Equals("quit", message))
{
_continue = false;
}
else
{
_serialPort.WriteLine(
String.Format("<{0}>: {1}", name, message));
}
} readThread.Join();
_serialPort.Close();
} public static void Read()
{
while (_continue)
{
try
{
string message = _serialPort.ReadLine();
Console.WriteLine(message);
}
catch (TimeoutException) { }
}
} public static string SetPortName(string defaultPortName)
{
string portName; Console.WriteLine("Available Ports:");
foreach (string s in SerialPort.GetPortNames())
{
Console.WriteLine(" {0}", s);
} Console.Write("COM port({0}): ", defaultPortName);
portName = Console.ReadLine(); if (portName == "")
{
portName = defaultPortName;
}
return portName;
} public static int SetPortBaudRate(int defaultPortBaudRate)
{
string baudRate; Console.Write("Baud Rate({0}): ", defaultPortBaudRate);
baudRate = Console.ReadLine(); if (baudRate == "")
{
baudRate = defaultPortBaudRate.ToString();
} return int.Parse(baudRate);
} public static Parity SetPortParity(Parity defaultPortParity)
{
string parity; Console.WriteLine("Available Parity options:");
foreach (string s in Enum.GetNames(typeof(Parity)))
{
Console.WriteLine(" {0}", s);
} Console.Write("Parity({0}):", defaultPortParity.ToString());
parity = Console.ReadLine(); if (parity == "")
{
parity = defaultPortParity.ToString();
} return (Parity)Enum.Parse(typeof(Parity), parity);
} public static int SetPortDataBits(int defaultPortDataBits)
{
string dataBits; Console.Write("Data Bits({0}): ", defaultPortDataBits);
dataBits = Console.ReadLine(); if (dataBits == "")
{
dataBits = defaultPortDataBits.ToString();
} return int.Parse(dataBits);
} public static StopBits SetPortStopBits(StopBits defaultPortStopBits)
{
string stopBits; Console.WriteLine("Available Stop Bits options:");
foreach (string s in Enum.GetNames(typeof(StopBits)))
{
Console.WriteLine(" {0}", s);
} Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString());
stopBits = Console.ReadLine(); if (stopBits == "")
{
stopBits = defaultPortStopBits.ToString();
} return (StopBits)Enum.Parse(typeof(StopBits), stopBits);
} public static Handshake SetPordtHandshake(Handshake defaultPortHandshake)
{
string handshake; Console.WriteLine("Available Handshake options:");
foreach (string s in Enum.GetNames(typeof(Handshake)))
{
Console.WriteLine(" {0}", s);
} Console.Write("Stop Bits({0}):", defaultPortHandshake.ToString());
handshake = Console.ReadLine(); if (handshake == "")
{
handshake = defaultPortHandshake.ToString();
} return (Handshake)Enum.Parse(typeof(Handshake), handshake);
}
}
}