Developer Articles
- SDK for Windows
- Creating a Simple Serialization Interface
- SDK for Windows Mobile
- ActiveX® Control
- SDK for BlackBerry
- BlackBerry Java Connectivity, Part 1
To use the COM port functions in C#, write a simple Serialization interface to test COM port functions. The .NET framework has a nice serial port namespace that makes reading and writing data very easy. Use a protocol analyzer when venturing into the .NET COM port realm. The simple interface was working in a few hours and the protocol analyzerr confirmed that everything worked properly.
Now, keep in mind that this code has very minimal error checking, only works through a serial interface (not Bluetooth), and it uses a fixed COM port. But the interface is very simple and easy to understand. If you do this type of serial port work be SURE that you have a serial monitor (aka, Protocol Analyzer). Check out eBay for protocol analyzers (search for “network probe”, like the NCC-66xx models available for < $100).
Serialization Protocol is very simple to implement and can be used to download data from both the Flic and ROV Scanners. This protocol is slower than the batch protocols since it must acknowledge each bar code individually. Note that this sample only works with the serial port (does NOT work with Bluetooth). To use Serialization Protocol send these configuration commands to the ROV Scanner:
RestoreFactorySettings
Set Autodownload,true
Set BcDataAck,true
Set SeqNum,true
Set Timestamps,false
The ROV Scanner then sends each scan with a 4-digit serialization number suffix. The application then returns the 4-digit serialization number with an ACK (0x06) character. This is how you open the COM port:
// Configure the COM port parameters.
ScannerSerialPort.PortName = "COM1";
ScannerSerialPort.BaudRate = 4800;
ScannerSerialPort.Parity = Parity.None;
ScannerSerialPort.DataBits = 8;
ScannerSerialPort.StopBits = StopBits.Two;
ScannerSerialPort.Handshake = Handshake.None;
ScannerSerialPort.ReadTimeout = 5000; // 1 second read timeout.
ScannerSerialPort.WriteTimeout = 500; // 1/2 second write timeout
ScannerSerialPort.ReceivedBytesThreshold = 200;
ScannerSerialPort.Open(); // Open the COM port.
This is how you activate the thread:
m_serializationThread = new System.Threading.Thread(Bcs_SerializationThread);
m_threadActive = true;
m_serializationThread.Start();
This is how the thread reads and acknowledges the data:
public void Bcs_SerializationThread ()
{
string barCode;
int length;
byte [] parseString = new byte [100];
string serialNo;
while (m_threadActive)
{
try
{
barCode = ScannerSerialPort.ReadTo("\r");
// The bar code will probably have an STX prefix (if so, then remove it).
if (barCode[0] == '\x02')
{
// This is a roundabout way to remove the STX. With the STX prefix the
// string functions think that the string length is zero. This code gets
// around that problem.
parseString = Encoding.ASCII.GetBytes(barCode);
length = parseString.Length - 1;
barCode = Encoding.ASCII.GetString(parseString, 1, length);
}
else
length = barCode.Length;
if (length > 0)
{
// The Serialization number is the last four digits of the bar code.
// Send the Serialization number with an ACK (hex 06) character to the
// scanner to acknowledge and delete the bar code. If the scanner has bar
// codes buffered then it sends the first stored bar code, deletes that
// bar code after it is acknowledged, and then sends the next stored bar
// code. This process continues until all bar codes have been sent.
serialNo = barCode.Substring(length-4, 4); // Get Serialization #.
ScannerSerialPort.Write (serialNo + "\x06"); // Send number w/ACK char.
}
} // end of try
catch (Exception ex) { } // For timeouts, etc.
} // end of while(m_threadActive)
} // end of Bcs_SerializationThread
This is very basic code but it will allow you to read and acknowledge the scanned bar codes. Set m_threadActive to false to force the thread to stop. If you attempt a bar serial interface then be sure to use a Protocol Analyzer. And, if you decide to do a serial interface then be sure to use a Protocol Analyzer.
Additional Resources
Windows SDK product page |
|
DC0119391 |
XSP – eXtensible Scanner Protocol Specification |
