Q: What to use in a NET development environment ?
A: Using SuperCom in Microsoft .NET Framework (e.g. C#, VB Net) offers nothing less than the known DLL API and ActiveX API. Both APIs are compatible to the well known but the new class library offers a lot more. Developers can now use the DLL API and the ActiveX API via the SuperCom .NET Class Library and even combine both API as needed since the class library includes both. Thus the SuperCom ActiveX control is not needed in order to use the ActiveX API because one can use the SuperCom NET class TSCom instead.
The SuperCom ActiveX OLE control can still be used with a NET application, if required.
The SuperCom .NET Class Library is included in every DLL API and DUAL API SuperCom completely with its C# source code and can be used with NET aware compilers like C#, VB Net and C++. The SuperCom .NET Class Library is available in 32 bit and 64 bit SuperCom packages.
The following samples are using the NET class "TSCom" included with the SuperCom .NET Class Library. It is the same API used for serial connections, TCP/IP and ISDN.
Establish a serial modem connection and file transfer
C# Sample
using ADONTEC.Comm; // see C# source in SComClass.cs
: // VB Net references the class DLL
:
public class MYSCOM : TSCom
{
public MYSCOM(int CommId, Form frm)
: base(CommId, frm) // pass the window handle to TSCom
{
}
protected override void OnComm(OnCommEventArgs e) [OnComm +-]
{
int SComEvent = (int)e.EventCode;
if (SuperCom.BitsSet(SComEvent, SuperCom.EV_RXCHAR))
if (SuperCom.BitsSet(SComEvent, SuperCom.EV_TXEMPTY))
if (SuperCom.BitsSet(SComEvent, SuperCom.EV_TRIGGER))
if (SuperCom.BitsSet(SComEvent, SuperCom.EV_RING))
:
:
e.RetCode = 0;
}
protected override void OnConnect(OnConnectEventArgs e) [OnConnect +-]
{
switch (e.Action) // handle event
{
case SuperCom.acCONNECT_INFO:
case SuperCom.acCONNECT_DIALING:
case SuperCom.acCONNECT_OK:
:
:
}
}
protected override void OnFile(OnFileEventArgs e) [OnFile +-]
{
switch (e.Action)
{
case SuperCom.acFILENAME:
case SuperCom.acFILEDATA:
case SuperCom.acSYN:
case SuperCom.acRXING:
case SuperCom.acTXING:
case SuperCom.acRXFIN:
case SuperCom.acTXFIN:
:
}
}
protected override void OnDataPacket(OnDataPacketEventArgs e) [OnDataPacket +-]
{
switch (e.Action)
{
case OnDataPacketEventCode.SCOMM_DATAPACKET_OK:
case OnDataPacketEventCode.SCOMM_DATAPACKET_NOK:
:
}
}
} //MYSCOM
SCom = new MYSCOM(Com, frm1);
// Set some comm parameters
SCom.ComType = ComType.COMTYPE_RS232; // *) serial, TAPI, TCP/IP, ISDN
SCom.Settings = "115200,N,8,1";
// or
SCom.BaudRate = 115200;
SCom.DataBits = 8;
SCom.StopBits = StopBits.One;
SCom.Parity = Parity.None;
SCom.Handshaking = Handshaking.SCOMM_HANDSHAKE_CTS;
SCom.PortOpen = true; // Ready to start action...
: [Triggers +-]
// need some trigger to report when received ?
SCom.Trigger = SuperCom.StringToByteArray("Username");
SCom.TriggerAction = TriggerAction.SCOMM_TRIGGER_ADD;
SCom.Trigger = SuperCom.StringToByteArray("Password");
SCom.TriggerAction = TriggerAction.SCOMM_TRIGGER_ADD;
[Modem | Cable]
// using a modem to connect to a remote server ...
SCom.ConnectAddress="1234 5678 99"; // phone number
SCom.Connect = true; // using a direct cable connection (e.g.. NULL Modem cable)...
-
-
:
// transmit a file
SCom.FileName = "sales.doc";
SCom.Protocol = Protocol.PROTOCOL_ZMODEM;
SCom.FileOptions = FO_RESUME; // Optional: resume a broken file transfer
SCom.FileTransmit = true;
:
*One point to select the desired communication type!
The same class can be used for console applications as well.
|
The above sample gives a brief outline on how to use the NET class "TSCom" of the SuperCom .NET Class Library. The other class "SuperCom" (see sample) is a nearly one to one implementation of the well known SuperCom API.
Now, once we have a working sample as the above how much would it take to switch over to a TCP/IP client ?
Switching ComType from Serial to TCP/IP
C# Sample
In the above sample we've done serial communications. Now we need to send files
to a TCP/IP server. We can create a new class or reuse the one we had in
the previous sample for serial communications.
:
SCom.PortOpen = false; // close that one...
SCom.CommPort = ClientCom; // switch comm index, if needed...
SCom.ComType = ComType.COMTYPE_WINSOCK_CLIENT; // *) serial, TAPI, TCP/IP, ISDN
SCom.PortOpen = true; // Ready to take actions ...
:
// now connect to a TCP/IP server ..
SCom.ConnectAddress="www.weburl.com:9000";
SCom.Connect = true;
:
// transmit a file
SCom.FileName = "sales.doc";
SCom.Protocol = Protocol.PROTOCOL_ZMODEM;
SCom.FileTransmit = true;
:
* one point to select the desired communication type!
|
Obviously, the SuperCom API not only increases productivity but the code developed once can be reused easily (e.g. from the SuperCom ActiveX, MSComm or PDQComm to SuperCom for NET) and most of the time without changes.
A simple console application can be found [ here ].
|