PDA

View Full Version : serial ports


Mogulbasher
10-17-2007, 07:31 PM
Ok, I have looked at the DDK and the sample files. I was wondering when it came to the section where it says initialize COMx stuff here. Typically if trying to open a port I would use System.IO and do something like this



// Instantiate the communications port with some basic settings
SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

// Open the port for communications
port.Open();

//Do something with the port

// Close the port
port.Close();

In this case I am creating a new serialport object. Is this how you expect to do it or have you created somewhere an object within a class that I should be using for this.

Can you provide a sample working DLL file (source code) that I can use as a reference or alternatively suggest whether there is anything in the files htat I should be using specifically. I see that the port name is defined as base.Port

katrash
10-17-2007, 10:39 PM
It is up to the developer to manage the port. We have a COMMLIB DLL which has a buffered serial port driver in mControl server plug-ins folder (EA.CommLib.dll). You are free to use it or use the System.IO.Ports namespace of the .NET framework.

You have to open the driver inside the startup method, and close it inside the shutdown method. Otherwise, in between, you have to send commands inside SendAction() method and listen asynchronously to received bytes. Moreover, upon receiving data you have to analyze it and send notification to mServer as a notification of changed status events.

Serial port dynamic parameters are set in the mServer.exe.xml file.