A
AlliXSenoS
hi to everybody
I have a small but urgent problem... seems me and my friend got ourselves
in a project a bit out of our league, and now we're stuck. and the delivery
date was... um. last month
the program is supposed to communicate with a COM port-based device that is
actually a reader for keys (a lo-tek version of USB thumbdrives) that carry
information.
the communication is done in 'bytes' because the device is pretty stupid
and uses 1-byte commands and responses
we picked up this code from some MSDN page dealing with COM port
communication:
#region COM port HocusPocus
[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode creationdisposition,
int flags, IntPtr template);
#endregion
public void Connect()
{
if (!Connected)
{
try
{
IntPtr ptr = CreateFile(_port, FileAccess.ReadWrite,
FileShare.ReadWrite, 0, FileMode.Create, 0, IntPtr.Zero);
stream = new FileStream(ptr, FileAccess.ReadWrite);
}
catch (ArgumentException)
{
throw new InvalidOperationException("Cannot open
communication port. Please close all other applicaions using port COM 1.");
}
}
else
throw new InvalidOperationException("Already connected");
}
public void Send(byte b)
{
stream.WriteByte(b);
int response = 0;
timer.Reset();
while ((response != 32) || (!timer.Timeout))
{
response = stream.ReadByte();
response = response & 0x20;
}
}
the problem is that the stream.ReadByte call hangs and never returns
anything. the programs hangs here, and we've been busting our heads over
this. we used a terminal program to test the equipment we're communicating
with and it returns 0xE0 if there's an error or 0xE1 if the command is
understood. but our program just sits there waiting... forever
can anyone please help us, we're in deeep trouble if we don't get this
running.
thanks,
Luka
I have a small but urgent problem... seems me and my friend got ourselves
in a project a bit out of our league, and now we're stuck. and the delivery
date was... um. last month

the program is supposed to communicate with a COM port-based device that is
actually a reader for keys (a lo-tek version of USB thumbdrives) that carry
information.
the communication is done in 'bytes' because the device is pretty stupid
and uses 1-byte commands and responses
we picked up this code from some MSDN page dealing with COM port
communication:
#region COM port HocusPocus
[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode creationdisposition,
int flags, IntPtr template);
#endregion
public void Connect()
{
if (!Connected)
{
try
{
IntPtr ptr = CreateFile(_port, FileAccess.ReadWrite,
FileShare.ReadWrite, 0, FileMode.Create, 0, IntPtr.Zero);
stream = new FileStream(ptr, FileAccess.ReadWrite);
}
catch (ArgumentException)
{
throw new InvalidOperationException("Cannot open
communication port. Please close all other applicaions using port COM 1.");
}
}
else
throw new InvalidOperationException("Already connected");
}
public void Send(byte b)
{
stream.WriteByte(b);
int response = 0;
timer.Reset();
while ((response != 32) || (!timer.Timeout))
{
response = stream.ReadByte();
response = response & 0x20;
}
}
the problem is that the stream.ReadByte call hangs and never returns
anything. the programs hangs here, and we've been busting our heads over
this. we used a terminal program to test the equipment we're communicating
with and it returns 0xE0 if there's an error or 0xE1 if the command is
understood. but our program just sits there waiting... forever
can anyone please help us, we're in deeep trouble if we don't get this
running.
thanks,
Luka