473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to write abstraction for communications Ethernet and Serial

I am attempting to write an abstract layer to make Ethernet and Serial seemless in my application. I have an interface that is the what I call ILayer it has the method stubs for connect, disconnect, read and write. Next I have an AbstractLayer class that will handle the read and writes and abstract the rest of the methods to the inheriting classes. What I want is to use IOStreams or something similar so to that when I have the Ethernet or Serial classes I can new up the IO streams particular to the Ethernet or Serial making the reading and writing of data seamless. Therefore the application doesn't care what the connection type is just that it has a connection. I did the same thing in Java but I am new to C# and I am trying to do the same thing. Any ideas?
Dec 23 '09 #1
1 3041
Let expand on this I have an interface ILayer that is used in my abstract class ALayer and this abstract is used in My Ethernet or Com classes. Therefore this will abstract the communication layer, then I won't care what the actual communication as long as I can read and write from them. SO far this is what I have:

public interface ILayer {
bool isConnected();
bool reconnectSetting();
void connect();
void disconnect();
int read(byte[] data , int length);
void write(byte[] data);
}

public abstract class ALayer : ILayer{
protected ???? inStream; //not sure what to use here to make the readers and writers for communication common.
protected ???? outStream;

private bool reconnect;
public abstract bool isConnected();
public abstract void connect();
public abstract void disconnect();
public bool reconnectSetting() {
return false;
}

private void waitingToConnect() {
while (reconnect && !isConnected()) {
connect();
}
}

public int read(byte[] data, int length) {
waitingToConnect();
// add reading logic
return 0;
}

public void write(byte[] data) {
waitingToConnect();
// add write logic.
}

}

public class Ethernet {
// So far don't know how to abstract the Out and In streams... not sure if C# will let me do something like this.
}
Dec 27 '09 #2

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

Similar topics

2
by: Ashwini Kumar | last post by:
Hi, I want to know if there is a way to get system level information using Java. I am mostly interested in things like Ethernet ID and serial number of Hard disk. Some of the values when you...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
9
by: Mairhtin O'Feannag | last post by:
Hello, We have two machines we wish to use DPF. They are both RH ES 2.1, with DB2 8.2. I read the documentation CAREFULLY, and added the following line to my db2nodes.cfg file : 1 egret 0
3
by: rover | last post by:
I'm looking for information about using Access or vb/vba for serial communications to test devices or for alphanumieric paging. Please email if you can point me in the right direction. Thanks...
2
by: M | last post by:
does c# or the .NET framework provide any serial communications support? where can i find some info on how to handle serial ports in c#? thanks m
6
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
10
by: Jim H | last post by:
I need to communicate using a serial port. Are there any classes or libraries for this in .NET? If not are there any open source libraries for this out there? jim
8
by: vicky | last post by:
Hello,I met a question when I wrote the program.I want the program can transmit the data frame continuosly through the RS232 when the communication has been interrupted.But I don't know how to...
5
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.