473,582 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"are you missing a using directive or an assembly reference?" prob

I keep receiving this "The type or namespace name 'CASsEventHandl er' could
not be found (are you missing a using directive or an assembly reference?)"
message in two particular lines, and I've tried everything...

Could anyone please paste this and tell me what I'm doing wrong ? I use
SerialPort.zip, which can be downloaded at
http://www.gotdotnet.com/Community/U...4-dfe325097c69

Thanks very much !
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.IO.Ports ;
using System.IO;
using System.Text;
using System.Threadin g;
namespace CASs.NIInstrume nts
{
/// <summary>
/// Simple generic CASs Reader Interface.
/// Provides methods to open and close communication with the device
/// and request reads from the device.
/// </summary>
public interface ICASsReader : IDisposable
{
/// <summary>
/// Opens a connection to the CASs Reader
/// </summary>
void Open();
/// <summary>
/// Closes a connection to the CASs Reader
/// </summary>
void Close();
/// <summary>
/// Forces the CASs reader to make a single read of an ID CAS
/// <returns>
/// Returns a string indicating the ID of the CAS that was read
/// or string.Empty if no CAS was read
/// </returns>
/// </summary>
string ReadOne();
/// <summary>
/// Causes the CASs Reader to enter a continuous reading state
/// </summary>
void ReadContinuous( );
/// <summary>
/// Causes the CASs Reader to exit from a continuous reading state
/// </summary>
void StopReadContinu os();
/// <summary>
/// This event signals that data is received from the CASs Reader
/// </summary>
event CASsEventHandle r CASsEvent;
}
/// <summary>
/// NI Instruments specific implementation of the ICASsReader Interface
/// </summary>
public class NIInstrumentsCA SsReader : ICASsReader
{
private const int MaxReadBytes = 128;

#region Private Member Fields
private SerialPort serialPort;

private Thread continuousReadT hread;
private ThreadStart readThreadStart ;

#endregion Private Member Fields

#region Public Constructors
public NIInstrumentsCA SsReader()
{
Initialize();
}
#endregion

#region ICASsReader Members
public event CASsEventHandle r CASsEvent;

public void Open()
{
// Check if serial port is already open
if( !serialPort.IsO pen )
{
serialPort.Open ();

if (serialPort.IsO pen)
{
// Make reader awake (get ready now command)
serialPort.Writ e(Command.Start , 0, Commands.Start. Lenght);
Thread.Sleep(10 00);

serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();
}
}
}
public void Close()
{
CleanUpContinuo usReadThread();
serialPort.Clos e();
}
public string ReadOne()
{
byte[] buffer;
string CAS;

CleanUpContinuo usReadThread();

serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();

WriteCommand(Co mmands.ReadOne) ;
buffer = ReadResponse();

// Check the response
if (buffer == Responses.NoRea d)
{
CAS = string.Empty;
}
else
{
CAS = StripCASFromRes ponse(buffer);
}
return CAS;
}
public void ReadContinuous( )
{
CleanUpContinuo usReadThread();

serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();

continuousReadT hread = new Thread(readThre adStart);
continuousReadT hread.Start();

WriteCommand(Co mmands.ReadCont inuousNormal);
}
public void StopReadContinu ous()
{
CleanUpContinuo usReadThread();

serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();

WriteCommand(Co mmands.Start);
Thread.Sleep(10 00);

serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();
}
#endregion

#region IDisposable Members

public void Dispose()
{
CleanUpContinuo usReadThread();
serialPort.Disp ose();
}

#endregion

#region Private Member Functions

private void Initialize()
{
// Create a new serial port
serialPort = new SerialPort();

if (serialPort.IsO pen)
{
serialPort.Clos e();
}

// Set all important data
serialPort.Baud Rate = 9600;
serialPort.Data Bits = 8;
serialPort.Enco ding = Encoding.ASCII;
serialPort.Pari ty = Parity.None;
serialPort.Port Name = "COM1";
serialPort.Stop Bits = StopBits.One;
serialPort.Rece ivedBytesThresh old = 2;

readThreadStart = new ThreadStart(Con tinuousReadProc );
continuousReadT hread = null;
}

private byte[] ReadResponse()
{
byte[] buffer = new byte[MaxReadBytes];
int offset = 0;
bool responseReceive d = false;
int readval;

for (int i = 0; i < MaxReadBytes; i++)
buffer[i] = 0;

if (serialPort.IsO pen)
{
try
{
while (!responseRecei ved && offset < MaxReadBytes)
{
readval = serialPort.Read (buffer, offset, MaxReadBytes - offset);
if (readval >= 0)
{
offset += readval;
}
if ((offset > 1) &&
(buffer[0] != (byte)ASCII.SOH ))
{
// Didn't get an SOH
// Response is invalid, just bail out !
offset = MaxReadBytes + 1;
responseReceive d = false;
}

if ((offset > 1) &&
(offset >= buffer[1] + 3))
{
// Received entire response
serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();
responseReceive d = true;
}
}
if (!responseRecei ved)
{
// Some error occurred and we didn't get the response
// Just clear out the buffer, and discard the serialPort buffers...
for (int i = 0; i < MaxReadBytes; i++)
buffer[i] = 0;
serialPort.Read Available();
serialPort.Disc ardInBuffer();
serialPort.Disc ardOutBuffer();
}
}
catch (ObjectDisposed Exception e)
{
throw new ApplicationExce ption("ReadResp onse failed. The serial port
object is disposed", e);
}
catch (InvalidOperati onException e)
{
throw new ApplicationExce ption("ReadResp onse failed. The serial port is
closed", e);
}
catch (IOException e)
{
throw new ApplicationExce ption("ReadResp onse failed. An IO exception
occurred", e);
}
}
return buffer;
}

private void WriteCommand(by te[] command)
{
if (serialPort.IsO pen)
{
try
{
serialPort.Writ e(command, 0, command.Length) ;
}
catch (ObjectDisposed Exception e)
{
throw new ApplicationExce ption("Write " +
RawHexEncoding. GetString(comma nd) + " failed. The serial port object is
disposed", e);
}
catch (InvalidOperati onException e)
{
throw new ApplicationExce ption("Write " +
RawHexEncoding. GetString(comma nd) + " failed. The serial port is closed", e);
}
catch (IOException e)
{
throw new ApplicationExce ption("Write " +
RawHexEncoding. GetString(comma nd) + " failed. An IO exception occurred", e);
}
}
}

private void ContinuousReadP roc()
{
byte[] buffer;
string CAS;

while(true)
{
buffer = ReadResponse();

// Check the response
if (buffer == Responses.NoRea d)
{
CAS = string.Empty;
}
else
{
CAS = StripCASFromRes ponse(buffer);
}

FireCASsEvent (CAS);
}
}

private void FireCASsEvent(s tring ID)
{
CASsEventArgs args = new CASsEventArgs(I D);
if (CASsEvent != null)
{
CASsEvent(this, args);
}
}

private string StripCASFromRes ponse(byte[] response)
{
if ((response.Leng th < 4) ||
(response[0] != ((byte)ASCII.SO H)) ||
(response[2] == 0x03) ||
((response[2]&0x03) > 0) ||
(!ValidCRC(resp onse)) )
{
return string.Empty;
}

ArrayList list = new ArrayList(respo nse.Length - 3);
for (int i = response[1] + 1; i > 2; i--)
{
list.Add(respon se[i]);
}
return RawHexEncoding. GetString(((byt e[])list.ToArray(t ypeof(byte))));
}

private bool ValidCRC(byte[] bytes)
{
BitArray crc = new BitArray(8, false);
bool test;

if (bytes[1] + 2 > bytes.Length + 2)
{
return false;
}
for (int i = 1; i <= bytes[1] + 1; i++)
{
byte[] b = new byte[1];
b[0] = bytes[i];
BitArray ba = new BitArray(b);
crc = crc.Xor(ba);
}

test = ((bytes[bytes[1] + 2]& 0x1) > 0);
if (test != crc[0])
return false;

test = ((bytes[bytes[1] + 2]& 0x2) > 0);
if (test != crc[1])
return false;

test = ((bytes[bytes[1] + 2]& 0x4) > 0);
if (test != crc[2])
return false;

test = ((bytes[bytes[1] + 2]& 0x8) > 0);
if (test != crc[3])
return false;

test = ((bytes[bytes[1] + 2]& 0x10) > 0);
if (test != crc[4])
return false;

test = ((bytes[bytes[1] + 2]& 0x20) > 0);
if (test != crc[5])
return false;

test = ((bytes[bytes[1] + 2]& 0x40) > 0);
if (test != crc[6])
return false;

test = ((bytes[bytes[1] + 2]& 0x80) > 0);
if (test != crc[7])
return false;

return true;
}

private void CleanUpContinuo usReadThread()
{
// Kill the ContinuousReadT hread if it is executing
if (continuousRead Thread != null &&
continuousReadT hread.IsAlive)
{
continuousReadT hread.Abort();
continuousReadT hread = null;
}
}

#endregion Private Member Functions
}
}

Jul 21 '05 #1
1 21373
Junior <Ju****@discuss ions.microsoft. com> wrote:
I keep receiving this "The type or namespace name 'CASsEventHandl er' could
not be found (are you missing a using directive or an assembly reference?)"
message in two particular lines, and I've tried everything...


Well, where are you expecting the delegate 'CASsEventHandl er' to be
declared? You haven't declared it in the code you've posted.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6385
by: Jacek Dziedzic | last post by:
Is it valid to use a "using namespace foo" (as opposed to using foo::bar which I'm sure is legal) within a class declaration? My compiler rejects it, but I've been told it's valid. Can anyone please confirm or deny? TIA, - J.
0
1605
by: Oliver | last post by:
hi - I have a written a "Serviced Component" which works fine when declared as: but I am seeing an 'Access Denied' exception when I declare it as: this is probably something to do with Roles etc, but I'm clueless ;)
4
1338
by: Philipp Sumi | last post by:
Hello all I have a thread that performs some simple I/O within a loop that runs on a separate thread. I used the using keyword to ensure the writer's disposal: using (writer) { while (myCondition) {
7
9978
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and using CodeDOM for my scripting needs (I realize I could use yacc or something else, but I wanted to try using CodeDOM -- this is more of an exercise for...
1
595
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've tried everything... Could anyone please paste this and tell me what I'm doing wrong ? I use SerialPort.zip, which can be downloaded at...
30
4086
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" << std::endl; Myself I am not sure which I prefer, it is certainly easier to specify that the std namespace is being used instead of tagging each...
1
4276
by: BobPaul | last post by:
I'm following code out of a howto book and this is really bugging me. This header file was created by VStudio 6.0 when I did a "Right Click: Add Member Function" CLine is a class I wrote (per the book's instructions) and Line.h in included in Day10Doc.cpp Here is the contents of Day10Doc.h #if...
3
12332
by: VRSki | last post by:
Hello, Is there any way to use "using" for aliasing in the global scope? The example below works fine in the context of a given file, but in the different file MyByte alias is unknown. Is there any way to extend its visibility to multiple files without redefining it? using MyByte=System.Byte;
2
2071
by: Peter Webb | last post by:
Sorry, stupid newbie question. I have VS2008, and I downloaded and installed the DirectX SDK. I want to access the DirectX classes from C#, but I can't see how to make C# aware of them. using Microsoft.DirectX.Direct3DX; says the namespace doesn't exist.
0
7886
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7809
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8159
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7920
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8183
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6569
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1147
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.