Click here to Skip to main content
15,885,546 members
Home / Discussions / C#
   

C#

 
QuestionFullText Search Pin
ellllllllie30-May-09 19:14
ellllllllie30-May-09 19:14 
AnswerRe: FullText Search Pin
I Believe In GOD31-May-09 2:01
I Believe In GOD31-May-09 2:01 
QuestionForms, Transparencykey and Windows VISTA Pin
franco nero30-May-09 18:39
franco nero30-May-09 18:39 
AnswerRe: Forms, Transparencykey and Windows VISTA Pin
franco nero30-May-09 20:00
franco nero30-May-09 20:00 
QuestionWeb service Pin
chotuithamgia30-May-09 18:13
chotuithamgia30-May-09 18:13 
AnswerRe: Web service Pin
Dave Kreskowiak30-May-09 18:42
mveDave Kreskowiak30-May-09 18:42 
JokeRe: Web service Pin
Manas Bhardwaj30-May-09 20:13
professionalManas Bhardwaj30-May-09 20:13 
QuestionOne apps causes another app to crash.. [modified] Pin
Jonathan Tripathy30-May-09 11:28
Jonathan Tripathy30-May-09 11:28 
Hi folks,

I have written 2 applications on my till running windows 2000. One is an epos system and the other is a "driver" which parses the text from the touch screen and moves the mouse accordingly.

I'm having a very strange issue. I have recently added network functionality to my epos app. There is a classwhich keeps retrying to connect to the server incase the network is down. What I find is that during this loop (which is run in a seperate thread from my epos app's main thread), my touchscreen driver just doesn't move the mouse or just crashes if you just wait long enough (circa 1 minute or so) with a Send/Don't Send style message "system.indexoutofrangeexception". Once the epos app connects to the server, the touch screen drivers works again (provided it hasn't crashed already...).

Here is my "connector" class used in the epos app:
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;

namespace Paypoint
{
class Connector
{
Network networkinterface;
IPEndPoint ipEnd;

public Connector(Network network, IPEndPoint endpoint)
{
networkinterface = network;
network.Connected = false;
ipEnd = endpoint;
}

public void Start()
{
while (true)
{
if (networkinterface.Connected == false)
{
networkinterface.initSocket();
connect();
}
Object objData = "ping";
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());
networkinterface.send("ping");
Thread.Sleep(2000);
}
}

private void connect()
{

while (!networkinterface.Connected)
{
try
{
Network.m_clientSocket.Connect(ipEnd);
networkinterface.Connected = true;
}
catch
{
networkinterface.Connected = false;
Thread.Sleep(10000);
}
}
}
}
}

Here is my TouchScreen "driver". It's a small app so I've included all of it:

<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.IO.Ports;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;

namespace EpsonTouchPanelDriver
{
class Device
{
static SerialPort spt;
public static int x;
public static int y;

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;


public static void init()
{
spt = new SerialPort();
if (spt.IsOpen) spt.Close();
spt.PortName = "COM4";
spt.BaudRate = 9200;
spt.DataBits = 8;
spt.StopBits = StopBits.One;
spt.DataReceived += new SerialDataReceivedEventHandler(spt_DataReceived);
spt.Open();
}

private static void spt_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{

int i = 0;
byte[] bytesToReadArray = new byte[1024];

while (spt.BytesToRead > 0)
{
bytesToReadArray.SetValue((byte)spt.ReadByte(), i);
i++;
}
string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(bytesToReadArray);
if (str.Substring(0, 1) == "T")
{

char[] delimiterChars = {','};
double scalex;
double scaley;
if (str.Length > 1)
{
try
{
str = str.Substring(1, str.Length - 1);
string[] xy = str.Split(delimiterChars);
if (xy[1].Length > 4) xy[1] = xy[1].Substring(0, 4);
if (int.Parse(xy[0]) < 525) scalex = 0.61 - ((525 - int.Parse(xy[0])) * 0.0004);
else scalex = 0.61 + ((int.Parse(xy[0]) - 525) * 0.00005);
if ((1000 - int.Parse(xy[1])) < 500) scaley = 0.4873 - ((500 - (1000 - int.Parse(xy[1]))) * 0.00005);
else scaley = 0.4873 + (((1000 - int.Parse(xy[1])) - 500) * 0.00005);
x = (int)(int.Parse(xy[0]) * scalex);
y = (int)((1000 - int.Parse(xy[1])) * scaley);

if ((x > 0) && (y > 0))
{
Cursor.Position = new Point((int)x, (int)y);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
Thread.Sleep(100);
}
}
catch
{
MessageBox.Show("ERROR");
}

}
}

}



}
}

I find this behaviour very strange as these are 2 different assemblies! I simply don't have the knowledge required to understand how one app can cause another to crash.

Thanks for your help. It's appreciated

**Update**
Ok so the suitation gets weirder. I have found out that during the time when my epos app is trying to connect to the server (hense also the time when to touchscreen won't work), the mouse CAN move if the "driver" Winform is in Focus (normally, it is minimised to the system tray..)

Jonny

p.s. sorry about the bad formatting

**UPDATE 2**

OK folks yet another update! If I put a Thread.Sleep(10) in my driver app just before the if statement, then it works just VERY slowly (Unuseable but hey, there's life!).

modified on Saturday, May 30, 2009 5:36 PM

AnswerRe: One apps causes another app to crash.. Pin
Luc Pattyn30-May-09 15:22
sitebuilderLuc Pattyn30-May-09 15:22 
GeneralRe: One apps causes another app to crash.. Pin
Jonathan Tripathy30-May-09 23:32
Jonathan Tripathy30-May-09 23:32 
QuestionVehicle Lane Tracking Algorithm Pin
sebogawa30-May-09 9:44
sebogawa30-May-09 9:44 
AnswerRe: Vehicle Lane Tracking Algorithm Pin
Uffe Rask30-May-09 10:52
Uffe Rask30-May-09 10:52 
AnswerRe: Vehicle Lane Tracking Algorithm Pin
Henry Minute30-May-09 11:01
Henry Minute30-May-09 11:01 
QuestionRe: Vehicle Lane Tracking Algorithm Pin
sebogawa30-May-09 11:11
sebogawa30-May-09 11:11 
AnswerRe: Vehicle Lane Tracking Algorithm Pin
Henry Minute30-May-09 11:28
Henry Minute30-May-09 11:28 
GeneralRe: Vehicle Lane Tracking Algorithm Pin
sebogawa30-May-09 11:33
sebogawa30-May-09 11:33 
GeneralRe: Vehicle Lane Tracking Algorithm Pin
Henry Minute30-May-09 11:53
Henry Minute30-May-09 11:53 
QuestionAdding an event to a dynamically created Button Pin
Douglas Kirk30-May-09 8:08
Douglas Kirk30-May-09 8:08 
AnswerRe: Adding an event to a dynamically created Button Pin
Luc Pattyn30-May-09 8:15
sitebuilderLuc Pattyn30-May-09 8:15 
QuestionSQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 4:09
bigjoe11a30-May-09 4:09 
AnswerRe: SQL Server 2008 in C# Console Appications Pin
Mbah Dhaim30-May-09 5:17
Mbah Dhaim30-May-09 5:17 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 5:35
bigjoe11a30-May-09 5:35 
AnswerRe: SQL Server 2008 in C# Console Appications Pin
Henry Minute30-May-09 7:48
Henry Minute30-May-09 7:48 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 8:17
bigjoe11a30-May-09 8:17 
GeneralRe: SQL Server 2008 in C# Console Appications Pin
bigjoe11a30-May-09 8:33
bigjoe11a30-May-09 8:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.