Programming tutorials online .NET, Java, C++, Visual Basic, and More
 

Home
.NET Tutorials
General Programming Tutorials
Community/Forums
Site Extras

 

.NET Forum
 

Open forum for all things .NET, including C#, ASP.NET, and VB.NET. Feel free to post or browse through postings for lots of .NET information and help.


POST REPLY
Posted By: Pandi   4/21/2006 5:08:00 AM
 
Hi,

I am using a check scanner.It has functions which gives output like image ,checknumber. i am using serial port to get this output in my coding. My problem is i am not able to read the display image ( which i scanned using scanner ). I used serail port as well as MSCOMM control.but i couldn't get the output. Can anybody knows this and help me to sort out my problem -- it is very urgent

here i am using windows 2000 professional OS and i am using VS 2005 c# .Here is my code
MSCOMM Control Code

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Initialize the COM Port control
InitComPort();
try
{
axMSComm1.Output = new byte[] { 0, 0x41, (byte)'A', 255 };
}
catch (System.Exception se)
{
rtfTerminal.Text = se.Message;
}
}

private void OnComm(object sender,EventArgs e)//MSCommLib OnComm Event Handler
{
//*** The below code gives the check number
rtfTerminal.Text = axMSComm1.Input.ToString();

//***code below suppose to capture the check image and save as a jpg file, but it never works
//no error is thrown in this occssion.It swallows the error and does nothing

byte[] picture = (byte[])axMSComm1.Input;
MemoryStream ms = new MemoryStream(picture);
Bitmap bmp = new Bitmap(ms);
string saveTime = System.DateTime.Now.Millisecond.ToString() + ".jpg";
bmp.Save("C:\\Images" + saveTime);

}
private void InitComPort()
{

axMSComm1.CommPort = 1;
if (axMSComm1.PortOpen) axMSComm1.PortOpen = false;
axMSComm1.RThreshold = 1;
axMSComm1.Settings = "115200,n,8,1";
axMSComm1.DTREnable = true;
axMSComm1.Handshaking = MSCommLib.HandshakeConstants.comNone;
axMSComm1.InputMode = MSCommLib.InputModeConstants.comInputModeText;
axMSComm1.InputLen = 0;
axMSComm1.NullDiscard = false;
// Attach the event handler
axMSComm1.OnComm += new System.EventHandler(this.OnComm);
try
{
axMSComm1.PortOpen = true;
}
catch(System.Exception se)
{
rtfTerminal.Text = se.Message;
}

}
}

Serial Port

public partial class Form1
{
System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort();
public Form1()
{
InitializeComponent();
serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived);
}

private void btnConnect_Click(System.Object sender, System.EventArgs e)
{
if (serialPort.IsOpen)
{
serialPort.Close();
}
try
{
System.IO.Ports.SerialPort with_1 = serialPort;
with_1.PortName = cbbCOMPorts.Text;
with_1.BaudRate = 115200;
with_1.Parity = System.IO.Ports.Parity.None;
with_1.DataBits = 8;
with_1.StopBits = System.IO.Ports.StopBits.One;
// .Encoding = System.Text.Encoding.Unicode
serialPort.Open();
lblMessage.Text = cbbCOMPorts.Text + " connected.";
btnConnect.Enabled = false;
//btnDisconnect.Enabled = True
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void Form1_Load(System.Object sender, System.EventArgs e)
{
for (int i = 0; i {
cbbCOMPorts.Items.Add((new Microsoft.VisualBasic.Devices.Computer()).Ports.SerialPortNames[i]);
}
}
private void serialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{

txtDataReceived.Invoke(new myDelegate(updateTextBox), new object[] {});
}
public delegate void myDelegate();
public void updateTextBox ()
{
System.Windows.Forms.RichTextBox



 
Sign In
Email
Password
  Forgot my password

Search

Featured Book

Introducing Microsoft .Net, Third Edition ($19.79)
Introducing Microsoft .Net, Third Edition


Featured Software

Microsoft Visual Studio Standard 2005 ($249.99)
Microsoft Visual Studio Standard 2005