Best is to create Automation for that. Or you can use the "Microsoft Communications Control, version 6.0" OCX (without triggers), you cannot create code "when scanner read something, run this trigger). For this you need MSCOMM32.OCX. I will try to upload my application changing COM scanner into Keyboard scanner and with interface to NAV to be able to read data from the scanner.
I worked for 2 projects where scanners were involved. One used the com port automation as kine noted and one used a usb port sending the data direct to the keyboard buffer. Acutally it does not matter wheter you are using com or usb.
What I want to say is: Its maybe possible to just have the cursor blinking on the field you want and then do your scan ==> Data is written to the field without fuss. Maybe nonsense, but just to think about it.
Best is to create Automation for that. Or you can use the "Microsoft Communications Control, version 6.0" OCX (without triggers), you cannot create code "when scanner read something, run this trigger). For this you need MSCOMM32.OCX. I will try to upload my application changing COM scanner into Keyboard scanner and with interface to NAV to be able to read data from the scanner.
I worked for 2 projects where scanners were involved. One used the com port automation as kine noted and one used a usb port sending the data direct to the keyboard buffer. Acutally it does not matter wheter you are using com or usb.
What I want to say is: Its maybe possible to just have the cursor blinking on the field you want and then do your scan ==> Data is written to the field without fuss. Maybe nonsense, but just to think about it.
Sorry, cant send you the automation object, since I have developed it for my last company I worked for.
What excactly do you want to do with the scanner?
thnks ta5, actually its a scanner to read a bar code of a product and sent it to a field in NAV. i hve written some automation code bt it given some problem.
Can you configure your scanner to have the data from the scanner right to the keyboard buffer. If yes you don't have to fiddle with com port functions.
Can you configure your scanner to have the data from the scanner right to the keyboard buffer. If yes you don't have to fiddle with com port functions.
I am not allowed to upload my whole application, but it is easy to create one application or Automation for that (if you are using serial port scanner). Just create new application/automation, use the SerialPort component in VisualStudio 2005, use somewhere this code:
//sPort1 - System.IO.Ports.SerialPort
//EmulateKeyb - flag if keyboard emulation is enabled
String Data = sPort1.ReadLine();
Data = Data.Replace("\r", "");
IWshRuntimeLibrary.WshShellClass Shell = new IWshRuntimeLibrary.WshShellClass();
bool bWait = false;
object Wait = bWait;
if (EmulateKeyb)
{
Shell.SendKeys(Data, ref Wait);
}
else
{
LastData = Data;
Shell.SendKeys("^{F12}", ref Wait); //Ctrl+F12
}
this code will send the data as keyboard keys if emulation is enabled, else it will store the data into buffer and send Ctrl+F12 into keyboart input. Than it is easy to catch this key on your form (through hidden menu button with one item with this shortcut) and call the function to read the buffer (assume Automation and not just simple application).
Of course you need to configure and open the port first, but it is easy and I know that you will not have problems with that.
I am not allowed to upload my whole application, but it is easy to create one application or Automation for that (if you are using serial port scanner). Just create new application/automation, use the SerialPort component in VisualStudio 2005, use somewhere this code:
//sPort1 - System.IO.Ports.SerialPort
//EmulateKeyb - flag if keyboard emulation is enabled
String Data = sPort1.ReadLine();
Data = Data.Replace("\r", "");
IWshRuntimeLibrary.WshShellClass Shell = new IWshRuntimeLibrary.WshShellClass();
bool bWait = false;
object Wait = bWait;
if (EmulateKeyb)
{
Shell.SendKeys(Data, ref Wait);
}
else
{
LastData = Data;
Shell.SendKeys("^{F12}", ref Wait); //Ctrl+F12
}
this code will send the data as keyboard keys if emulation is enabled, else it will store the data into buffer and send Ctrl+F12 into keyboart input. Than it is easy to catch this key on your form (through hidden menu button with one item with this shortcut) and call the function to read the buffer (assume Automation and not just simple application).
Of course you need to configure and open the port first, but it is easy and I know that you will not have problems with that.
thanks kine, pls can u help me on how to get my serial port ID on my local machine
Hi Kine
Maybe a stupid question, but to ask again:
Why not configure the scanner in a way so the scanner is writing the code directly to the keyboard buffer :?
Yes, you can, but if the scanner is connected to COM, you need some driver or application on the PC which will do that. And if you do not have such a driver with the scanner, there is no way and you need to create your own one... :-) Scanner as a HW is not able do it without SW support...
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
What I want to say is: Its maybe possible to just have the cursor blinking on the field you want and then do your scan ==> Data is written to the field without fuss. Maybe nonsense, but just to think about it.
Thomas
Thomas
What excactly do you want to do with the scanner?
this code will send the data as keyboard keys if emulation is enabled, else it will store the data into buffer and send Ctrl+F12 into keyboart input. Than it is easy to catch this key on your form (through hidden menu button with one item with this shortcut) and call the function to read the buffer (assume Automation and not just simple application).
Of course you need to configure and open the port first, but it is easy and I know that you will not have problems with that.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Maybe a stupid question, but to ask again:
Why not configure the scanner in a way so the scanner is writing the code directly to the keyboard buffer :?
Thomas
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.