|
An ordinary VB developer shares his own successes and failures |
|
| Home News Articles Resources Tips Downloads About me | ||
Advanced .NET Reflection<ms-quotation>.NET is a new generation of technology based on Web services.</ms-quotation> Is .NET able to handle the nuts-and-bolts of low-level serial communications? Let's use .NET and Reflection to implement serial communications software for controlling a large congress network.Late march this year my company has been asked to take part in a joint project to deliver a complete congress solution for a major government organization here in Slovakia. The hardware was the Philips Digital Congress Network (DCN, see links) line of products and my company had to develop new control software for the DCN Central Control Unit (CCU).I took over the software part of the project and started analyzing the requirements. Here they are in a nutshell:
The "funny" part of this project turned out to be the protocol handler, mainly because the protocol specifications were a bit incomplete and imprecise (and I'm very tolerant with this wording;-). The protocol basically describes how to transfer messages between the CCU and the controlling PC. The message data are opaque streams of bytes. The actual structure of the data is implied by the message type, which is defined in the documentation using C-style syntax. For illustration, here is the definition of a message that the CCU sends when a delegate inserts a PIN card into her delegate unit (don't worry about the semantics, its not important for this discussion):
typedef struct
{
WORD wUnitId;
WORD wDelegateId;
BYTE byAttend;
} AT_T_DEL_ATTEND;
Because there are lots of different message types
defined, I wanted to design some generic mechanism
that would allow me to:
I came up with the following design:
The
The Private Sub SerializeInteger( _ ByVal obj As Object, _ ByVal field As FieldInfo, _ ByVal attr As CcuSerializableAttribute, _ ByVal writer As System.IO.BinaryWriter) Dim Value As Integer = CInt(field.GetValue(obj)) writer.Write(Value) End Sub Private Sub DeserializeInteger( _ ByVal obj As Object, _ ByVal field As FieldInfo, _ ByVal attr As CcuSerializableAttribute, _ ByVal reader As System.IO.BinaryReader) Dim Value As Integer = reader.ReadInt32() field.SetValue(obj, Value) End SubYou can find a link to the complete SerializationManager source code at the end of
this article. (Yes, complete code; taken straight
from the project and placed on my website. For
you:-)).
With <CcuSerializable()> _ Public Class AttnEntry <CcuSerializable()> Private _UnitID As Short <CcuSerializable()> Private _DelegateID As Short <CcuSerializable()> Private _Status As Byte ......And the rest was handled automatically. That's it. Well, the project isn't completed yet. It will enter beta testing at the beginning of August (this year;-). The software will control over 150 delegate units and I've tested with just 15 so far. Nevertheless, I'm quite confident that the software will survive the load of the production environment and that the use of Reflection won't be a problem. Stay tuned, I'm going to write another article after the project completes. (And please, don't worry--I'll be honest and tell you when something would go wrong. After all, VBInfoZine is about real projects and they have a tendency to fail sometimes:-) © Palo Mraz - Monday, July 14, 2003 Linkshttp://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/ - John Hind's article about serial communications in .NET. Accompanied with C# source for theCommBase class used within the project
described here.
http://www.philipscsi.com/ - The makers of the DCN product line. Formerly Philips Communication, Security & Imaging, now owned by Bosch.
http://www.vbinfozine.com/downloads/sm.txt - The
|
||
|
|
||
| ©2003-2008 Palo Mraz. All Rights Reserved. See my 'new browser window' policy | ||