2 important questions

1) I would be grateful if anyone tell me how to write a text file from C#, for saving information from the program. For example, if I want to save some variable, I would write its name and content into the text file. I need also to be able to read from the text file and use the information inside it. I would be even more grateful if you could explain also how to transform it to .dll file.

2) I need to import a sensor (for example, a light or temperature sensor) information, and use it in my program. what should I do?
I would like to import by aparallel port a DTYPE 25 PIN.
LPT -
parallel port.
I need the output to be 378 Hex, and I need the input to be 379 Hex or 37A Hex.

Thanks ahead, Daniel.

[913 byte] By [KillerGermel] at [2008-1-8]
# 1

1) The easiest way to store the data is to use a BinaryFormatter on a class marked with the SerializableAttribute or to use the XmlSerializer on an appropriate class.

a)

Code Snippet
[Serializable]
class DataStore
{
int data;
// etc.
}

DataStore data;
// initialize the store
Formatter formatter = new BinaryFormatter();
using (Stream stream = File.Create("data.dat"))
{
formatter.Serialize(stream, data);
}

using (Stream stream = File.OpenRead("data.dat"))
{
data = (DataStore)formatter.Deserialize(stream);
}

b)

Code Snippet

class DataStore
{
int data;
// etc.

public int Data
{
get { return data; }
set { data = value; }
}
// etc.
}

DataStore data;
// initialize the store
XmlSerializer serializer = new XmlSerializer(typeof(DataStore));
using (Stream stream = File.Create("data.dat"))
{
serializer.Serialize(stream, data);
}
using (Stream stream = File.OpenRead("data.dat"))
{
data = (DataStore)serializer.Deserialize(stream);
}

2)

To retrieve data from or send data to the serial port, you can use the class System.IO.Ports.SerialPort but I don't know if it also works with the parallel port.

ThomasDanecker at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2
I tried what you suggested in 1), but there are some errors that I don't know how to fix. Click the link, theres a screenshot of the errors.
http://img487.imageshack.us/img487/8599/meteorologicalstationstbs3.png
KillerGermel at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3

For first question, you could check two classes: StreamReader and StreamWriter for help.

Thanks

FigoFei-MSFT at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 4
Hey, my code was just an example and is not complete. Of course you've to put the static methods into a class. You can't declare methods directly in a namespace. Maybe you should start with some C# tutorials or a book about C#. There are dozens of good books out there.
ThomasDanecker at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 5
I work with forms, and not with usual classes, and with event based coding, so its harder to use classes there. i would appreciate if you could adjust the code you wrote to a form in an event based coding. thanks ahead.
KillerGermel at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 6

I tried using the script you gave me, Thomas, but I also need the namespace for using those methods. I tried to use XML namespace but I didnt work. The best thing you can do is to send me a sample program or script with all the basic methos and namespaces.

Thanks ahead, Daniel.

KillerGermel at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 8
I need to use parallel port and not serial port. I think I need to use the inpout32.dll file, but I dont really know how to do it... I tried to create PortAcess class and import the file:

public class PortAccess
{
[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int adress, int value);
}

and used the output method - PortAcess.Output(888, value), but I dont know how to check if it works (those are sensors, not leds or engines). I would be grateful if you could confirm or disconfirm this, and maybe even tell me how to check if it works... Thanks ahead.

p.s, my LPT1 (printer port) range is 0378-037F (hex), like most computers.

KillerGermel at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified