473,498 Members | 37 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read images using serial port in c#.net 2005

1 New Member
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(ser ialPort_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 <= (new Microsoft.VisualBasic.Devices.Computer()).Ports.Se rialPortNames.Count - 1; i++)
{
cbbCOMPorts.Items.Add((new Microsoft.VisualBasic.Devices.Computer()).Ports.Se rialPortNames[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 with_1 = txtDataReceived;
with_1.Font = new Font("Garamond", (float) (12.0), FontStyle.Bold);
with_1.SelectionColor = Color.Red;
with_1.AppendText(serialPort.ReadExisting());
with_1.ScrollToCaret();
}
}
Apr 21 '06 #1
0 9756

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5017
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
6
16994
by: DraguVaso | last post by:
Hi, I'm experimenting with the Serial Port in VB.NET 2005. Although it isn't that easy to get any feedback from my COM-port as I thought it would be... How can I read all the Data that the...
1
8563
by: Tolgay Gül | last post by:
I need some codes that able to send and read data by serialport in VB.Net 2005 beta 2. I wrote some codes and It can send data via serialport but It cannot read what I send. I have looked up on...
6
3574
by: Casey Bralla | last post by:
I'd like to read ASCII data from a serial port, but (once again) I'm having trouble getting started. (Can't seem to find the basic level of docs to get going <sigh>) I'd like to use only...
0
1517
by: daikeechi | last post by:
hello guys .. i want to perform pc to pc chatting via null modem cable.. i managed to write and sent data to serial port but how to write loops to read data from serial port ? i'm using visual c++...
4
11650
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
0
4538
by: ghjk | last post by:
I want to read sms from GSM modem using C# in serial communication. I wrote the code. But i want to do it automatically. I put my code here and please tell me how can i do it automatically. ...
2
10388
by: mmrasheed | last post by:
Hi, I am newbie in python. I am working on Telit GM862 GPS/GPRS module which has python interpreter built in. But it seems this problem is pretty much related to general python structure. I...
1
4262
by: rfarley | last post by:
Hi, I am using the pyserial module and am trying to read the serial port from an accelerometer (LIS302DL). It has an option in which you write "*debug\r\n" and then you read the data (three...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.