|
 |
|
สอบถามการเขียนโปรแกรมรับการยิงบาร์โค้ด แบบไม่ต้องเอา Cursor ไปวางที่ Textbox ครับ |
|
 |
|
|
 |
 |
|
มันขึ้นอยู่กับรุ่นของเครื่องยิง Barcode ซึ่ง
- ซึ่งบางรุ่นถ้า cursor ไม่ focus จะยิงไม่ได้
- บางรุ่นทำได้ ก็แค่ส่งออกข้อมูลที่อ่านไปทาง rs232 ส่วนจะไปออกที่ไหน user กำหนดเอาเอง
- และบางรุ่นมีโปรแกรมมาให้ กำหนดการตั้งค่าด้วย เช่น ต้องการให้ส่ง code ENTER<CR> หรือ Comma(,) หลังจากอ่าน barcode
การเขียนแอพต้องเขียนระดับ Com Port(RS232) เช่น
Code (C#)
private SerialPort InitializeScanner()
{
SerialPort port = null;
bool result;
int iPort = 2;
do
{
try
{
result = true;
port = new SerialPort("COM" + iPort, 9600, Parity.None, 8, StopBits.One);
port.Close();
if (!port.IsOpen)
port.Open();
port.DiscardOutBuffer();
port.DiscardInBuffer();
port.DataReceived += OnScan;
}
catch (IOException)
{
iPort++;
result = false;
}
} while (result == false && iPort <= 20);
return port;
}
แล้วก็ใช้ SerialDataReceivedEventArgs.
Code (C#)
private void OnScan(object sender, SerialDataReceivedEventArgs args)
{
SerialPort port = sender as SerialPort;
string line = port.ReadExisting();
int idx = line.IndexOf('\r');
if (idx != -1)
{
line = line.Substring(0, idx);
_scanBuffer += line;
Invoke((MethodInvoker)delegate { OnScan(_scanBuffer); });
_scanBuffer = "";
}
else
{
_scanBuffer += line;
}
}
ส่วนอ่านค่ามาได้จะส่งไปไหนก็แล้วแต่เรา
|
 |
 |
 |
 |
Date :
2017-08-06 01:55:21 |
By :
ccjpn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|